import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class D_452
{
	public static final long[] POWER2 = generatePOWER2();
	public static final IteratorBuffer<Long> ITERATOR_BUFFER_PRIME = new IteratorBuffer<>(streamPrime(1000000).iterator());
	private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
	private static StringTokenizer stringTokenizer = null;
	private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

	interface BiFunctionResult<Type0, Type1, TypeResult>
	{
		TypeResult apply(Type0 x0, Type1 x1, TypeResult x2);
	}

	static class Array<Type> implements Iterable<Type>
	{
		private final Object[] array;

		public Array(int size)
		{
			this.array = new Object[size];
		}

		public Array(int size, Type element)
		{
			this(size);
			Arrays.fill(this.array, element);
		}

		public Array(Array<Type> array, Type element)
		{
			this(array.size() + 1);
			for (int index = 0; index < array.size(); index++)
			{
				set(index, array.get(index));
			}
			set(size() - 1, element);
		}

		public Array(List<Type> list)
		{
			this(list.size());
			int index = 0;
			for (Type element : list)
			{
				set(index, element);
				index += 1;
			}
		}

		public Type get(int index)
		{
			return (Type) this.array[index];
		}

		public Array set(int index, Type value)
		{
			this.array[index] = value;
			return this;
		}

		public int size()
		{
			return this.array.length;
		}

		public List<Type> toList()
		{
			List<Type> result = new ArrayList<>();
			for (Type element : this)
			{
				result.add(element);
			}
			return result;
		}

		@Override
		public Iterator<Type> iterator()
		{
			return new Iterator<Type>()
			{
				int index = 0;

				@Override
				public boolean hasNext()
				{
					return this.index < size();
				}

				@Override
				public Type next()
				{
					Type result = Array.this.get(index);
					index += 1;
					return result;
				}
			};
		}

		@Override
		public String toString()
		{
			return "[" + D_452.toString(this, ", ") + "]";
		}
	}

	static class BIT
	{
		private static int lastBit(int index)
		{
			return index & -index;
		}

		private final long[] tree;

		public BIT(int size)
		{
			this.tree = new long[size];
		}

		public void add(int index, long delta)
		{
			index += 1;
			while (index <= this.tree.length)
			{
				tree[index - 1] += delta;
				index += lastBit(index);
			}
		}

		private long prefix(int end)
		{
			long result = 0;
			while (end > 0)
			{
				result += this.tree[end - 1];
				end -= lastBit(end);
			}
			return result;
		}

		public int size()
		{
			return this.tree.length;
		}

		public long sum(int start, int end)
		{
			return prefix(end) - prefix(start);
		}
	}

	static abstract class Edge<TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>>
	{
		public final TypeVertex vertex0;
		public final TypeVertex vertex1;
		public final boolean bidirectional;

		public Edge(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)
		{
			this.vertex0 = vertex0;
			this.vertex1 = vertex1;
			this.bidirectional = bidirectional;
			this.vertex0.edges.add(getThis());
			if (this.bidirectional)
			{
				this.vertex1.edges.add(getThis());
			}
		}

		public TypeVertex other(Vertex<TypeVertex, TypeEdge> vertex)
		{
			TypeVertex result;
			if (vertex0 == vertex)
			{
				result = vertex1;
			}
			else
			{
				result = vertex0;
			}
			return result;
		}

		public abstract TypeEdge getThis();

		public void remove()
		{
			this.vertex0.edges.remove(getThis());
			if (this.bidirectional)
			{
				this.vertex1.edges.remove(getThis());
			}
		}

		@Override
		public String toString()
		{
			return this.vertex0 + "->" + this.vertex1;
		}
	}

	public static class EdgeDefault<TypeVertex extends Vertex<TypeVertex, EdgeDefault<TypeVertex>>> extends Edge<TypeVertex, EdgeDefault<TypeVertex>>
	{
		public EdgeDefault(TypeVertex vertex0, TypeVertex vertex1, boolean bidirectional)
		{
			super(vertex0, vertex1, bidirectional);
		}

		@Override
		public EdgeDefault<TypeVertex> getThis()
		{
			return this;
		}
	}

	public static class Vertex<TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> implements Comparable<Vertex<? super TypeVertex, ? super TypeEdge>>
	{
		public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> void depthFirstSearch(
				Array<TypeVertex> vertices,
				int indexVertexStart,
				BiConsumer<TypeVertex, TypeEdge> functionPreVisit,
				BiConsumer<TypeVertex, TypeEdge> functionInVisit,
				BiConsumer<TypeVertex, TypeEdge> functionPostVisit
		)
		{
			TypeVertex vertexTo;
			TypeEdge edgeTo;
			boolean[] isOnStack = new boolean[vertices.size()];
			Stack<Operation> stackOperations = new Stack<>();
			Stack<TypeVertex> stackVertices = new Stack<>();
			Stack<TypeEdge> stackEdges = new Stack<>();

			TypeVertex vertexStart = vertices.get(indexVertexStart);
			stackOperations.push(Operation.EXPAND);
			stackVertices.push(vertexStart);
			stackEdges.push(null);
			isOnStack[vertexStart.index] = true;
			while (!stackOperations.isEmpty())
			{
				Operation operation = stackOperations.pop();
				TypeVertex vertex = stackVertices.pop();
				TypeEdge edge = stackEdges.pop();
				switch (operation)
				{
					case INVISIT:
						functionInVisit.accept(vertex, edge);
						break;
					case POSTVISIT:
						functionPostVisit.accept(vertex, edge);
						break;
					case EXPAND:
						stackOperations.push(Operation.POSTVISIT);
						stackVertices.push(vertex);
						stackEdges.push(edge);
						Integer indexTo = null;
						for (int index = 0; indexTo == null && index < vertex.edges.size(); index++)
						{
							edgeTo = vertex.edges.get(index);
							vertexTo = edgeTo.other(vertex);
							if (!isOnStack[vertexTo.index])
							{
								indexTo = index;
							}
						}
						if (indexTo != null)
						{
							edgeTo = vertex.edges.get(indexTo);
							vertexTo = edgeTo.other(vertex);
							stackOperations.push(Operation.EXPAND);
							stackVertices.push(vertexTo);
							stackEdges.push(edgeTo);
							isOnStack[vertexTo.index] = true;
							for (int index = indexTo + 1; index < vertex.edges.size(); index++)
							{
								edgeTo = vertex.edges.get(index);
								vertexTo = edgeTo.other(vertex);
								if (!isOnStack[vertexTo.index])
								{
									stackOperations.push(Operation.INVISIT);
									stackVertices.push(vertex);
									stackEdges.push(edge);
									stackOperations.push(Operation.EXPAND);
									stackVertices.push(vertexTo);
									stackEdges.push(edgeTo);
									isOnStack[vertexTo.index] = true;
								}
							}
						}
						functionPreVisit.accept(vertex, edge);
						break;
				}
			}
		}

		public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>> void depthFirstSearch(
				Array<TypeVertex> vertices,
				int indexVertexStart,
				Consumer<TypeVertex> functionPreVisit,
				Consumer<TypeVertex> functionInVisit,
				Consumer<TypeVertex> functionPostVisit
		)
		{
			depthFirstSearch(
					vertices,
					indexVertexStart,
					(vertex, edge) -> functionPreVisit.accept(vertex),
					(vertex, edge) -> functionInVisit.accept(vertex),
					(vertex, edge) -> functionPostVisit.accept(vertex)
			);
		}

		public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>, TypeResult> TypeResult breadthFirstSearch(
				TypeVertex vertex,
				TypeEdge edge,
				BiFunctionResult<TypeVertex, TypeEdge, TypeResult> function,
				Array<Boolean> visited,
				FIFO<TypeVertex> verticesNext,
				FIFO<TypeEdge> edgesNext,
				TypeResult result
		)
		{
			if (!visited.get(vertex.index))
			{
				visited.set(vertex.index, true);
				result = function.apply(vertex, edge, result);
				for (TypeEdge edgeNext : vertex.edges)
				{
					TypeVertex vertexNext = edgeNext.other(vertex);
					if (!visited.get(vertexNext.index))
					{
						verticesNext.push(vertexNext);
						edgesNext.push(edgeNext);
					}
				}
			}
			return result;
		}

		public static <TypeVertex extends Vertex<TypeVertex, TypeEdge>, TypeEdge extends Edge<TypeVertex, TypeEdge>, TypeResult> TypeResult breadthFirstSearch(
				Array<TypeVertex> vertices,
				int indexVertexStart,
				BiFunctionResult<TypeVertex, TypeEdge, TypeResult> function,
				TypeResult result
		)
		{
			Array<Boolean> visited = new Array<>(vertices.size(), false);
			FIFO<TypeVertex> verticesNext = new FIFO<>();
			verticesNext.push(vertices.get(indexVertexStart));
			FIFO<TypeEdge> edgesNext = new FIFO<>();
			edgesNext.push(null);
			while (!verticesNext.isEmpty())
			{
				result = breadthFirstSearch(verticesNext.pop(), edgesNext.pop(), function, visited, verticesNext, edgesNext, result);
			}
			return result;
		}

		public final int index;
		public final List<TypeEdge> edges;

		public Vertex(int index)
		{
			this.index = index;
			this.edges = new ArrayList<>();
		}

		@Override
		public int compareTo(Vertex<? super TypeVertex, ? super TypeEdge> that)
		{
			return Integer.compare(this.index, that.index);
		}

		@Override
		public String toString()
		{
			return "" + this.index;
		}

		enum Operation
		{
			INVISIT, POSTVISIT, EXPAND
		}
	}

	public static class VertexDefault<TypeEdge extends Edge<VertexDefault<TypeEdge>, TypeEdge>> extends Vertex<VertexDefault<TypeEdge>, TypeEdge>
	{
		public VertexDefault(int index)
		{
			super(index);
		}
	}

	public static class VertexDefaultDefault extends Vertex<VertexDefaultDefault, EdgeDefaultDefault>
	{
		public static Array<VertexDefaultDefault> vertices(int n)
		{
			Array<VertexDefaultDefault> result = new Array<>(n);
			for (int index = 0; index < n; index++)
			{
				result.set(index, new VertexDefaultDefault(index));
			}
			return result;
		}

		public VertexDefaultDefault(int index)
		{
			super(index);
		}
	}

	public static class EdgeDefaultDefault extends Edge<VertexDefaultDefault, EdgeDefaultDefault>
	{
		public EdgeDefaultDefault(VertexDefaultDefault vertex0, VertexDefaultDefault vertex1, boolean bidirectional)
		{
			super(vertex0, vertex1, bidirectional);
		}

		@Override
		public EdgeDefaultDefault getThis()
		{
			return this;
		}
	}

	public static class Tuple2<Type0, Type1>
	{
		public final Type0 v0;
		public final Type1 v1;

		public Tuple2(Type0 v0, Type1 v1)
		{
			this.v0 = v0;
			this.v1 = v1;
		}

		@Override
		public String toString()
		{
			return "(" + this.v0 + ", " + this.v1 + ")";
		}
	}

	static class Wrapper<Type>
	{
		public Type value;

		public Wrapper(Type value)
		{
			this.value = value;
		}

		public Type get()
		{
			return this.value;
		}

		public void set(Type value)
		{
			this.value = value;
		}

		@Override
		public String toString()
		{
			return this.value.toString();
		}
	}

	public static class Tuple3<Type0, Type1, Type2>
	{
		public final Type0 v0;
		public final Type1 v1;
		public final Type2 v2;

		public Tuple3(Type0 v0, Type1 v1, Type2 v2)
		{
			this.v0 = v0;
			this.v1 = v1;
			this.v2 = v2;
		}

		@Override
		public String toString()
		{
			return "(" + this.v0 + ", " + this.v1 + ", " + this.v2 + ")";
		}
	}

	public static class Tuple2Comparable<Type0 extends Comparable<? super Type0>, Type1 extends Comparable<? super Type1>> extends Tuple2<Type0, Type1> implements Comparable<Tuple2Comparable<Type0, Type1>>
	{
		public Tuple2Comparable(Type0 v0, Type1 v1)
		{
			super(v0, v1);
		}

		@Override
		public int compareTo(Tuple2Comparable<Type0, Type1> that)
		{
			int result = this.v0.compareTo(that.v0);
			if (result == 0)
			{
				result = this.v1.compareTo(that.v1);
			}
			return result;
		}
	}

	public static class SingleLinkedList<Type>
	{
		public final Type element;
		public SingleLinkedList<Type> next;

		public SingleLinkedList(Type element, SingleLinkedList<Type> next)
		{
			this.element = element;
			this.next = next;
		}

		public void toCollection(Collection<Type> collection)
		{
			if (this.next != null)
			{
				this.next.toCollection(collection);
			}
			collection.add(this.element);
		}
	}

	public static class Node<Type>
	{
		public static <Type> Node<Type> balance(Node<Type> result)
		{
			while (result != null && 1 < Math.abs(height(result.left) - height(result.right)))
			{
				if (height(result.left) < height(result.right))
				{
					Node<Type> right = result.right;
					if (height(right.right) < height(right.left))
					{
						result = new Node<>(result.value, result.left, right.rotateRight());
					}
					result = result.rotateLeft();
				}
				else
				{
					Node<Type> left = result.left;
					if (height(left.left) < height(left.right))
					{
						result = new Node<>(result.value, left.rotateLeft(), result.right);
					}
					result = result.rotateRight();
				}
			}
			return result;
		}

		public static <Type> Node<Type> clone(Node<Type> result)
		{
			if (result != null)
			{
				result = new Node<>(result.value, clone(result.left), clone(result.right));
			}
			return result;
		}

		public static <Type> Node<Type> delete(Node<Type> node, Type value, Comparator<? super Type> comparator)
		{
			Node<Type> result;
			if (node == null)
			{
				result = null;
			}
			else
			{
				int compare = comparator.compare(value, node.value);
				if (compare == 0)
				{
					if (node.left == null)
					{
						result = node.right;
					}
					else
					{
						if (node.right == null)
						{
							result = node.left;
						}
						else
						{
							Node<Type> first = first(node.right);
							result = new Node<>(first.value, node.left, delete(node.right, first.value, comparator));
						}
					}
				}
				else
				{
					if (compare < 0)
					{
						result = new Node<>(node.value, delete(node.left, value, comparator), node.right);
					}
					else
					{
						result = new Node<>(node.value, node.left, delete(node.right, value, comparator));
					}
				}
				result = balance(result);
			}
			return result;
		}

		public static <Type> Node<Type> first(Node<Type> result)
		{
			while (result.left != null)
			{
				result = result.left;
			}
			return result;
		}

		public static <Type> Node<Type> get(Node<Type> node, Type value, Comparator<? super Type> comparator)
		{
			Node<Type> result;
			if (node == null)
			{
				result = null;
			}
			else
			{
				int compare = comparator.compare(value, node.value);
				if (compare == 0)
				{
					result = node;
				}
				else
				{
					if (compare < 0)
					{
						result = get(node.left, value, comparator);
					}
					else
					{
						result = get(node.right, value, comparator);
					}
				}
			}
			return result;
		}

		public static <Type> Node<Type> head(Node<Type> node, Type value, Comparator<? super Type> comparator)
		{
			Node<Type> result;
			if (node == null)
			{
				result = null;
			}
			else
			{
				int compare = comparator.compare(value, node.value);
				if (compare == 0)
				{
					result = node.left;
				}
				else
				{
					if (compare < 0)
					{
						result = head(node.left, value, comparator);
					}
					else
					{
						result = new Node<>(node.value, node.left, head(node.right, value, comparator));
					}
				}
				result = balance(result);
			}
			return result;
		}

		public static int height(Node node)
		{
			return node == null ? 0 : node.height;
		}

		public static <Type> Node<Type> insert(Node<Type> node, Type value, Comparator<? super Type> comparator)
		{
			Node<Type> result;
			if (node == null)
			{
				result = new Node<>(value, null, null);
			}
			else
			{
				int compare = comparator.compare(value, node.value);
				if (compare == 0)
				{
					result = new Node<>(value, node.left, node.right);
					;
				}
				else
				{
					if (compare < 0)
					{
						result = new Node<>(node.value, insert(node.left, value, comparator), node.right);
					}
					else
					{
						result = new Node<>(node.value, node.left, insert(node.right, value, comparator));
					}
				}
				result = balance(result);
			}
			return result;
		}

		public static <Type> Node<Type> last(Node<Type> result)
		{
			while (result.right != null)
			{
				result = result.right;
			}
			return result;
		}

		public static int size(Node node)
		{
			return node == null ? 0 : node.size;
		}

		public static <Type> Node<Type> tail(Node<Type> node, Type value, Comparator<? super Type> comparator)
		{
			Node<Type> result;
			if (node == null)
			{
				result = null;
			}
			else
			{
				int compare = comparator.compare(value, node.value);
				if (compare == 0)
				{
					result = new Node<>(node.value, null, node.right);
				}
				else
				{
					if (compare < 0)
					{
						result = new Node<>(node.value, tail(node.left, value, comparator), node.right);
					}
					else
					{
						result = tail(node.right, value, comparator);
					}
				}
				result = balance(result);
			}
			return result;
		}

		public static <Type> void traverseOrderIn(Node<Type> node, Consumer<Type> consumer)
		{
			if (node != null)
			{
				traverseOrderIn(node.left, consumer);
				consumer.accept(node.value);
				traverseOrderIn(node.right, consumer);
			}
		}

		public final Type value;
		public final Node<Type> left;
		public final Node<Type> right;
		public final int size;
		private final int height;

		public Node(Type value, Node<Type> left, Node<Type> right)
		{
			this.value = value;
			this.left = left;
			this.right = right;
			this.size = 1 + size(left) + size(right);
			this.height = 1 + Math.max(height(left), height(right));
		}

		public Node<Type> rotateLeft()
		{
			Node<Type> left = new Node<>(this.value, this.left, this.right.left);
			return new Node<>(this.right.value, left, this.right.right);
		}

		public Node<Type> rotateRight()
		{
			Node<Type> right = new Node<>(this.value, this.left.right, this.right);
			return new Node<>(this.left.value, this.left.left, right);
		}
	}

	public static class SortedSetAVL<Type> implements SortedSet<Type>
	{
		public Comparator<? super Type> comparator;
		public Node<Type> root;

		private SortedSetAVL(Comparator<? super Type> comparator, Node<Type> root)
		{
			this.comparator = comparator;
			this.root = root;
		}

		public SortedSetAVL(Comparator<? super Type> comparator)
		{
			this(comparator, null);
		}

		public SortedSetAVL(Collection<? extends Type> collection, Comparator<? super Type> comparator)
		{
			this(comparator, null);
			this.addAll(collection);
		}

		public SortedSetAVL(SortedSetAVL<Type> sortedSetAVL)
		{
			this(sortedSetAVL.comparator, Node.clone(sortedSetAVL.root));
		}

		@Override
		public void clear()
		{
			this.root = null;
		}

		@Override
		public Comparator<? super Type> comparator()
		{
			return this.comparator;
		}

		public Type get(Type value)
		{
			Node<Type> node = Node.get(this.root, value, this.comparator);
			return node == null ? null : node.value;
		}

		@Override
		public SortedSetAVL<Type> subSet(Type valueStart, Type valueEnd)
		{
			return tailSet(valueStart).headSet(valueEnd);
		}

		@Override
		public SortedSetAVL<Type> headSet(Type valueEnd)
		{
			return new SortedSetAVL<>(this.comparator, Node.head(this.root, valueEnd, this.comparator));
		}

		@Override
		public SortedSetAVL<Type> tailSet(Type valueStart)
		{
			return new SortedSetAVL<>(this.comparator, Node.tail(this.root, valueStart, this.comparator));
		}

		@Override
		public Type first()
		{
			return Node.first(this.root).value;
		}

		@Override
		public Type last()
		{
			return Node.last(this.root).value;
		}

		@Override
		public int size()
		{
			return this.root == null ? 0 : this.root.size;
		}

		@Override
		public boolean isEmpty()
		{
			return this.root == null;
		}

		@Override
		public boolean contains(Object value)
		{
			return Node.get(this.root, (Type) value, this.comparator) != null;
		}

		@Override
		public Iterator<Type> iterator()
		{
			Stack<Node<Type>> path = new Stack<>();

			return new Iterator<Type>()
			{
				{
					push(SortedSetAVL.this.root);
				}

				public void push(Node<Type> node)
				{
					while (node != null)
					{
						path.push(node);
						node = node.left;
					}
				}

				@Override
				public boolean hasNext()
				{
					return !path.isEmpty();
				}

				@Override
				public Type next()
				{
					if (path.isEmpty())
					{
						throw new NoSuchElementException();
					}
					else
					{
						Node<Type> node = path.peek();
						Type result = node.value;
						if (node.right != null)
						{
							push(node.right);
						}
						else
						{
							do
							{
								node = path.pop();
							}
							while (!path.isEmpty() && path.peek().right == node);
						}
						return result;
					}
				}
			};
		}

		@Override
		public Object[] toArray()
		{
			return toArray(new Object[0]);
		}

		@Override
		public <T> T[] toArray(T[] ts)
		{
			List<Object> list = new ArrayList<>();
			Node.traverseOrderIn(this.root, list::add);
			return list.toArray(ts);
		}

		@Override
		public boolean add(Type value)
		{
			int sizeBefore = size();
			this.root = Node.insert(this.root, value, this.comparator);
			return sizeBefore != size();
		}

		@Override
		public boolean remove(Object value)
		{
			int sizeBefore = size();
			this.root = Node.delete(this.root, (Type) value, this.comparator);
			return sizeBefore != size();
		}

		@Override
		public boolean containsAll(Collection<?> collection)
		{
			return collection.stream()
					.allMatch(this::contains);
		}

		@Override
		public boolean addAll(Collection<? extends Type> collection)
		{
			return collection.stream()
					.map(this::add)
					.reduce(true, (x, y) -> x | y);
		}

		@Override
		public boolean retainAll(Collection<?> collection)
		{
			SortedSetAVL<Type> set = new SortedSetAVL<>(this.comparator);
			collection.stream()
					.map(element -> (Type) element)
					.filter(this::contains)
					.forEach(set::add);
			boolean result = size() != set.size();
			this.root = set.root;
			return result;
		}

		@Override
		public boolean removeAll(Collection<?> collection)
		{
			return collection.stream()
					.map(this::remove)
					.reduce(true, (x, y) -> x | y);
		}

		@Override
		public String toString()
		{
			return "{" + D_452.toString(this, ", ") + "}";
		}
	}

	public static class SortedMapAVL<TypeKey, TypeValue> implements SortedMap<TypeKey, TypeValue>
	{
		public final Comparator<? super TypeKey> comparator;
		public final SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet;

		public SortedMapAVL(Comparator<? super TypeKey> comparator)
		{
			this(comparator, new SortedSetAVL<>((entry0, entry1) -> comparator.compare(entry0.getKey(), entry1.getKey())));
		}

		private SortedMapAVL(Comparator<? super TypeKey> comparator, SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet)
		{
			this.comparator = comparator;
			this.entrySet = entrySet;
		}

		@Override
		public Comparator<? super TypeKey> comparator()
		{
			return this.comparator;
		}

		@Override
		public SortedMapAVL<TypeKey, TypeValue> subMap(TypeKey keyStart, TypeKey keyEnd)
		{
			return new SortedMapAVL<>(this.comparator, this.entrySet.subSet(new AbstractMap.SimpleEntry<>(keyStart, null), new AbstractMap.SimpleEntry<>(keyEnd, null)));
		}

		@Override
		public SortedMapAVL<TypeKey, TypeValue> headMap(TypeKey keyEnd)
		{
			return new SortedMapAVL<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)));
		}

		@Override
		public SortedMapAVL<TypeKey, TypeValue> tailMap(TypeKey keyStart)
		{
			return new SortedMapAVL<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)));
		}

		public Entry<TypeKey, TypeValue> firstEntry()
		{
			return this.entrySet.first();
		}

		@Override
		public TypeKey firstKey()
		{
			return firstEntry().getKey();
		}

		public Entry<TypeKey, TypeValue> lastEntry()
		{
			return this.entrySet.last();
		}

		@Override
		public TypeKey lastKey()
		{
			return lastEntry().getKey();
		}

		@Override
		public int size()
		{
			return this.entrySet().size();
		}

		@Override
		public boolean isEmpty()
		{
			return this.entrySet.isEmpty();
		}

		@Override
		public boolean containsKey(Object key)
		{
			return this.entrySet().contains(new AbstractMap.SimpleEntry<>((TypeKey) key, null));
		}

		@Override
		public boolean containsValue(Object value)
		{
			throw new UnsupportedOperationException();
		}

		@Override
		public TypeValue get(Object key)
		{
			Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);
			entry = this.entrySet.get(entry);
			return entry == null ? null : entry.getValue();
		}

		@Override
		public TypeValue put(TypeKey key, TypeValue value)
		{
			TypeValue result = get(key);
			Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>(key, value);
			this.entrySet().add(entry);
			return result;
		}

		@Override
		public TypeValue remove(Object key)
		{
			TypeValue result = get(key);
			Entry<TypeKey, TypeValue> entry = new AbstractMap.SimpleEntry<>((TypeKey) key, null);
			this.entrySet.remove(entry);
			return result;
		}

		@Override
		public void putAll(Map<? extends TypeKey, ? extends TypeValue> map)
		{
			map.entrySet()
					.forEach(entry -> put(entry.getKey(), entry.getValue()));
		}

		@Override
		public void clear()
		{
			this.entrySet.clear();
		}

		@Override
		public Set<TypeKey> keySet()
		{
			throw new UnsupportedOperationException();
		}

		@Override
		public Collection<TypeValue> values()
		{
			return new Collection<TypeValue>()
			{
				@Override
				public int size()
				{
					return SortedMapAVL.this.entrySet.size();
				}

				@Override
				public boolean isEmpty()
				{
					return SortedMapAVL.this.entrySet.isEmpty();
				}

				@Override
				public boolean contains(Object value)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public Iterator<TypeValue> iterator()
				{
					return new Iterator<TypeValue>()
					{
						Iterator<Entry<TypeKey, TypeValue>> iterator = SortedMapAVL.this.entrySet.iterator();

						@Override
						public boolean hasNext()
						{
							return this.iterator.hasNext();
						}

						@Override
						public TypeValue next()
						{
							return this.iterator.next().getValue();
						}
					};
				}

				@Override
				public Object[] toArray()
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public <T> T[] toArray(T[] ts)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public boolean add(TypeValue typeValue)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public boolean remove(Object o)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public boolean containsAll(Collection<?> collection)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public boolean addAll(Collection<? extends TypeValue> collection)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public boolean removeAll(Collection<?> collection)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public boolean retainAll(Collection<?> collection)
				{
					throw new UnsupportedOperationException();
				}

				@Override
				public void clear()
				{
					throw new UnsupportedOperationException();
				}
			};
		}

		@Override
		public SortedSetAVL<Entry<TypeKey, TypeValue>> entrySet()
		{
			return this.entrySet;
		}

		@Override
		public String toString()
		{
			return this.entrySet().toString();
		}
	}

	public static class FIFO<Type>
	{
		public SingleLinkedList<Type> start;
		public SingleLinkedList<Type> end;

		public FIFO()
		{
			this.start = null;
			this.end = null;
		}

		public boolean isEmpty()
		{
			return this.start == null;
		}

		public Type peek()
		{
			return this.start.element;
		}

		public Type pop()
		{
			Type result = this.start.element;
			this.start = this.start.next;
			return result;
		}

		public void push(Type element)
		{
			SingleLinkedList<Type> list = new SingleLinkedList<>(element, null);
			if (this.start == null)
			{
				this.start = list;
				this.end = list;
			}
			else
			{
				this.end.next = list;
				this.end = list;
			}
		}
	}

	public static class MapCount<Type> extends SortedMapAVL<Type, Long>
	{
		private int count;

		public MapCount(Comparator<? super Type> comparator)
		{
			super(comparator);
			this.count = 0;
		}

		public long add(Type key, Long delta)
		{
			long result;
			if (delta > 0)
			{
				Long value = get(key);
				if (value == null)
				{
					value = delta;
				}
				else
				{
					value += delta;
				}
				put(key, value);
				result = delta;
			}
			else
			{
				result = 0;
			}
			this.count += result;
			return result;
		}

		public int count()
		{
			return this.count;
		}

		public List<Type> flatten()
		{
			List<Type> result = new ArrayList<>();
			for (Entry<Type, Long> entry : entrySet())
			{
				for (long index = 0; index < entry.getValue(); index++)
				{
					result.add(entry.getKey());
				}
			}
			return result;
		}

		@Override
		public void putAll(Map<? extends Type, ? extends Long> map)
		{
			throw new UnsupportedOperationException();
		}

		@Override
		public Long remove(Object key)
		{
			Long result = super.remove(key);
			this.count -= result;
			return result;
		}

		public long remove(Type key, Long delta)
		{
			long result;
			if (delta > 0)
			{
				Long value = get(key) - delta;
				if (value <= 0)
				{
					result = delta + value;
					remove(key);
				}
				else
				{
					result = delta;
					put(key, value);
				}
			}
			else
			{
				result = 0;
			}
			this.count -= result;
			return result;
		}

		@Override
		public SortedMapAVL<Type, Long> subMap(Type keyStart, Type keyEnd)
		{
			throw new UnsupportedOperationException();
		}

		@Override
		public SortedMapAVL<Type, Long> headMap(Type keyEnd)
		{
			throw new UnsupportedOperationException();
		}

		@Override
		public SortedMapAVL<Type, Long> tailMap(Type keyStart)
		{
			throw new UnsupportedOperationException();
		}
	}

	public static class MapSet<TypeKey, TypeValue> extends SortedMapAVL<TypeKey, SortedSetAVL<TypeValue>> implements Iterable<TypeValue>
	{
		private Comparator<? super TypeValue> comparatorValue;

		public MapSet(Comparator<? super TypeKey> comparatorKey, Comparator<? super TypeValue> comparatorValue)
		{
			super(comparatorKey);
			this.comparatorValue = comparatorValue;
		}

		public MapSet(Comparator<? super TypeKey> comparatorKey, SortedSetAVL<Entry<TypeKey, SortedSetAVL<TypeValue>>> entrySet, Comparator<? super TypeValue> comparatorValue)
		{
			super(comparatorKey, entrySet);
			this.comparatorValue = comparatorValue;
		}

		public TypeValue firstValue()
		{
			TypeValue result;
			Entry<TypeKey, SortedSetAVL<TypeValue>> firstEntry = firstEntry();
			if (firstEntry == null)
			{
				result = null;
			}
			else
			{
				result = firstEntry.getValue().first();
			}
			return result;
		}

		public Iterator<TypeValue> iterator()
		{
			return new Iterator<TypeValue>()
			{
				Iterator<SortedSetAVL<TypeValue>> iteratorValues = values().iterator();
				Iterator<TypeValue> iteratorValue = null;

				@Override
				public boolean hasNext()
				{
					return iteratorValues.hasNext() || (iteratorValue != null && iteratorValue.hasNext());
				}

				@Override
				public TypeValue next()
				{
					if (iteratorValue == null || !iteratorValue.hasNext())
					{
						iteratorValue = iteratorValues.next().iterator();
					}
					return iteratorValue.next();
				}
			};
		}

		public TypeValue lastValue()
		{
			TypeValue result;
			Entry<TypeKey, SortedSetAVL<TypeValue>> lastEntry = lastEntry();
			if (lastEntry == null)
			{
				result = null;
			}
			else
			{
				result = lastEntry.getValue().last();
			}
			return result;
		}

		public boolean add(TypeKey key, TypeValue value)
		{
			SortedSetAVL<TypeValue> set = computeIfAbsent(key, k -> new SortedSetAVL<>(comparatorValue));
			return set.add(value);
		}

		public boolean removeSet(TypeKey key, TypeValue value)
		{
			boolean result;
			SortedSetAVL<TypeValue> set = get(key);
			if (set == null)
			{
				result = false;
			}
			else
			{
				result = set.remove(value);
				if (set.size() == 0)
				{
					remove(key);
				}
			}
			return result;
		}

		@Override
		public MapSet<TypeKey, TypeValue> headMap(TypeKey keyEnd)
		{
			return new MapSet<>(this.comparator, this.entrySet.headSet(new AbstractMap.SimpleEntry<>(keyEnd, null)), this.comparatorValue);
		}

		@Override
		public MapSet<TypeKey, TypeValue> tailMap(TypeKey keyStart)
		{
			return new MapSet<>(this.comparator, this.entrySet.tailSet(new AbstractMap.SimpleEntry<>(keyStart, null)), this.comparatorValue);
		}
	}

	static class IteratorBuffer<Type>
	{
		private Iterator<Type> iterator;
		private List<Type> list;

		public IteratorBuffer(Iterator<Type> iterator)
		{
			this.iterator = iterator;
			this.list = new ArrayList<Type>();
		}

		public Iterator<Type> iterator()
		{
			return new Iterator<Type>()
			{
				int index = 0;

				@Override
				public boolean hasNext()
				{
					return this.index < list.size() || iterator().hasNext();
				}

				@Override
				public Type next()
				{
					if (list.size() <= this.index)
					{
						list.add(iterator.next());
					}
					Type result = list.get(index);
					index += 1;
					return result;
				}
			};
		}
	}

	public static class Tree2D
	{
		public static final int SIZE = 1 << 30;
		public static final Tree2D[] TREES_NULL = new Tree2D[]{null, null, null, null};

		public static int quadrantLeft(int left, int size, int index)
		{
			return left + (index & 1) * size;
		}

		public static int quadrantBottom(int bottom, int size, int index)
		{
			return bottom + (index >> 1) * size;
		}

		public static boolean contains(int x, int y, int left, int bottom, int size)
		{
			return left <= x && x < left + size && bottom <= y && y < bottom + size;
		}

		public static int count(Tree2D[] trees)
		{
			int result = 0;
			for (int index = 0; index < 4; index++)
			{
				if (trees[index] != null)
				{
					result += trees[index].count;
				}
			}
			return result;
		}

		public final Tree2D[] trees;
		public final int count;

		private Tree2D(Tree2D[] trees, int count)
		{
			this.trees = trees;
			this.count = count;
		}

		public Tree2D(Tree2D[] trees)
		{
			this(trees, count(trees));
		}

		public Tree2D()
		{
			this(TREES_NULL);
		}

		public static int count
				(
						int rectangleLeft,
						int rectangleBottom,
						int rectangleRight,
						int rectangleTop,
						Tree2D tree,
						int left,
						int bottom,
						int size
				)
		{
			int result;
			if (tree == null)
			{
				result = 0;
			}
			else
			{
				int right = left + size;
				int top = bottom + size;
				int intersectionLeft = Math.max(rectangleLeft, left);
				int intersectionBottom = Math.max(rectangleBottom, bottom);
				int intersectionRight = Math.min(rectangleRight, right);
				int intersectionTop = Math.min(rectangleTop, top);
				if (intersectionRight <= intersectionLeft || intersectionTop <= intersectionBottom)
				{
					result = 0;
				}
				else
				{
					if (intersectionLeft == left && intersectionBottom == bottom && intersectionRight == right && intersectionTop == top)
					{
						result = tree.count;
					}
					else
					{
						size = size >> 1;
						result = 0;
						for (int index = 0; index < 4; index++)
						{
							result += count
									(
											rectangleLeft,
											rectangleBottom,
											rectangleRight,
											rectangleTop,
											tree.trees[index],
											quadrantLeft(left, size, index),
											quadrantBottom(bottom, size, index),
											size
									);
						}
					}
				}
			}
			return result;
		}

		public int count(int rectangleLeft, int rectangleBottom, int rectangleRight, int rectangleTop)
		{
			return count
					(
							rectangleLeft,
							rectangleBottom,
							rectangleRight,
							rectangleTop,
							this,
							0,
							0,
							SIZE
					);
		}

		public Tree2D setPoint
				(
						int x,
						int y,
						Tree2D tree,
						int left,
						int bottom,
						int size
				)
		{
			Tree2D result;
			if (contains(x, y, left, bottom, size))
			{
				if (size == 1)
				{
					result = new Tree2D(TREES_NULL, 1);
				}
				else
				{
					size = size >> 1;
					Tree2D[] trees = new Tree2D[4];
					for (int index = 0; index < 4; index++)
					{
						trees[index] = setPoint
								(
										x,
										y,
										tree == null ? null : tree.trees[index],
										quadrantLeft(left, size, index),
										quadrantBottom(bottom, size, index),
										size
								);
					}
					result = new Tree2D(trees);
				}
			}
			else
			{
				result = tree;
			}
			return result;
		}

		public Tree2D setPoint(int x, int y)
		{
			return setPoint
					(
							x,
							y,
							this,
							0,
							0,
							SIZE
					);
		}
	}

	public static <Type> List<List<Type>> permutations(List<Type> list)
	{
		List<List<Type>> result = new ArrayList<>();
		result.add(new ArrayList<>());
		for (Type element : list)
		{
			List<List<Type>> permutations = result;
			result = new ArrayList<>();
			for (List<Type> permutation : permutations)
			{
				for (int index = 0; index <= permutation.size(); index++)
				{
					List<Type> permutationNew = new ArrayList<>(permutation);
					permutationNew.add(index, element);
					result.add(permutationNew);
				}
			}
		}
		return result;
	}

	public static List<List<Integer>> combinations(int n, int k)
	{
		List<List<Integer>> result = new ArrayList<>();
		if (k == 0)
		{
		}
		else
		{
			if (k == 1)
			{
				List<Integer> combination = new ArrayList<>();
				combination.add(n);
				result.add(combination);
			}
			else
			{
				for (int index = 0; index <= n; index++)
				{
					for (List<Integer> combination : combinations(n - index, k - 1))
					{
						combination.add(index);
						result.add(combination);
					}
				}
			}
		}
		return result;
	}

	public static <Type> int compare(Iterator<Type> iterator0, Iterator<Type> iterator1, Comparator<Type> comparator)
	{
		int result = 0;
		while (result == 0 && iterator0.hasNext() && iterator1.hasNext())
		{
			result = comparator.compare(iterator0.next(), iterator1.next());
		}
		if (result == 0)
		{
			if (iterator1.hasNext())
			{
				result = -1;
			}
			else
			{
				if (iterator0.hasNext())
				{
					result = 1;
				}
			}
		}
		return result;
	}

	public static <Type> int compare(Iterable<Type> iterable0, Iterable<Type> iterable1, Comparator<Type> comparator)
	{
		return compare(iterable0.iterator(), iterable1.iterator(), comparator);
	}

	private static String nextString() throws IOException
	{
		while ((stringTokenizer == null) || (!stringTokenizer.hasMoreTokens()))
		{
			stringTokenizer = new StringTokenizer(bufferedReader.readLine());
		}
		return stringTokenizer.nextToken();
	}

	private static String[] nextStrings(int n) throws IOException
	{
		String[] result = new String[n];
		{
			for (int index = 0; index < n; index++)
			{
				result[index] = nextString();
			}
		}
		return result;
	}

	public static int nextInt() throws IOException
	{
		return Integer.parseInt(nextString());
	}

	public static void nextInts(int n, int[]... result) throws IOException
	{
		for (int index = 0; index < n; index++)
		{
			for (int value = 0; value < result.length; value++)
			{
				result[value][index] = nextInt();
			}
		}
	}

	public static int[] nextInts(int n) throws IOException
	{
		int[] result = new int[n];
		nextInts(n, result);
		return result;
	}

	public static double nextDouble() throws IOException
	{
		return Double.parseDouble(nextString());
	}

	public static long nextLong() throws IOException
	{
		return Long.parseLong(nextString());
	}

	public static void nextLongs(int n, long[]... result) throws IOException
	{
		for (int index = 0; index < n; index++)
		{
			for (int value = 0; value < result.length; value++)
			{
				result[value][index] = nextLong();
			}
		}
	}

	public static long[] nextLongs(int n) throws IOException
	{
		long[] result = new long[n];
		nextLongs(n, result);
		return result;
	}

	public static String nextLine() throws IOException
	{
		return bufferedReader.readLine();
	}

	public static void close()
	{
		out.close();
	}

	public static int binarySearchMinimum(Function<Integer, Boolean> filter, int start, int end)
	{
		int result;
		if (start == end)
		{
			result = end;
		}
		else
		{
			int middle = start + (end - start) / 2;
			if (filter.apply(middle))
			{
				result = binarySearchMinimum(filter, start, middle);
			}
			else
			{
				result = binarySearchMinimum(filter, middle + 1, end);
			}
		}
		return result;
	}

	public static int binarySearchMaximum(Function<Integer, Boolean> filter, int start, int end)
	{
		return -binarySearchMinimum(x -> filter.apply(-x), -end, -start);
	}

	public static long divideCeil(long x, long y)
	{
		return (x + y - 1) / y;
	}

	public static Set<Long> divisors(long n)
	{
		SortedSetAVL<Long> result = new SortedSetAVL<>(Comparator.naturalOrder());
		result.add(1L);
		for (Long factor : factors(n))
		{
			SortedSetAVL<Long> divisors = new SortedSetAVL<>(result);
			for (Long divisor : result)
			{
				divisors.add(divisor * factor);
			}
			result = divisors;
		}
		return result;
	}

	public static long faculty(int n)
	{
		long result = 1;
		for (int index = 2; index <= n; index++)
		{
			result *= index;
		}
		return result;
	}

	public static LinkedList<Long> factors(long n)
	{
		LinkedList<Long> result = new LinkedList<>();
		Iterator<Long> primes = ITERATOR_BUFFER_PRIME.iterator();
		Long prime;
		while (n > 1 && (prime = primes.next()) * prime <= n)
		{
			while (n % prime == 0)
			{
				result.add(prime);
				n /= prime;
			}
		}
		if (n > 1)
		{
			result.add(n);
		}
		return result;
	}

	public static long gcd(long a, long b)
	{
		while (a != 0 && b != 0)
		{
			if (a > b)
			{
				a %= b;
			}
			else
			{
				b %= a;
			}
		}
		return a + b;
	}

	public static long[] generatePOWER2()
	{
		long[] result = new long[63];
		for (int x = 0; x < result.length; x++)
		{
			result[x] = 1L << x;
		}
		return result;
	}

	public static boolean isPrime(long x)
	{
		boolean result = x > 1;
		Iterator<Long> iterator = ITERATOR_BUFFER_PRIME.iterator();
		Long prime;
		while ((prime = iterator.next()) * prime <= x)
		{
			result &= x % prime > 0;
		}
		return result;
	}

	public static long knapsack(List<Tuple3<Long, Integer, Integer>> itemsValueWeightCount, int weightMaximum)
	{
		long[] valuesMaximum = new long[weightMaximum + 1];
		for (Tuple3<Long, Integer, Integer> itemValueWeightCount : itemsValueWeightCount)
		{
			long itemValue = itemValueWeightCount.v0;
			int itemWeight = itemValueWeightCount.v1;
			int itemCount = itemValueWeightCount.v2;
			for (int weight = weightMaximum; 0 <= weight; weight--)
			{
				for (int index = 1; index <= itemCount && 0 <= weight - index * itemWeight; index++)
				{
					valuesMaximum[weight] = Math.max(valuesMaximum[weight], valuesMaximum[weight - index * itemWeight] + index * itemValue);
				}
			}
		}
		long result = 0;
		for (long valueMaximum : valuesMaximum)
		{
			result = Math.max(result, valueMaximum);
		}
		return result;
	}

	public static boolean knapsackPossible(List<Tuple2<Integer, Integer>> itemsWeightCount, int weightMaximum)
	{
		boolean[] weightPossible = new boolean[weightMaximum + 1];
		weightPossible[0] = true;
		int weightLargest = 0;
		for (Tuple2<Integer, Integer> itemWeightCount : itemsWeightCount)
		{
			int itemWeight = itemWeightCount.v0;
			int itemCount = itemWeightCount.v1;
			for (int weightStart = 0; weightStart < itemWeight; weightStart++)
			{
				int count = 0;
				for (int weight = weightStart; weight <= weightMaximum && (0 < count || weight <= weightLargest); weight += itemWeight)
				{
					if (weightPossible[weight])
					{
						count = itemCount;
					}
					else
					{
						if (0 < count)
						{
							weightPossible[weight] = true;
							weightLargest = weight;
							count -= 1;
						}
					}
				}
			}
		}
		return weightPossible[weightMaximum];
	}

	public static long lcm(int a, int b)
	{
		return a * b / gcd(a, b);
	}

	public static <T> List<T> permutation(long p, List<T> x)
	{
		List<T> copy = new ArrayList<>();
		for (int index = 0; index < x.size(); index++)
		{
			copy.add(x.get(index));
		}
		List<T> result = new ArrayList<>();
		for (int indexTo = 0; indexTo < x.size(); indexTo++)
		{
			int indexFrom = (int) p % copy.size();
			p = p / copy.size();
			result.add(copy.remove(indexFrom));
		}
		return result;
	}

	public static <Type> String toString(Iterator<Type> iterator, String separator)
	{
		StringBuilder stringBuilder = new StringBuilder();
		if (iterator.hasNext())
		{
			stringBuilder.append(iterator.next());
		}
		while (iterator.hasNext())
		{
			stringBuilder.append(separator);
			stringBuilder.append(iterator.next());
		}
		return stringBuilder.toString();
	}

	public static <Type> String toString(Iterator<Type> iterator)
	{
		return toString(iterator, " ");
	}

	public static <Type> String toString(Iterable<Type> iterable, String separator)
	{
		return toString(iterable.iterator(), separator);
	}

	public static <Type> String toString(Iterable<Type> iterable)
	{
		return toString(iterable, " ");
	}

	public static Stream<BigInteger> streamFibonacci()
	{
		return Stream.generate(new Supplier<BigInteger>()
		{
			private BigInteger n0 = BigInteger.ZERO;
			private BigInteger n1 = BigInteger.ONE;

			@Override
			public BigInteger get()
			{
				BigInteger result = n0;
				n0 = n1;
				n1 = result.add(n0);
				return result;
			}
		});
	}

	public static Stream<Long> streamPrime(int sieveSize)
	{
		return Stream.generate(new Supplier<Long>()
		{
			private boolean[] isPrime = new boolean[sieveSize];
			private long sieveOffset = 2;
			private List<Long> primes = new ArrayList<>();
			private int index = 0;

			public void filter(long prime, boolean[] result)
			{
				if (prime * prime < this.sieveOffset + sieveSize)
				{
					long remainingStart = this.sieveOffset % prime;
					long start = remainingStart == 0 ? 0 : prime - remainingStart;
					for (long index = start; index < sieveSize; index += prime)
					{
						result[(int) index] = false;
					}
				}
			}

			public void generatePrimes()
			{
				Arrays.fill(this.isPrime, true);
				this.primes.forEach(prime -> filter(prime, isPrime));
				for (int index = 0; index < sieveSize; index++)
				{
					if (isPrime[index])
					{
						this.primes.add(this.sieveOffset + index);
						filter(this.sieveOffset + index, isPrime);
					}
				}
				this.sieveOffset += sieveSize;
			}

			@Override
			public Long get()
			{
				while (this.primes.size() <= this.index)
				{
					generatePrimes();
				}
				Long result = this.primes.get(this.index);
				this.index += 1;
				return result;
			}
		});
	}

	public static long totient(long n)
	{
		Set<Long> factors = new SortedSetAVL<>(factors(n), Comparator.naturalOrder());
		long result = n;
		for (long p : factors)
		{
			result -= result / p;
		}
		return result;
	}

	public static void main(String[] args)
	{
		try
		{
			solve();
		} catch (IOException exception)
		{
			exception.printStackTrace();
		}
		close();
	}

	public static LinkedList<Integer> digits(long n)
	{
		LinkedList<Integer> result = new LinkedList<>();
		while (n > 0)
		{
			result.addFirst((int) n % 10);
			n /= 10;
		}
		return result;
	}

	public static int mod(int count)
	{
		int result = 1;
		for (int index = 0; index < count; index++)
		{
			result *= 10;
		}
		return result;
	}

	public static void solve() throws IOException
	{
		int n = nextInt();
		List<Integer> digits = digits(n);
		int ninesCountMax;
		if (digits.get(0) < 5)
		{
			ninesCountMax = digits.size() - 1;
		}
		else
		{
			ninesCountMax = digits.size();
		}
		int mod = mod(ninesCountMax);
		int result = 0;
		for (int index = 1; index <= n; index++)
		{
			if (index % mod == mod - 1)
			{
				result += index / mod;
			}
			else
			{
				if (index % mod < 5 * (mod / 10))
				{
					result += Math.max(0, index / mod);
				}
				else
				{
					result += Math.max(0, index / mod + 1);
				}

			}
		}
		out.println(result);
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 * @author pttrung
 */
public class D_Round_452_Div2 {

    public static long MOD = 1000000007;
    //static boolean print = false;
    static int[][][][][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        String n = in.next();
        int result = n*(n - 1)/2;
        dp = new int[n.length()][2][2][3][3];
        for (int i = 1; i <= n.length(); i++) {
            for (int[][][][] a : dp) {
                for (int[][][] b : a) {
                    for (int[][] c : b) {
                        for (int[] d : c) {
                            Arrays.fill(d, -1);
                        }
                    }
                }
            }
            //            print = i == 1;
            int v = cal(n.length() - 1, i, 0, 0, 0, 0, new int[n.length()], new int[n.length()], n);

            if (v == 0) {
                break;
            }
            result = v;
        }
        out.println(result / 2);
        out.close();
    }

    static int cal(int index, int total, int x, int y, int a, int b, int[] A, int[] B, String n) {

        if (index == -1) {

            if (a <= 1 && b <= 1 && x == 1 && y == 1) {

                return 1;
            }
            return 0;
        }
        if (dp[index][x][y][a][b] != -1) {
            return dp[index][x][y][a][b];
        }
        int result = 0;
        int cur = n.charAt(index) - '0';
        if (total > 0) {

            for (int i = 0; i < 10; i++) {
                int left = 9 - i;
                //System.out.println(i + " " + left);
                A[index] = i;
                B[index] = left;
                result += cal(index - 1, total - 1, i != 0 ? 1 : x, left != 0 ? 1 : y, i > cur ? 2 : (i < cur ? 1 : a), left > cur ? 2 : (left < cur ? 1 : b), A, B, n);
            }
        } else {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    A[index] = i;
                    B[index] = j;
                    result += cal(index - 1, total, i != 0 ? 1 : x, j != 0 ? 1 : y, i > cur ? 2 : (i < cur ? 1 : a), j > cur ? 2 : (j < cur ? 1 : b), A, B, n);
                }
            }
        }
        return dp[index][x][y][a][b] = result;
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();

            int sum = N + (N - 1);

            if (onlyNines(sum)) {
                out.println(1);
                return;
            }

            int len = (sum + "").length();

            String suffix = nines(len - 1);

            int ans = 0;

            for (char c = '0'; c <= '8'; c++) {
                int p = Integer.parseInt(c + suffix);
                if (p <= N + 1) {
                    ans += p / 2;
                } else if (p <= N + N - 1) {
                    ans += 1 + (2 * N - 1 - p) / 2;
                }
            }

            out.println(ans);
        }

        private String nines(int cnt) {
            char[] ans = new char[cnt];
            Arrays.fill(ans, '9');
            return new String(ans);
        }

        private boolean onlyNines(int num) {
            while (num > 0) {
                if (num % 10 != 9) return false;
                num /= 10;
            }
            return true;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();
      int end = interval(y,a);
      int beg = end-1;
      if(y>0 && y<2a && x<a/2 && x>-a/2){
         System.out.println(interval(y,a));
      }
      else if(end%2==0) // means theres only one block{
         if(x<a/2 && x>-a/2 && y<end && y>beg){
            System.out.println(3*end/2-1);
         }
         else {
            System.out.println(-1);
         }
      else {
         if(x<a && x>0 && y<end && y> beg){
            System.out.println(3*end/2);
         }
         else if(x>-a && x<0 && y<end && y>beg){
            System.out.println(3*end/2-1);
         }
         else {
            System.out.println(-1);
         }
      }

   }
   public static int interval(int y, int a){
      int result=0;
      while(a*result<y) result++;

      return result;
   }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);

        int a = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        if ( x<Math.round(((double) a)/2) && x>-Math.round(((double) a)/2) && y>0 && y<a)
            System.out.print(1);
        else
        {
            if (y%a==0)
            {
                System.out.print(-1);
                System.exit(0);
            }
            y-=a;
            int nom = y/a;
            int two = nom/2;
            if (nom % 2 == 0)
            {
                if (x>-Math.round(((double) a)/2) && x<Math.round(((double) a)/2))
                    System.out.print(nom+2+two);
                else
                    System.out.print(-1);
            }package pkg141b;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);

        int a = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        if ( x<Math.round(((double) a)/2) && x>-Math.round(((double) a)/2) && y>0 && y<a)
            System.out.print(1);
        else
        {
            if (y%a==0)
            {
                System.out.print(-1);
                System.exit(0);
            }
            y-=a;
            int nom = y/a;
            int two = nom/2;
            if (nom % 2 == 0)
            {
                if (x>-Math.round(((double) a)/2) && x<Math.round(((double) a)/2))
                    System.out.print(nom+2+two);
                else
                    System.out.print(-1);
            }
            else
            {
                if (x>-a && x<0)
                    System.out.print(nom+2+two);
                else
                    if (x>0 && x<a)
                        System.out.print(nom+3+two);
                    else
                        System.out.print(-1);
            }
        }
    }
}

            else
            {
                if (x>-a && x<0)
                    System.out.print(nom+2+two);
                else
                    if (x>0 && x<a)
                        System.out.print(nom+3+two);
                    else
                        System.out.print(-1);
            }
        }
    }
}


///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package codeforces;

import java.util.Scanner;

public class B141 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int x = in.nextInt();
        int y = in.nextInt();
        int q = -1;
        int h = 0;
        if (y % a == 0) {
            q = -1;
        } else {
            if (x == 0 & (y / a) != 0 & ((y / a) % 2) == 0) {
                q = -1;
            } else if (x == 0 & (y / a) == 0) {
                q = 1;s
            } else {
                h = (y / (2 * a)) + 1;

                if (y % (2 * a) > a & Math.abs(x) < Math.abs(a / 2.0)) {

                    q = 3 * h - 1;
                } else if (y % (2 * a) < a & a > Math.abs(x)) {
                    if ((y / a) == 0 && Math.abs(x) > (a / 2.0)) {
                        q = -1;
                    } else {
                        q = 3 * h - 2;
                    }
                } else {
                    q = -1;
                }
            }
        }
        System.out.println(q);
    }
}


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter pw;

	static int maxX, maxY;

	public static void main(String[] args) throws IOException	{
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int a = readInt();
		int x = readInt();
		int y = readInt();
		if(y%a==0)	{
			pw.println(-1);
		}
		else	{
			int min = 1;
			for(int row = 1; true; row++)	{
				if(y > (row-1) * a)	{
					if(row == 1 || row%2 == 0)	{
						double leftX = -a/2.;
						double rightX = a/2.;
						if(x > leftX && x < rightX)	{
							pw.println(min);
						}
						else	{
							pw.println(-1);
						}
					}
					else	{
						if(x > -a && x < 0)	{
							pw.println(min);
						}
						else if(x > 0 && x < a)	{
							pw.println(min+1);
						}
						else	{
							pw.println(-1);
						}
					}
				}
				else	{
					if(row == 1 || row%2==0)
						min++;
					else
						min += 2;
				}
			}
		}
		pw.close();
	}

	public static boolean valid(long x, long y)	{
		return x >= 1 && x <= maxX && y >= 1 && y <= maxY;
	}

	public static long readLong() throws IOException	{
		return Long.parseLong(nextToken());
	}
	public static double readDouble() throws IOException	{
		return Double.parseDouble(nextToken());
	}
	public static int readInt() throws IOException	{
		return Integer.parseInt(nextToken());
	}
	public static short readShort() throws IOException	{
		return Short.parseShort(nextToken());
	}
	public static String nextToken() throws IOException	{
		while(st == null || !st.hasMoreTokens())	{
			if(!br.ready())	{
				pw.close();
				System.exit(0);
			}
			st = new StringTokenizer(br.readLine());
		}
		return st.nextToken();
	}
}


    import java.util.*;
    import java.lang.*;
    // StringBuilder uses java.lang

    public class mainClass {

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int numPres = sc.nextInt();
            int numPeop = sc.nextInt();
            int[] t = new int[1000000006];
            t[0]=1;
            for (int i=1;i<1000000006;i++) {
                t[i]=(2*t[i-1]) % 1000000007;
            }
            long fact = new long[1000000006];
            fact[0]=1;
            for (int i=0;i<numPres;i++) {
                t[i+1]=((((t[i]*(numPres-i)) % 1000000007)*fastPow(i+1,1000000005,1000000007)) % 1000000007);
            }
            long ans = 0;
            for (int i=0;i<n;i++) {
                long z = ((numPres-i)*numPeop) % 1000000006;
                long v = (t[z]*fact[i]) % 1000000007;
                if (i % 2 == 0) {
                    ans+=v;
                } else {
                    ans-=v;
                    ans+=1000000007;
                }
                ans= ans % 1000000007;
            }
            System.out.println(ans);
        }

        public static long fastPow(int base,long exp,int mod) {
            if (exp==0) {
                return 1;
            } else {
                if (exp % 2 == 1) {
                    long z = fastPow(base,(exp-1)/2,mod);
                    return ((((z*base) % mod) * z) % mod);
                } else {
                    long z = fastPow(base,exp/2,mod);
                    return ((z*z) % mod);
                }
            }
        }
    }


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        int m = 1000000007;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long N = in.nextLong();
            long M = in.nextLong();
            out.println(power((power(2, M) - 1) % m, N));
        }

        private long power(long a, long b) {
            return (b != 0) ? power(a * a % m, b / 2) * ((b % 2 != 0) ? a : 1) % m : 1;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Math;
public class hh {

	public static final int  Mod = 1000000007;

	public static void main(String[] args)  {
		MyScanner in = new MyScanner();
		long kinds = in.nextInt();
		long boxes = in.nextInt();
	    double ans = 1;
	    while(boxes>=30)
	    {
	    	ans =((ans%Mod)*(Math.pow(2,30)%Mod))%Mod;
	    	boxes-=30;
	    }
	   for(int i = 1;i<=boxes;i++)
	    	ans = ((ans%Mod)*2)%Mod;
	    ans-=1;
	    for(int i = 1;i<kinds;i++)
	       ans = ((ans%Mod)*(ans%Mod))%Mod;
	    System.out.println((int)ans);
	}

	}

class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    public MyScanner() {
       br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine(){
        String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
    }

 }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.lang.management.MemoryType;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Function;

public class Main {

    static int [][] comb;//may need BigInteger, if the numbers are large, use a treemap
    static  int MOD=(int)(10e9+7);

    static int nCr1(int n , int k)
    {
        if(n < k)
            return 0;
        if(k == 0 || k == n)
            return 1;
        if(comb[n][k] != -1)
            return comb[n][k];
        if(n - k < k)
            return comb[n][k] = nCr1(n, n - k)%MOD;
        return comb[n][k] = nCr1(n - 1, k - 1)%MOD + nCr1(n - 1, k)%MOD;
    }

    static int modPow(int a, int e, int mod)	// O(log e)
    {
        a %= mod;
        int res = 1;
        while(e > 0)
        {
            if((e & 1) == 1)
                res = (res * a) % mod;
            a = (a * a) % mod;
            e >>= 1;
        }
        return res;
    }

    public static void main (String[]args) throws IOException {
        Scanner in = new Scanner(System.in);
        try(PrintWriter or = new PrintWriter(System.out)) {

          int n=in.nextInt();
          int m=in.nextInt();
          int ans=modPow(n+1,m)%MOD;
          or.println(n==1?ans-1:ans);

        }
    }

    static int getlen(int r,int l,int a){
        return (r-l+1+1)/(a+1);
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

class Pair  {
    int first, second;

    public Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }

}

class Tempo {

    int num;
    int index;

    public Tempo(int num, int index) {
        this.num = num;
        this.index = index;
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class prob47 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new prob47().solve(in,out);
        in.close();
        out.close();
    }

    private void solve(Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
int ways = 0;
        for(int a=0; a<=1000; a++) {
           for(int b=0; b<=1000; b++) {
                if(a*a+b==n && a+b*b==m) ways++;
            }
        }
out.println(ways);
    }
}


import java.util.Scanner;
public class Class1{
    public static void main(String[] args){
        int n,m;
        Scanner in = new Scanner(System.in);
        n=in.nextInt();
        m=in.nextInt();
        int i=0,j=0;
        int count=0;
        for(i=0;i<n;i++){
            int sa=i*i;
            for(j=0;j<m;j++){
                int sb=j*j;
                if(sa+b==n&&sb+a==m)
                count++;
            }
        }
        System.out.print(count);

    }
}


/* package whatever; // don't place package name! */
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class test
{
	public static void main (String[] args) throws java.lang.Exception
	{
	int a=0, b=0;
	int n, m, x, y,
	int counter=0;

	Scanner in = new Scanner(System.in);
	n = in.nextInt();
	m = in.nextInt();
	x = n;
	while(x!=0){
        a = 0;
        y = m;
        while(y!=0){
            if(a*a+b == n && a + b*b == m)
            count +=1;
            a++;
            y--;
        }
        b++;
        x--;
    }

    System.out.println(count);
    }
}


input java.util.*;

public class Test{
    public static void main(String [] s){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int sch = 0;
        for(int i = 0; i < n ; i ++){
             for(int j = 0 ; j < m; j ++){
                 int x2 = Math.pow(i,2);
                 int y2 = Math.pow(j,2);
                 if((x2 + j) == n){
                     if((y2 + i) == m){
                         sch ++;
                     }
                 }
             }
        }
        System.out.println(sch);
    }
}


import java.util.*;

public class CodeForces785C{
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long n= sc.nextLong(), m= sc.nextLong();
		long l = 0,r=(long)2e9,mid,eat;

		while(l<r){
			mid = (l+r)/2;
			eat = mid*(mid+1)/2;

			if(n-eat<=m+1+mid){
				r=mid;
			}
			else{
				l=mid+1;
			}

		}

		System.out.print(Math.min(n, m+l+1));
	}
}


import java.util.Scanner;

public class ejercicio3 {

	public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

       if(m>=n) System.out.println(n);
       else{
    	   double x = -1/2.0+Math.sqrt(1+8*(n-m))/2;

    	   long newX = (long) x;
    	   if((newX*newX+newX)/2>=n-m){
    		   while((newX*newX+newX)/2>=n-m){
    			   newX--;
    		   }
    		   newX++;
    	   }else{
    		   while((newX*newX+newX)/2<n-m){
    			   newX++;
    		   }
    	   }

    	   System.out.println((long)(newX+m));

//    	   System.out.println(solve(1l,1000000000l,500000000));
       }

	}

	private static long solve(long l, long m, int i) {

		if((Math.pow(i, 2)+i)/2 -0,001){

		}

		return ;
	}

}


public class Solution {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		long days = k;
		int r = n-k;
		long factor;
		for ( factor=(long)Math.sqrt(2*r); true; factor++) {
			if (factor*factor + factor >= 2*(n-k)) break;
		}
		System.out.println(days + factor);
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Swatantra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long m = in.nextLong();

            if (m => n) {
                out.println(n);
            } else {
                int i;
                long ar[] = new long[1000000];
                for (i = 0; i < ar.length; i++) {
                    if (i <= m + 1)
                        ar[i] = n;
                    else {
                        long k = (i - (m + 1));
                        ar[i] = n - (k * (k + 1) / 2);

                    }
                    //  out.println("i="+i+" val="+ar[i]);

                }

                long ans = find(ar, m);

                out.println(ans);

            }
        }

        long find(long ar[], long m) {
            int min = 1;

            int max = ar.length;
            int flag = 0;
            int mid = 0;
            while (min <= max) {
                mid = (min + max) / 2;

                if (ar[mid] == m) {
                    flag = 1;
                    break;
                } else if (ar[mid] > m) {
                    min = mid + 1;
                } else {
                    max = mid - 1;
                }

            }
            if (ar[mid] <= m)
                return mid - 1;
            else
                return mid;

        }

    }
}


public class DaVinciPowers {

    public static void main(String[] args)
    {

        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        System.out.println(daVincisPower(input));

    }

    public static long  daVincisPower(int exponent){
        long power = 0;
        if(exponent<13){
            double base = 2.0;
            power = (long) Math.pow(base,exponent);

        }
        else{
            power = 8092;
            int difference = exponent - 13;
            for(int i=0;i<difference;i++){
                power = power*2;
            }
        }
        return power;
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{

    public static void main(String...l)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        System.out.println(1LL<<n);

    }

}


public class DaVinci{
    public static void main(String[] args) {
        Scanner f = new Scanner(System.in);
        int a = f.nextInt();
        if (a < 13) {
            int ans = 1;
            for (int i = 1; i < a; i++) ans *= 2;
            System.out.println(ans);
        }
        else {
            long ans = 8092;
            for (int i = 13; i < a; i++) ans *= 2;
            System.out.println(ans);
        }
        f.close();
    }

}


import java.io.*;
import java.util.*;

public class Solution {

    static void calc(double[] a, double x, double y, double z) {
        if (x == 1)
            a[0] = a[1] = a[2] = a[3] = 1;
        else if (x > 1) {
            a[0] = z * Math.log(y) + Math.log(Math.log(x));
            a[1] = y * Math.log(z) + Math.log(Math.log(x));
            a[2] = Math.log(z * y * Math.log(x));
            a[3] = a[2];
        }

        if (y == 1)
            a[4] = a[5] = a[6] = a[7] = 1;
        else if (y > 1) {
            a[4] = z * Math.log(x) + Math.log(Math.log(y));
            a[5] = x * Math.log(z) + Math.log(Math.log(y));
            a[6] = Math.log(z * x * Math.log(y));
            a[7] = a[6];
        }

        if (z == 1)
            a[8] = a[9] = a[10] = a[11] = 1;
        else if (z > 1) {
            a[8] = y * Math.log(x) + Math.log(Math.log(z));
            a[9] = x * Math.log(y) + Math.log(Math.log(z));
            a[10] = Math.log(y * x * Math.log(z));
            a[11] = a[10];
        }
    }

    static void solve(InputReader in, OutputWriter out) {
        double x = in.nextDouble();
        double y = in.nextDouble();
        double z = in.nextDouble();

        String[] ans = {"x^y^z", "x^z^y", "(x^y)^z", "(x^z)^y", "y^x^z", "y^z^x", "(y^x)^z", "(y^z)^x", "z^x^y", "z^y^x", "(z^x)^y", "(z^y)^x"};
        double[] a = new double[12];
        if (x <= 1 && y <= 1 && z <= 1) {
            calc(a, 1 / x, 1 / y, 1 / z);

            double min = Double.MAX_VALUE;
            int index = -1;
            for (int i = 0; i < a.length; i++)
                if (a[i] < min) {
                    min = a[i];
                    index = i;
                }
            out.print(ans[index]);

        } else {
            calc(a, x, y, z);

            double max = Double.MIN_VALUE;
            int index = -1;
            for (int i = 0; i < a.length; i++)
                if (a[i] > max) {
                    max = a[i];
                    index = i;
                }
            out.print(ans[index]);
        }
    }

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        solve(in, out);
        in.close();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        InputReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }

        String nextLine() {
            String line = null;
            try {
                line = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return line;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return null;
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    static class OutputWriter {
        BufferedWriter bw;

        OutputWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        void print(int i) {
            print(Integer.toString(i));
        }

        void println(int i) {
            println(Integer.toString(i));
        }

        void print(long l) {
            print(Long.toString(l));
        }

        void println(long l) {
            println(Long.toString(l));
        }

        void print(double d) {
            print(Double.toString(d));
        }

        void println(double d) {
            println(Double.toString(d));
        }

        void print(boolean b) {
            print(Boolean.toString(b));
        }

        void println(boolean b) {
            println(Boolean.toString(b));
        }

        void print(char c) {
            try {
                bw.write(c);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(char c) {
            println(Character.toString(c));
        }

        void print(String s) {
            try {
                bw.write(s);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        void println(String s) {
            print(s);
            print('\n');
        }

        void close() {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Ratkweshandcheese {

	public static void main(String[] args)
	{
		MyScannerrat sc=new MyScannerrat();
		double x=sc.nextDouble();
		double y=sc.nextDouble();
		double z=sc.nextDouble();
		boolean fmax=true;
		if((x<1) && (y<1) && (z<1) )
		{
			fmax=false;
		}
		int count=0;
		int index=0;
		double max=0;
		String types[]={"x^y^z",
						"x^z^y",
						"(x^y)^z",
						"(x^z)^y",
						"y^x^z",
						"y^z^x",
						"(y^x)^z",
						"(y^z)^x",
						"z^x^y",
						"z^y^x",
						"(z^x)^y",
						"(z^y)^x"};
		for(int i=1;i<=12;i++)
		{
			double res;
			double base;
			double log;
			double other;
			count++;
			if(count==5)
				count=1;
			if(i<=4)
			{	base=x;

			}
			else if(i<=8){
				base=y;
			}
			else{
				base=z;
			}
			if(base<=1)
				continue;
			if(i==1 || i==3 ||i==10 || i==12)
				log=y;
			else if(i==2 || i==4 ||i==6 || i==8)
				log=z;
			else
				log=x;
			other=x+y+z-base-log;
			if(count==1 || count==2)
			{	res=typea(base,log,other);
			}
			else
				res=typeb(log,other,base);

			if(fmax && res>max)
			{
				max=res;
				index=i;
			}
			else if(!fmax && res<max)
			{
				max=res;
				index=i;
			}
		}
		System.out.println(types[index-1]);
	}
	public static double typea(double base,double log,double other)
	{
		return other*Math.log(log)+lnln(base);

	}
	static double lnln(double v)
	{
		if(v<1)
			v=1/v;
		return Math.log(Math.log(v));
	}
	public static double typeb(double a,double b,double base)
	{
		return Math.log(a)+Math.log(b)+lnln(base);
	}
}
class MyScannerrat
{
	BufferedReader br;
	StringTokenizer st;
	MyScannerrat()
	{
		br=new BufferedReader(new InputStreamReader(System.in));
	}
	String next()
	{

		while(st==null || !st.hasMoreTokens())
		{
			try
			{
				st=new StringTokenizer(br.readLine());
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		return st.nextToken();

	}
	int nextInt()
	{
		return Integer.parseInt(next());
	}
	long nextLong()
	{
		return Long.parseLong(next());
	}
	double nextDouble()
	{
		return Double.parseDouble(next());
	}
	String nextLine()
	{
		String str="";
		try
		{
			str=br.readLine();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return str;

	}
}


import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int cheeseTypeCount = sc.nextInt();
        int maxHeight = sc.nextInt();
        int minCrushHeight = sc.nextInt();
        int[] values = new int[cheeseTypeCount];
        int[] heights = new int[cheeseTypeCount];
        for (int x = 0; x < cheeseTypeCount; x++) {
            values[x] = sc.nextInt();
            heights[x] = sc.nextInt();
        }
        sc.close();
        int[][] maxValue = new int[maxHeight + 1][((maxHeight * 5) / 4) + 1];
        boolean[][] isValid = new boolean[maxHeight + 1][((maxHeight * 5) / 4) + 1];
        isValid[0][0] = true;
        int maxTowerValue = 0;
        for (int crushedHeight = 0; crushedHeight <= maxHeight; crushedHeight++) {
            for (int trueHeight = 0; trueHeight <= (maxHeight * 5) / 4; trueHeight++) {
                if (isValid[crushedHeight][trueHeight]) {
                    for (int cheeseType = 0; cheeseType < cheeseTypeCount; cheeseType++) {
                        int newCrushedHeight = crushedHeight + ((heights[cheeseType] * 4) / 5);
                        int newTrueHeight = ((heights[cheeseType] >= minCrushHeight) ? crushedHeight : trueHeight) + heights[cheeseType];
                        int newValue = maxValue[crushedHeight][trueHeight] + values[cheeseType];
                        if (newCrushedHeight <= maxHeight && newTrueHeight <= (maxHeight * 5) / 4) {
                            maxValue[newCrushedHeight][newTrueHeight] = Math.max(maxValue[newCrushedHeight][newTrueHeight], newValue);
                            if (newTrueHeight <= maxHeight) maxTowerValue = Math.max(maxTowerValue, newValue);
                            isValid[newCrushedHeight][newTrueHeight] = true;
                        }
                    }
                }
            }
        }
        System.out.println(maxTowerValue);
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

/**
 * @auther chao
 * @date 16/1/31
 */

public class CF4 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        Scanner in = new Scanner(System.in);
        double x = in.nextDouble();
        double y = in.nextDouble();
        double z = in.nextDouble();
        EXP[] exps = new EXP[9];
        exps[0] = new EXP(x, y,   z, "x^y^z", 0);
        exps[1] = new EXP(x, z,   y, "x^z^y", 1);
        exps[2] = new EXP(x, y*z, 1, "(x^y)^z", 2);
        exps[3] = new EXP(y, x,   z, "y^x^z", 3);
        exps[4] = new EXP(y, z,   x, "y^z^x", 4);
        exps[5] = new EXP(y, x*z, 1, "(y^x)^z", 5);
        exps[6] = new EXP(z, x,   y, "z^x^y", 6);
        exps[7] = new EXP(z, y,   x, "z^y^x", 7);
        exps[8] = new EXP(z, x*y, 1, "(z^x)^y", 8);
        /*
        int p = 0;
        for (int i = 1; i < 9; i++) {
            if (exps[i].compareTo(exps[p]) > 0) p =i;
        }*/
        Arrays.sort(exps);
        System.out.println(exps[p].exp);

    }
}
class EXP implements Comparable<EXP>{
    double x;
    double y;
    double z;
    int p;
    String exp;
    public EXP(double x, double y, double z, String exp, int p) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.exp = exp;
        this.p = p;
    }
    public int compareTo(EXP exp) {
        double lnx1 = Math.log(x);
        double lnx2 = Math.log(exp.x);
        double cmp;
        int op = 1;
        if (lnx1 * lnx2 > 0) {
            if (lnx1 < 0) {
                op = -1;
                lnx1 = -lnx1;
                lnx2 = -lnx2;
            }
            cmp = (z*Math.log(y)+Math.log(lnx1))-(exp.z*Math.log(exp.y)+Math.log(lnx2));
        } else {
            cmp = lnx1 - lnx2;
        }
        if (op < 0) cmp = -cmp;
        if (cmp == 0) return exp.p - p;
        return cmp > 0 ? 1 : -1;

    }
}


import java.util.*;
import java.io.*;
public class Main{
public static void main(String... args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] temp = br.readLine().split(" ");
int a = Integer.parseInt(temp[0]);
int c = Integer.parseInt(temp[1]);
List<Integer> ta = new ArrayList<Integer>();
List<Integer> tc = new ArrayList<Integer>();
while (a>0 || c>0){
  ta.add(a%3);
  tc.add(c%3);
  a/=3;
  c/=3;
}
List<Integer> tb = new ArrayList<Integer>(ta.size());
for (int i=0; i<ta.size(); i++){
  int x = tc.get(i)+3-ta.get(i);
  x%=3;
  tb.add(x);
}

long x = 0;
for (int i=0; i<tb.size(); i++){
  x+=tb.get(i)*Math.pow(3,i);
}

System.out.println(x);

}
}


import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.ArrayList;
import java.text.DecimalFormat;

public class Main {
    public static void cout(String s)
    {
        System.out.print(s);

    }
    public static void main(String[] args) {
         ArrayList <Integer> list=new ArrayList<Integer>();
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {

        }
    }

}


import java.util.Scanner;
public class Ternary {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int num2 = sc.nextInt();
		int mayor = num2;
		int cont = 0;
		int fin = 0;
		while(fin != num2) {
			while(num >= 3 || num2 >= 3) {
				fin += (((num % 3 + num2 % 3) % 3 + (mayor % 3)) % 3) * Math.pow(3, cont);
				num /= 3;
				num2 /= 3;
				mayor /= 3;
				cont++;
			}
			fin += (((num % 3 + num2 % 3) % 3 + (mayor % 3)) % 3) * Math.pow(3, cont);
		}
		System.out.println(fin);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author 3mara
 */
public class Main {

    public static String getTernary(int x) {

        String returnVal = "";
        int result = x;
        while (result > 0) {
            returnVal = (result % 3) + returnVal;
            result = result / 3;
        }
        return returnVal;
    }

    public static void read2() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            try {
                String ar;
                if (!(ar = br.readLine()).equals("")) {
                    String[] array = ar.split(" ");
                    int a = Integer.parseInt(array[0]);
                    int c = Integer.parseInt(array[1]);
                    String aString = "";
                    String cString = "";
                    String result = "";

                    aString = getTernary(a);
                    cString = getTernary(c);

                    while (aString.length() < cString.length()) {
                        aString = "0" + aString;
                    }
                    while (aString.length() > cString.length()) {
                        cString = "0" + cString;
                    }
                    for (int i = 0; i < aString.length(); i++) {
                        if (aString.charAt(i) > cString.charAt(i)) {
                            result += (cString.charAt(i) + 3 - aString.charAt(i));
                        } else {
                            result += (cString.charAt(i) - aString.charAt(i));
                        }
                    }
                    int finalval = 0;
                    int index = 0;
                    for (int i = result.length() - 1; i >= 0; i--) {
                        finalval += ((Math.pow(3.0, index)) * Integer.parseInt((result.charAt(i) + "")));
                        index++;
                    }

                    System.out.println(finalval);
                }
            } catch (NumberFormatException e) {
            }
        } catch (ArrayIndexOutOfBoundsException e) {
        } catch (IOException ex) {
        }
    }

        */
    public static void main(String[] args) {
        // TODO code application logic here
        read2();
    }
}


import java.io.*;
import java.util.*;

public class Solution{

	public static void main(String[] args){
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input = br.readLine();
		int len = input.length();

		Set<String> set = new HashSet<String>();
		set.add(input);
		input = input+input;
		int ans = 1;
		for(int i=0;i<len;i++){
			String cand = input.substring(i,len);
			if(!set.contains(cand)){
				set.add(cand);
				ans++;
			}
		}
		System.out.println(ans);
	}

}


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		int count = 0;
		for (int i = 0; i < in.length() - 1; i++) {
			for (int j = i + 1; j < in.length(); j++) {
				if (in.charAt(i) == in.charAt(j)) {
					count++;
					break;
				}
			}
		}
		System.out.println(in.length()-count);
	}
}


import java.util.Scanner;
import java.util.HashSet;

public class Hongcow{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        HashSet<String> words = new HashSet<>();
        char[] newWord = scan.next().toCharArray();

        words.add(new String(newWord));

        for(int i=0;i<newWord.length;i++){
            char[] nextWord = new char[newWord.length];

            for(int j=0;j<newLord.length;j++){
                nextWord[j] = newWord[(j+i)%newWord.length];
            }

            words.add(new String(nextWord));
        }

        System.out.println(words.size());
    }
}


import java.util.HashSet;
import java.util.Scanner;

public class A {

	public static void main(String[] args){

		Scanner s = new Scanner(System.in);

		while(s.hasNext()){
			HashSet<String> h = new HashSet<String>();
			String c = s.nextLine();
			String b = "";
			int count = 1;
			h.add(c);
			for(int i = 0; i< c.length(); i++){
				b = c.substring(1, c.length()) + c.charAt(0);
				if(!bbbh.contains(b)){
					count++;
				}
				c = b;
				h.add(c);
			}
			System.out.println(count);
		}

	}
}