There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines.You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other.

The first line contains a single integer n (2 ≤ n ≤ 109) — the number of shovels in Polycarp's shop.

Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.  Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≤ 109 the answer doesn't exceed 2·109.

NoteIn the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:  2 and 7;  3 and 6;  4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp:  1 and 8;  2 and 7;  3 and 6;  4 and 5;  5 and 14;  6 and 13;  7 and 12;  8 and 11;  9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50.

import java.util.Collections;
import java.util.Scanner;

public class Main implements Runnable {

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = new Scanner(System.in).nextInt();
        int len = (n / 5 + "").length();
        long sum = Long.parseLong(String.join("", Collections.nCopies(len, "9")));
        long changeUnit = sum + 1;
        long count = 0;
        if (n <= 4) {
            int[] ans = {0, 0, 1, 3, 6};
            System.out.println(ans[n]);
            return;
        }
        while (2 * n - 1 >= sum) {
            if (n >= sum) {
                count += sum / 2;
            } else {
                count += (sum - 1 - (sum - 1 - n) * 2) / 2;
            }
            sum += changeUnit;
        }
        System.out.println(count);
    }
}

import java.util.*;
public class tp {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long m=n+(n-1);
		String s=String.valueOf(m);
		int size=s.length();
		//System.out.println(size);
		StringBuilder number=new StringBuilder("");
		for (int i=0; i<size; i++) {
			number=number.append("9");
		}
		if (Long.parseLong(number.toString())==m) {
			System.out.println(1);
		}
		else {
			long res=0;
			number=number.deleteCharAt(0);
			//System.out.println(number);
			if (number.length()>0) {
				long ans=Long.parseLong(number.toString());
				if(n>=ans) {
					res+=ans/2;
				}
				else {
					ans=2*n-ans;
					res+=(ans+1)/2;
				}
				for (int i=1; i<9; i++) {
					StringBuilder one=new StringBuilder(String.valueOf(i));
					one=one.append(number);
					ans=Long.parseLong(one.toString());

				    if (m>=ans) {
				    	if(n>=ans) {
							res+=ans/2;
						}
				    	else {
				    		ans=2*n-ans;
				    		res+=(ans+1)/2;
				    	}
				    }
				    else {
				    	break;
				    }
				}
			}
			else {
				res+=n*(n-1)/2;
			}

			System.out.println(res);

		}
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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);
        d899 solver = new d899();
        solver.solve(1, in, out);
        out.close();
    }

    static class d899 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int max = 2 * n - 1;
            int digitCount = 0;
            int nineCount = 0;
            while (max > 0) {
                if (max % 10 == 9) nineCount++;
                digitCount++;
                max /= 10;
            }
            if (digitCount == nineCount) {
                out.println(1);
                return;
            }
            max = 2 * n - 1;
            long posMax = 0;
            long firstDigit = 1;
            for (int i = 1; i < digitCount; i++) {
                posMax *= 10;
                posMax += 9;
                firstDigit *= 10;
            }
            long ans = 0;
            for (int i = 0; i < 10; i++) {
                long first = posMax - n;
                if (first >= n) break;
                if (first < 1) first = 1;
                long last = posMax - first;
                ans += (last - first + 1) / 2;
                posMax += firstDigit;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

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

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.util.NoSuchElementException;
import java.io.InputStream;

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

  static class TaskD {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      long n = in.nextInt();
      if (n <= 4) {
        out.println(n * (n - 1) / 2);
        return;
      }
      int length = Long.toString(n + n - 1).length();
      List<Long> targets = new ArrayList<>();
      if (n + n - 1 == (long) Math.pow(10, length) - 1) {
        targets.add(n + n - 1);
      } else {
        long head = (long) Math.pow(10, length - 1);
        long remain = head - 1;
        for (int i = 0; i < 10; i++) {
          if (head * i + remain <= n + n - 1) {
            targets.add(head * i + remain);
          } else {
            break;
          }
        }
      }
      long res = 0;
      for (long target : targets) {
        long lhs = Math.max(1, target - n), rhs = Math.min(n, target / 2);
        res += rhs - lhs + 1;
      }
      out.println(res);
    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    private OutputWriter(Writer writer, boolean autoFlush) {
      this.writer = new PrintWriter(new BufferedWriter(writer, 32767), autoFlush);
    }

    public OutputWriter(Writer writer) {
      this(writer, true);
    }

    public OutputWriter(OutputStream outputStream) {
      this(new OutputStreamWriter(outputStream), false);
    }

    public OutputWriter println(long value) {
      writer.println(value);
      return this;
    }

    public void close() {
      writer.close();
    }

  }

  static class InputReader {
    public final BufferedReader reader;
    public StringTokenizer tokenizer = null;

    public InputReader(Reader reader) {
      this.reader = new BufferedReader(reader, 32767);
    }

    public InputReader(InputStream inputStream) {
      this(new InputStreamReader(inputStream));
    }

    public String next() {
      if (hasNext()) return tokenizer.nextToken();
      else throw new NoSuchElementException();
    }

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

    public boolean hasNext() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String nextLine = reader.readLine();
          if (nextLine == null) return false;
          tokenizer = new StringTokenizer(nextLine);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.hasMoreTokens();
    }

  }
}

/* package codechef; // 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		MyScanner sc = new MyScanner();
		long n = sc.nextLong();
		long maxNum = n + (n - 1);
// 		System.out.println(maxNum);
		long[] ten = new long[10];
		long z = 1L;
		long cur = 0L;
		int numNine = 0;
		for (int i = 0; i < 10; ++i){
		    cur = z * 9L + cur;
		    if (cur <= maxNum){
		        numNine = i + 1;
		    }
		    ten[i] = z;
		    z *= 10L;
		}

		cur = 0L;

		for (int i = 0 ; i < numNine; ++i){
		    cur = 9L * ten[i] + cur;
		}
		long res = 0L;
		for (int i = 0; i <= 9; ++i){
		    long k = ten[numNine] * i + cur;
		  //  System.out.println(k);
		    if (k > maxNum) continue;
		    long g = Math.min(k-1, n);
		    long t = (k + 1L) / 2L;
		    if (k % 2L == 0) t++;
		  //  System.out.println("k: " + k + " g: " + g + " t: " + t);
		    res += Math.max(0L, g - t + 1L);
		}

		System.out.println(res);

	}

	public static int GCD(int a, int b){
	    while (b > 0){
	        int tmp = b;
	        b = a % b;
	        a = tmp;
	    }
	    return a;
	}

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static 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.*;
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 long mod(int count)
	{
		long 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();
		}
		long result;
		if (ninesCountMax == 0)
		{
			result = n * (n - 1) / 2;
		}
		else
		{
            long mod = mod(ninesCountMax);
            result = 0;
            for (long index = mod - 1; index <= n + n - 1; index+=mod)
            {
                long largestMax = Math.min(index - 1, n);
                long largestMin = Math.max(index / 2 + 1, index - (n - 1));
                result +=  largestMax + 1 - largestMin;
            }
		}
		out.println(result);
	}
}

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

public class Solution
{
    public static void main(String[] args)
    {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        //--------Solution---------------------------------------------//
        long n = sc.nextInt();

        long sum = 2*n - 1;
        long ans=0;

        if(n==2) ans=1;
        else if(n==3) ans=3;
        else if(n==4) ans=6;

        else {
            if (all9(sum)) ans = 1;
            else {
                int n9 = numdig(sum) - 1;

                for (int i = 0; ; i++) {
                    long req = nextnum(i, n9);
                    if (req > sum) break;
                    else {
                        if (req <= n) {
                            ans += (req - 1) / 2;
                        } else {
                            ans += (2 * n - req + 1) / 2;
                        }
                    }
                }
            }
        }
        out.println(ans);
        //-------------------------------------------------------------//

        out.close();
    }

    static boolean all9(long n){
        while(n>0){
            if(n%10 != 9) return false;
            n /= 10;
        }
        return true;
    }

    static int numdig(long n){
        int ans=0;
        while(n>0){n/=10; ans++;}
        return ans;
    }

    static long nextnum(long st, long n){
        return st*((long)Math.pow(10,n)) + ( (long) Math.pow(10,n) ) - 1;
    }

    //-----------PrintWriter for faster output-------------------------//
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------------------//
    public static 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;
        }

    }
}

class Pair implements Comparable<Pair>
{
    int first;
    int second;

    Pair(int f,int s){
        first=f;
        second=s;
    }

    public int compareTo(Pair p){
        return this.first - p.first;
    }
}

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

public class D {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = { 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, Integer.MAX_VALUE };
		TreeSet<Integer> set = new TreeSet<>();
		for (int x : arr)
			set.add(x);

		Integer x = set.floor(2 * n - 1);
		if (x == null) {
			System.out.println((n * (n - 1) / 2));
		}
		else {
			nines = ("" + x).length();
			nines = 10 - nines;
			num = new int[10];
			String s = ("" + n);
			for (int i = 0; i < s.length(); i++)
				num[10 - s.length() + i] = (s.charAt(i) - '0');
			memo = new long[11][2][2][2][2];
			for (long[][][][] zz : memo)
				for (long[][][] zzz : zz)
					for (long[][] xx : zzz)
						for (long[] yy : xx)
							Arrays.fill(yy, -1);
			long ans = solve(0, 0, 0, 0, 0) / 2;
			System.out.println(ans);

		}
	}

	static int nines;
	static int[] num;
	static long[] memo[][][][];
	static int[] na = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	static int[] nb = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };

	static long solve(int idx, int less1, int less2, int non1, int non2) {
		if (idx == 10)
			if (non1 == 1 && non2 == 1)
				return 1;
			else
				return 0;
		if (memo[idx][less1][less2][non1][non2] != -1)
			return memo[idx][less1][less2][non1][non2];

		long ans = 0;
		int cur = num[idx];
		if (idx < nines) {
			if (less1 == 1) {
				if (less2 == 1) {
					for (int i = 0; i < 10; i++)
						for (int j = 0; j < 10; j++) {
							int n1 = non1;
							int n2 = non2;
							if (i > 0)
								n1 = 1;
							if (j > 0)
								n2 = 1;
							ans = ans + solve(idx + 1, 1, 1, n1, n2);
						}
					// ans = ans + 100 * solve(idx + 1, less1, less2);
				}
				else {
					for (int i = 0; i < 10; i++)
						for (int j = 0; j < 10; j++) {
							if (j > cur)
								continue;
							int l2 = 1;
							if (j == cur)
								l2 = 0;
							int n1 = non1;
							int n2 = non2;
							if (i > 0)
								n1 = 1;
							if (j > 0)
								n2 = 1;
							ans = ans + solve(idx + 1, 1, l2, n1, n2);
						}
					// ans = ans + 10 * (cur) * solve(idx + 1, 1, 1);
					// ans = ans + 10 * solve(idx + 1, less1, less2);
				}
			}
			else {
				if (less2 == 1) {
					for (int i = 0; i < 10; i++)
						for (int j = 0; j < 10; j++) {
							if (i > cur)
								continue;
							int l2 = 1;
							if (i == cur)
								l2 = 0;
							int n1 = non1;
							int n2 = non2;
							if (i > 0)
								n1 = 1;
							if (j > 0)
								n2 = 1;
							ans = ans + solve(idx + 1, l2, 1, n1, n2);
						}
					// ans = ans + 10 * (cur) * solve(idx + 1, 1, 1);
					// ans = ans + 10 * solve(idx + 1, less1, less2);
				}
				else {
					for (int i = 0; i < 10; i++)
						for (int j = 0; j < 10; j++) {
							if (j > cur || i > cur)
								continue;
							int l2 = 1;
							int l1 = 1;
							if (i == cur)
								l1 = 0;
							if (j == cur)
								l2 = 0;
							int n1 = non1;
							int n2 = non2;
							if (i > 0)
								n1 = 1;
							if (j > 0)
								n2 = 1;
							ans = ans + solve(idx + 1, l1, l2, n1, n2);
						}
					// ans = ans + solve(idx + 1, less1, less2);
					// ans = ans + cur * solve(idx + 1, 0, 1);
					// ans = ans + cur * solve(idx + 1, 1, 0);
					// ans = ans + cur * cur * solve(idx + 1, 1, 1);
				}
			}
		}
		else {
			for (int i = 0; i < na.length; i++) {
				if (less1 == 0 && na[i] > cur || less2 == 0 && nb[i] > cur)
					continue;
				int l1 = less1;
				int l2 = less2;
				if (less1 == 0)
					if (na[i] < cur)
						l1 = 1;
				if (less2 == 0)
					if (nb[i] < cur)
						l2 = 1;
				int n1 = non1;
				int n2 = non2;
				if (na[i] > 0)
					n1 = 1;
				if (nb[i] > 0)
					n2 = 1;
				ans = ans + solve(idx + 1, l1, l2, n1, n2);
			}
		}

		return memo[idx][less1][less2][non1][non2] = ans;
	}

	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 String nextLine() throws IOException {
			return br.readLine();
		}
	}
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.valueOf(st.nextToken());
		int sum = n + n - 1;
		//System.out.println("sum==" + sum);
		if (checkAllNine(sum) || sum == 9) {
			System.out.println(1);
			return;
		}
		if (sum < 9) {
			System.out.println(n * (n - 1) / 2);
			return;
		}

		//

		long ans = 0;

		// len >= 2
		int len = cntLen(sum);
		int left = sum / (int) (Math.pow(10, len - 1));

		int firstNum = getFirst(sum, len, left);

		len = cntLen(firstNum);
		int loop = (int) (Math.pow(10, len - 1));
		left = firstNum / (int) (Math.pow(10, len - 1));
		if (firstNum < 10)
			left = 0;
		if (left == 9) {
			if (firstNum <= n)
				System.out.println(firstNum / 2);
			else {
				System.out.println(n - firstNum / 2);
			}
			return;
		}
		// System.out.println("left==" + left);
		while (left >= 0) {
			// System.out.println("firstNum==" + firstNum);
			if (firstNum > n) {
				int half = firstNum / 2 + 1;
				ans += (n - half + 1);
			}

			else
				ans += firstNum / 2;
			// System.out.println("ans==" + ans);
			firstNum -= loop;
			left--;
		}
		System.out.println(ans);
	}

	public static int getFirst(int sum, int len, int left) {
		int firstNum = -1;
		int rightSum = 0;

		for (int i = 0; i < len - 1; i++) {
			rightSum *= 10;
			rightSum += 9;
		}
		if (sum % (int) (Math.pow(10, len - 1)) != rightSum)
			left--;
		// System.out.println("rightSum==" + rightSum);
		firstNum = left * (int) (Math.pow(10, len - 1)) + rightSum;
		//System.out.println("firstNum==" + firstNum);
		// System.out.println();
		return firstNum;
	}

	public static int cntLen(int n) {
		int i = 0;
		while (n != 0) {
			i++;
			n /= 10;
		}
		return i;
	}

	public static boolean checkAllNine(int n) {
		while (n != 0) {
			if (n % 9 != 0)
				return false;
			n /= 10;
		}
		return true;
	}

	public static void printArray(int a[], int n) {
		for (int i = 0; i < n; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

}

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

public class Solution {

        public static long mod = 1000000007;
     public static void main(String[] args) throws IOException{

//         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
         PrintWriter  pw = new PrintWriter(System.out);
         Scanner in = new Scanner(System.in);

         long n = in.nextLong();
        if(n<5)
        {
            if(n==1)
                pw.print(0);
            else if(n==2)
                pw.print(1);
            else if(n==3)
                pw.print(3);
            else if(n==4)
                pw.print(6);

        }

         else
         {
         long max = (long)2*n - 1;
         int dig = 0;
         long tmp = max;
         long ans = 0;
         while(tmp>0)
         {

             tmp /= 10;
             dig++;
         }
         int nine = dig-1;
         if(max==Math.pow(10, dig)-1)
         {
             nine = dig;
            ans = 1;
             pw.print(1);
         }
             else
             {

                 String s = "";

                 for(int i=0; i<nine; i++)
                    s += '9';
                 //pw.print(n);

                 for(int i=0; i<9; i++)
                 {
                     long num = Long.parseLong((i+s));
                      //  pw.print(num);
                     if(num>max)
                         break;
                     if(num<=n)
                         ans +=num/2;
                     else {
                        // pw.print("-");

                         ans += 1+(max - num)/2;
                     }
                   //  pw.print(ans+" "+n/2);

                 }

                  pw.print(ans);
             }

         }

         pw.flush();
         pw.close();

       }
    }

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.*;

public class _899D {

    private static final int E5 = 100000;
    private static final long E18 = 1000000000000000000L;
    private static final int[] P5 = new int[11];

    private static void solve(Scanner scan, PrintWriter pw) {

        long[] pow10s = new long[10];
        pow10s[0] = 1;
        for(int i = 1; i < 10; i++)
            pow10s[i] = pow10s[i-1] * 10;

        int n = scan.nextInt();
        int numDigits = 0;
        int highestDigit = 0;

        for(int tmp = n; tmp > 0; tmp /= 10) {
            numDigits++;
            highestDigit = tmp % 10;
        }

        int numNines = highestDigit < 5 ? numDigits-1 : numDigits;

        int suffix = 0;
        for(int i = 0; i < numNines; i++) {
            suffix = suffix * 10 + 9;
        }

        int max = n+n-1;

        long pt = pow10s[numNines];

        long ans = 0;
        for(int i = 0; i < 9; i++) {
            long v = pt * i + suffix;
            if(v == 0)
                continue;
            if(v > max)
                break;
            long pairs = numPairs(v, n);
            ans += pairs;
        }

        pw.println(ans);

    }

    private static long numPairs(long m, int n) {
        long max = n < m ? n : m-1;
        long min = m / 2 + 1;
        return max - min + 1;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024 * 64));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 1024 * 64));
        solve(scan, pw);
        pw.flush();
    }

}

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

public class d {

    static long[][][] memo;
    static int len = 10;
    static int[] max;
    static long[] base1 = new long[] {0, 1};
    static long[] base0 = new long[] {-100, 0};

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

        memo = new long[12][len][];
        max = new int[len];
        int n = in.nextInt();
        int idx = 0;
        while (n > 0) {
            max[idx++] = n % 10;
            n /= 10;
        }
        out.println(go(1, 0, 0)[1]);

        out.close();
    }

    static long[] go(int bound, int boundPair, int i) {
        int key = bound * 3 + boundPair;
        if (i == len) {
            return bound != 2 && boundPair == 1 ? base1 : base0;
        }
        if (memo[key][i] != null)
            return memo[key][i];
        long[] res = new long[2];
        for (int a = 0; a <= 9; a++) {
            for (int b = 0; b <= 9; b++) {
                int newBound = b < max[i] ? 0 : (b == max[i] ? bound : 2);
                int newBoundPair = 1;
                if (a > b || (a == b && (boundPair == 2 || i == 0)))
                    newBoundPair = 2;
                if (boundPair + a == 0)
                    newBoundPair = 0;
                long[] tmp = go(newBound, newBoundPair, i + 1);
                long tmp9s = a + b == 9 ? tmp[0] + 1 : 0;
                long tmpCount = tmp[1];
                if (tmpCount == 0) continue;
                if (tmp9s > res[0]) {
                    res[0] = tmp9s;
                    res[1] = 0;
                }
                if (tmp9s == res[0])
                    res[1] += tmpCount;
            }
        }
        return memo[key][i] = res;
    }
    static Random rand = new Random();
    static void sort(int[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            int tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static void sort(long[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            long tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static void sort(double[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            double tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    static long[] eEuclid(long a, long b) {
        if (b == 0) return new long[] { a, 1, 0 };
        long[] ans = eEuclid(b, a % b);
        long temp = ans[1] - ans[2] * (a / b);
        ans[1] = ans[2];  ans[2] = temp;
        return ans;
    }
    static long modInverse(long a, long m) {
        return ((eEuclid(a, m)[1] % m) + m) % m;
    }
    static class IntList {
        static int[] EMPTY = {};
        int[] a = EMPTY;
        int n = 0;
        void add(int v) {
            if (n >= a.length)
                a = Arrays.copyOf(a, (n << 2) + 8);
            a[n++] = v;
        }
        int get(int idx) {
            return a[idx];
        }
        int size() {
            return n;
        }
    }
    static class DisjointSet {
        int[] s, r;
	public DisjointSet(int n) {
            s = new int[n]; r = new int[n];
            for (int i = 0; i < n; i++) s[i] = i;
        }
        public int find(int i) { return s[i] == i ? i : (s[i] = find(s[i])); }
	public void union(int a, int b) {
            if(r[a = find(a)] == r[b = find(b)]) r[a]++;
            if(r[a] >= r[b]) s[b] = a; else s[a] = b;
        }
    }
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
            st = new StringTokenizer("");
        }
        public String next() throws IOException {
            if(st.hasMoreTokens())
                return st.nextToken();
            else
                st = new StringTokenizer(br.readLine());
            return next();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
        public int[] nextOffsetIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt() - 1;
            return arr;
        }
        public int[] nextIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }
        public int[][] nextIntArray(int n, int m) throws IOException {
            int[][] arr = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextInt();
            return arr;
        }
        public long[] nextLongArray(int n) throws IOException {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextLong();
            return arr;
        }
        public long[][] nextLongArray(int n, int m) throws IOException {
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextLong();
            return arr;
        }
        public double[] nextDoubleArray(int n) throws IOException {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextDouble();
            return arr;
        }
        public double[][] nextDoubleArray(int n, int m) throws IOException {
            double[][] arr = new double[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextDouble();
            return arr;
        }
        public char[][] nextCharArray(int n, int m) throws IOException {
            char[][] arr = new char[n][];
            for (int i = 0; i < n; i++)
                arr[i] = next().toCharArray();
            return arr;
        }
    }
}

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 (sum < 9) {
                out.println(N * (N - 1) / 2);
                return;
            }

            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++) {
                long p = Long.parseLong(c + suffix);
                if (p <= N) {
                    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.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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();
            if (N <= 4) {
                out.println(N * (N - 1) / 2);
                return;
            }

            long max = N + N - 1;
            long ten = 1;
            while (ten * 10 <= max) ten *= 10L;
            long maxNines = getMaxNines(max, ten); //x99999

            String str = "" + maxNines;
            long ans = 0;
            if (str.charAt(0) == '9') {
                long half = (maxNines + 1) / 2;
                ans = Math.min(maxNines - 1, N) - half + 1;
            } else {
                long cnt = ten * 10L - 1;
                while (cnt >= ten) {
                    if (cnt <= maxNines) {
                        ans += compute(cnt, N);
                    }
                    cnt -= ten;
                }
                if (cnt > 0) {
                    long half = (cnt + 1) / 2;
                    long tmp = Math.min(cnt - 1, N) - half + 1;
                    ans += tmp;
                }
            }

            out.println(ans);
        }

        private long compute(long cnt, long n) {//39999
            long half = (cnt + 1) / 2;
            if (cnt <= n) {
                return cnt - half;
            }
            return n - half + 1;
        }

        private long getMaxNines(long max, long ten) {
            if ((max + 1) % ten == 0) return max; //x9999999

            return (max / ten) * ten - 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());
        }

    }
}

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 (sum < 9) {
                out.println(N * (N - 1) / 2);
                return;
            }

            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++) {
                long p = Long.parseLong(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.io.*;
import java.lang.reflect.Field;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        new Main();
    }

    Main() throws IOException {
        solve();
    }

    void solve() throws IOException {
        long N = Reader.nextInt();
        if(N < 5){System.out.println(N*(N-1)/2); return;}
        else{
            long x = 2*N-1;
            int c = 0;
            int t = 0;
            while(x > 0){if(x%10 == 9){c++;}x /= 10;t++;}
            if(t == c){System.out.println(1);}
            else{
                x = 2*N - 1;
                StringBuilder S = new StringBuilder();
                for(int i = 0; i < t-1; i++) S.append("9");
                int w =  0;
                int count = 0;
                while(Long.parseLong(w + S.toString()) <= x){
                    if(Long.parseLong(w + S.toString()) <= N) count += (Long.parseLong(w + S.toString()) - 1)/2;
                    else count += (N - (Long.parseLong(w + S.toString()) - N) + 1)/2;
                    w++;
                }
                System.out.println(count);
            }
        }
    }

}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    /** call this method to initialize reader for InputStream */

    static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");

    }

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {

                tokenizer = new StringTokenizer(reader.readLine());

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    static String next() throws IOException {

        while ( ! tokenizer.hasMoreTokens() ) {

            tokenizer = new StringTokenizer(

                    reader.readLine() );

        }
        return tokenizer.nextToken();

    }

    static int nextInt() throws IOException {

        return Integer.parseInt( next() );

    }

    static double nextDouble() throws IOException {

        return Double.parseDouble( next() );

    }

    static long nextLong() {

        return Long.parseLong(nextToken());
    }
}

import java.util.Scanner;

public class P899D
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if (n <= 4)
		{
			int[] ans = {0, 0, 1, 3, 6};
			System.out.println(ans[n]);
			return;
		}
		long pow10 = 1;
		while (true)
		{
			pow10 *= 10;
			if (n+n-1 < pow10-1)
			{
				pow10 /= 10;
				break;
			}
		}
		long total = 0;
		long nines = pow10-1;
		while (true)
		{
			if (n+n-1 < nines)
				break;
			long min = Math.max(1, nines-n);
			long max = nines/2;
			total += max - min + 1;

			nines += pow10;
		}
		System.out.println(total);
	}
}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = 2 * n - 1;
		int l = Integer.toString(m).length();
		char[] c = Integer.toString(m).toCharArray();
		boolean b = true;
		for (int i = 0; i < c.length; i++) {
			if (c[i] != '9')
				b = false;
		}
		if (b)
			System.out.println(1);
		else {
			if (n >= 5) {
				l--;
				String s = "";
				for (int i = 0; i < l; i++)
					s += "9";
				int k = Integer.parseInt(s);
				int k1 = k + 1;
				long n1 = k;
				int count = 0;
				while (n1 <= m) {
					if (n1 < n)
						count += (n1 / 2);
					else {
						count += n1 / 2;
						count -= Math.max((n1 - n - 1), 0);
					}

					n1 += k1;
				}
				System.out.println(count);
			} else
				System.out.println(n*(n-1)/2);
		}
	}

}

/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

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

public class Code270
{

	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		long n = in.nextLong();
		if(n<=4)
		{
			pw.print((n*(n-1))/2);
		}
		else
		{
			long max = 999999999;

			while(true)
			{
				long x = max/2;
				x++;
				if(n>=x)
					break;
				max/=10;
			}
			//System.out.println(max);
			long ans = 0;
			long temp = max;
			long count = 0;

			while(temp>0)
			{
				count++;
				temp/=10;
			}

			long multi = 1;
			while(count>0)
			{
				multi*=10;
				count--;
			}

			for(long i=0;i<=8;i++)
			{
				long cur = i*multi + max;
				if(n>=cur)
					ans += (cur/2);
				else if(n<cur/2)
					break;
				else
					ans += (n - cur/2);
			}

			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}

	static class InputReader
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}

	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static HashSet<Integer> primeFactorization(int n)
	{
		HashSet<Integer> a =new HashSet<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(2*i);j<n;j+=i)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

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

	public static void extendedEuclid(int A,int B)
	{
		if(B==0)
		{
			d = A;
			p = 1 ;
			q = 0;
		}
		else
		{
			extendedEuclid(B, A%B);
			int temp = p;
			p = q;
			q = temp - (A/B)*q;
		}
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static boolean isPrime(int n)
	{

	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    if (n%2 == 0 || n%3 == 0)
	    	return false;

	    for (int i=5; i*i<=n; i=i+6)
	    {
	        if (n%i == 0 || n%(i+2) == 0)
	           return false;
	    }

	    return true;
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString()
		{
			return x+" "+y;
		}

		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}

		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}

/* Author: Ronak Agarwal */
import java.io.* ; import java.util.* ; import java.math.* ;
import static java.lang.Math.min ;
import static java.lang.Math.max ;
import static java.lang.Math.abs ;
/* Thread is created here to increase the stack size of the java code so that recursive dfs can be performed */
public class Codeshefcode{
	public static void main(String[] args) throws IOException{
		new Thread(null,new Runnable(){	public void run(){ exec_Code() ;} },"Solver",1l<<27).start() ;
	}
	static void exec_Code(){
		try{
			Solver Machine = new Solver() ;
			Machine.Solve() ; Machine.Finish() ;}
		catch(Exception e){ e.printStackTrace() ; print_and_exit() ;}
		catch(Error e){ e.printStackTrace() ; print_and_exit() ; }
	}
	static void print_and_exit(){ System.out.flush() ; System.exit(-1) ;}
}
/* Implementation of the pair class, useful for every other problem */
class pair implements Comparable<pair>{
	long x ; long y ;
	pair(long _x,long _y){ x=_x ; y=_y ;}
	public int compareTo(pair p){
		return (this.x<p.x ? -1 : (this.x>p.x ? 1 : (this.y<p.y ? -1 : (this.y>p.y ? 1 : 0)))) ;
	}
}
/* Main code starts here */
class Solver extends Template{
	public void Solve() throws IOException{
		long n = ip.i() ;
		long nn = n+(n-1) ;
		if(nn<9){
			pln((n*(n-1))/2) ;
			return ;
		}
		if(ispow10(nn+1)){
			pln(1) ;
			return ;
		}
		long eqnn = eqn(nn) ;
		long incr = eqnn+1 ;
		long res=0 ;
		while(eqnn<=nn){
			long val=poss(n,eqnn) ;
			res+=val ;
			eqnn+=incr ;
		}
		pln(res) ;
	}
	long poss(long n,long sm){
		if(sm<=n){
			if(sm%2==1) return (sm-1)/2 ;
			else return (sm-2)/2 ;
		}
		long ll = (sm-n) ;
		long rr = min(n,sm%2==0 ? sm/2-1 : sm/2) ;
		if(ll<=rr) return (rr-ll+1) ;
		return 0 ;
	}
	long eqn(long i){
		long res=0 ;
		while(i!=0){
			res = 10*res+9 ;
			i/=10 ;
		}
		return res/10 ;
	}
	boolean ispow10(long i){
		while(i!=1){
			if(i%10!=0) return false ;
			i/=10 ;
		}
		return true ;
	}
}

/* All the useful functions,constants,renamings are here*/
class Template{
	/* Constants Section */
	final int INT_MIN = Integer.MIN_VALUE ; final int INT_MAX = Integer.MAX_VALUE ;
	final long LONG_MIN = Long.MIN_VALUE ; final long LONG_MAX = Long.MAX_VALUE ;
	static long MOD = 1000000007 ;
	static Reader ip = new Reader(System.in) ;
	static PrintWriter op = new PrintWriter(System.out) ;
	/* Methods for writing */
	static void p(Object o){ op.print(o) ; }
	static void pln(Object o){ op.println(o) ;}
	static void Finish(){ op.flush();	op.close(); }
	/* Implementation of operations modulo MOD */
	static long inv(long a){ return powM(a,MOD-2) ; }
	static long m(long a,long b){ return (a*b)%MOD ; }
	static long d(long a,long b){ return (a*inv(b))%MOD ; }
	static long powM(long a,long b){
		if(b<0) return powM(inv(a),-b) ;
		long val=a ; long ans=1 ;
		while(b!=0){
			if((b&1)==1) ans = (ans*val)%MOD ;
			val = (val*val)%MOD ;
			b/=2 ;
		}
		return ans ;
	}
	/* Renaming of some generic utility classes */
	final static class mylist extends ArrayList<Long>{}
	final static class myset extends TreeSet<Long>{}
	final static class mystack extends Stack<Integer>{}
	final static class mymap extends TreeMap<Long,Integer>{}
}

class Reader{
	BufferedReader reader;
	StringTokenizer tkz;
	Reader(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input)) ;
		tkz = new StringTokenizer("") ;
	}
	String s() throws IOException{
		while (!tkz.hasMoreTokens()) tkz = new StringTokenizer(reader.readLine()) ;
		return tkz.nextToken() ;
	}
	int i() throws IOException{ return Integer.parseInt(s()) ;}
	long l() throws IOException{ return Long.parseLong(s()) ;}
	double d() throws IOException{	return Double.parseDouble(s()) ;}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 *
 * @author shankar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        private boolean isAllNines(long num) {
            while (num > 0) {
                if (num % 9 > 0) {
                    return false;
                }

                num /= 10;
            }

            return true;
        }

        private int numDigits(long num) {
            int count = 0;
            while (num > 0) {
                count += 1;
                num /= 10;
            }

            return count;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long N = in.nextLong();
            long maxN = 2 * N - 1;

            if (isAllNines(maxN)) {
                out.println(1);
            } else if (N < 5) {
                out.println((N * (N - 1)) / 2);
            } else {
                long numNines = numDigits(maxN) - 1;
                long currentNiner = (long) Math.pow(10, numNines) - 1;
                long ans = 0;
                while (currentNiner <= maxN) {
                    if (currentNiner <= N)
                        ans += currentNiner / 2;
                    else
                        ans += (N - currentNiner / 2);

                    currentNiner += (long) Math.pow(10, numNines);
                }
                out.println(ans);
            }

        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}

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 long[][][][][] 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();
        long N = Long.parseLong(n);
        long result = N*(N - 1);
        dp = new long[n.length()][2][2][3][3];
        for (int i = 1; i <= n.length(); i++) {
            for (long[][][][] a : dp) {
                for (long[][][] b : a) {
                    for (long[][] c : b) {
                        for (long[] d : c) {
                            Arrays.fill(d, -1);
                        }
                    }
                }
            }
            //            print = i == 1;
            long 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 long 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];
        }
        long 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.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
import java.util.InputMismatchException;
public class solution{
	public static int numofdigits(int n)
	{
		int ans = 0;
		while(n!=0)
		{
			ans++;
			n/=10;
		}
		return ans;
	}
	public static boolean check(int n)
	{
		while(n!=0)
		{
			if(n%10!=9)
			{
				return false;
			}
			n = n/10;
		}
		return true;
	}
	public static int getMax(int n,boolean flag)
	{
		if(n/10==0)
		{
			if(flag)
			return n-1;
			else
			return n;
		}
		if(n%10!=9)
		{
			flag = true;
		}
		return getMax(n/10,flag)*10+9;
	}
	public static void main(String args[]) throws Exception
		{
			InputReader sc = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			int n = sc.nextInt();
			int max = 2*n-1;
			long ans = 0;
			if(max<9)
			{
				ans = (n*(n-1))/2;
			}
			else if(check(max))
			{
				int min = max-n;
				if(min==0)
					ans = (n-1)/2;
				else
					ans = (n-min+1)/2;
			}
			else
			{
				int num = getMax(max,false);
				if(check(num))
				{
					int min = num-n;
					if(min==0)
					{
						ans = (n-1)/2;
					}
					else
					{
						ans = (n-min+1)/2;
					}
				}
				else
				{
					int digits = numofdigits(num);
					int diff = (int)Math.pow(10,digits-1);
					while(numofdigits(num)!=digits-1)
					{
						if(num>=n)
						{
							int min = num-n;
							if(min==0)
								ans+=(n-1)/2;
							else
								ans+=(n-min+1)/2;
						}
						else
						{
							ans+=(num-1)/2;
						}
						num-=diff;
					}
					if(num>=n)
					{
						int min = num-n;
						if(min==0)
							ans+=(n-1)/2;
						else
							ans+=(n-min+1)/2;
					}
					else
					{
						ans+=(num-1)/2;
					}
				}
			}
			out.println(ans);
			out.close();
		}
	static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int[] readCharCount() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int[] map = new int[256];
            do {
                int val = c ;
                map[val]++;
                c = snext();
            } while (!isSpaceChar(c));
            return map;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main {

    public void solve() throws IOException {
        long n = nextInt();
        if (n < 5) {
            out.print((n * (n - 1) / 2));
        } else {
            int r = 0;
            long b = 0;
            while (10 * b + 9 <= 2 * n - 1) {
                b = 10 * b + 9;
                r++;
            }
            int s = 0;
            for (long d = 0; d < 9; d++) {
                long r1 = 0;
                long a = d;
                while (10 * a + 9 <= 2 * n - 1) {
                    a = 10 * a + 9;
                    r1++;
                }
                if (r == r1) {
                    if (a - 1 <= n) {
                        s += (a - 1) / 2;
                    } else {
                        s += (n + n - a + 1) / 2;
                    }
                }
            }
            out.print(s);
        }

    }

    StringTokenizer sc;
    BufferedReader br;
    PrintWriter out;

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    public static void main(String[] args) throws IOException {
        try {
            Locale.setDefault(Locale.US);
            new Main().run();
        } catch (Exception e) {

        }
    }

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

    public void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}

//>>>BaZ<<<//
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Student
{
    static int dx[] = {-1,1,0,0};
    static int dy[] = {0,0,1,-1};
    static long MOD = 1000000007;
    static int INF = Integer.MAX_VALUE/10;
    static PrintWriter pw;
    static Reader scan;
    //static MyFileReader scan;
    //static MyFileReader1 ss;
    static int ni() throws IOException{return scan.nextInt();}
    static long nl() throws IOException{return scan.nextLong();}
    static double nd() throws IOException{return scan.nextDouble();}
    static void pl() throws IOException{pw.println();}
    static void pl(Object o) throws IOException{pw.println(o);}
    static void p(Object o) throws IOException {pw.print(o+" ");}
    static void psb(StringBuilder sb) throws IOException {pw.print(sb);}
    static long largest,mul,n;
    public static void main(String[] args){
        new Thread(null,null,"BaZ",99999999)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static void solve() throws IOException
    {
        Calendar CAL1 = Calendar.getInstance();
        CAL1.setTime(new Date());
        scan = new Reader();
        //scan = new MyFileReader();
        //ss = new MyFileReader1();
        pw = new PrintWriter(System.out,true);
        //pw = new PrintWriter(new File("C://Users/Aman deep/Desktop/output.txt"));
        StringBuilder sb = new StringBuilder();
        n = ni();
        String s = "0";
        while(Long.parseLong(s+'9')<=2*n-1)
            s+='9';
        largest = (int)(Long.parseLong(s));
     //   pl("largest : "+largest);
        mul = largest+1;
        long ans = 0;
        for(int i=0;;++i)
        {
            long l = i*mul+largest-n;
            long r = i*mul+largest-1;
         //   pl("l : "+l+" r : "+r);
            if(l>n)
                break;
            if(l<1)
                l = 1;
            if(r>n)
                r = n;
            if(r<1)
                r = 1;
         //   pl("i : "+i+" l : "+l+" r : "+r);
            if(r>=l)
                ans+=(r-l+1);
        }
        if(n<5)
            ans = (n*(n-1));
        pl((ans>>1));
        Calendar CAL2 = Calendar.getInstance();
        CAL2.setTime(new Date());
        double Execution_Time = (double)(CAL2.getTimeInMillis()-CAL1.getTimeInMillis())/1000.000;
        //System.out.println("Execution time : "+Execution_Time+" seconds");
        pw.flush();
        pw.close();
    }
    static int f(long x)
    {
        int cnt = 0;
        for(int k=0;;++k)
        {
            long corr = k*mul+largest-x;
            if(corr>n)
                return cnt;
            if(corr>=1)
                ++cnt;
        }
    }
    static long gf(int req)
    {
        long low = 1;
        long high = n;
        long mid;
        while(low<high)
        {
            mid = (low+high)>>1;
            if(f(mid)>=req)
            {
                if(mid==1 || f(mid-1)<req)
                {
                    low = mid;
                    break;
                }
                else high = --mid;
            }
            else low = ++mid;
        }
        if(f(low)==req)
            return low;
        return -1;
    }
    static long gl(int req)
    {
        long low = 1;
        long high = n;
        long mid;
        while(low<high)
        {
            mid = (low+high)>>1;
            if(f(mid)<=req)
            {
                if(mid==n || f(mid+1)>req)
                {
                    low = mid;
                    break;
                }
                else low = ++mid;
            }
            else high = --mid;
        }
        if(f(low)==req)
            return low;
        return -1;
    }
    static class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
        byte[] buf = new byte[64];
        int cnt = 0, c;
        while ((c = read()) != -1) {
            if (c == '\n') break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public long nextLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public double nextDouble() throws IOException {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
        if (neg) return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) buffer[0] = -1;
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead) fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException {
        if (din == null) return;
        din.close();
    }
}
     static class MyFileReader                                          //File input template
    {
        StringTokenizer st;
        BufferedReader br;
        MyFileReader() throws IOException
        {
            br = new BufferedReader(new FileReader("C://Users/Aman deep/Desktop/input.txt"));
        }
        String nextLine() throws IOException
        {
            return br.readLine();
        }
        String next() throws IOException
        {
            if(st==null || !st.hasMoreTokens())
                st = new StringTokenizer(nextLine());
            return st.nextToken();
        }
        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
     static class MyFileReader1                                          //File input template
    {
        StringTokenizer st;
        BufferedReader br;
        MyFileReader1() throws IOException
        {
            br = new BufferedReader(new FileReader("C://Users/Aman deep/Desktop/output.txt"));
        }
        String nextLine() throws IOException
        {
            return br.readLine();
        }
        String next() throws IOException
        {
            if(st==null || !st.hasMoreTokens())
                st = new StringTokenizer(nextLine());
            return st.nextToken();
        }
        int nextInt() throws IOException
        {
            return Integer.parseInt(next());
        }
        long nextLong() throws IOException
        {
            return Long.parseLong(next());
        }
        double nextDouble() throws IOException
        {
            return Double.parseDouble(next());
        }
    }
}

//package com.company;
//
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner(System.in);
        int n = sc.nextInt();
        if (n < 5){
            System.out.println(n * (n - 1) / 2);
            return;
        }
        int ll = n + n - 1;
        int di = Integer.toString(ll + 1).length();
        boolean ref = false;
        if (Integer.toString(n).length() != Integer.toString(n + 1).length()){
            ref = true;
        }
        int tt = 1;
        for (int i = 0; i < di - 1; i++) {
            tt *= 10;
        }
        long cbt = tt - 1;
        int res = 0;
        if (cbt <= n){
            res += cbt / 2;
        } else {
            res += n - cbt / 2;
            System.out.println(res);
            return;
        }
        while (cbt + tt <= ll){
            cbt += tt;
            if (cbt <= n){
                res += cbt / 2;
            } else {
                res += n - cbt / 2;
            }
        }
        System.out.println(res);
    }

    static class MyScanner {
        StringTokenizer st;
        BufferedReader br;

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

        public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(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 { return Double.parseDouble(next()); }

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class codeforces {
	static int N;
	public static void main(String[] args) {
		FS scan = new FS(System.in);

		int N = scan.nextInt();
		if(N <= 4){
			System.out.println(N*(N-1)/2);
			return;
		}
		int cap = 0;
		long ten = 10;
		int max = 0;
		for(int i=1;i<=10;i++){
			if(ten-N-1<N)
				max++;
			else{
				ten/=10;
				break;
			}
			ten*=10;
		}

		long sol = 0;
		for(long i=0;i<10;i++){
			long val = ten*i + (ten-1);

			long lo = 1, hi = val/2, ans = 0;
			while(lo<=hi){
				long mid = lo+hi>>1;
				if(mid <= N && mid != val-mid && val-mid <= N){
					ans = mid;
					hi = mid-1;
				}else{
					lo = mid+1;
				}
			}

			if(ans>0)sol+=val/2 - ans + 1;
		}
		System.out.println(sol);
	}
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(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());}
	}

}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/*
 public class _899D {

 }

 */
public class _899D {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    int n = in.readInteger();

    if (n <= 4) {
      System.out.println(((n - 1) * n) / 2);
      return;
    }

    int max9 = 0;

    long num = 0;
    long maxnum = -1;;
    for (int i = 1;; i++) {
      num *= 10;
      num += 9;

      if (2 * n >= num) {
        max9 = i;
        maxnum = num;
      } else {
        break;
      }
    }

    List<Long> posssums = new ArrayList<Long>();

    long mul = 1;

    for (int i = 1; i <= max9; i++) {
      mul *= 10;
    }
    for (int i = 0; i < 9; i++) {
      if (i * mul + maxnum <= 2 * n && i * mul + maxnum >= 2) {
        posssums.add(i * mul + maxnum);
      }

    }

    long ans = 0;

    for (Long cnum : posssums) {

      if (cnum <= n) {
        long min = 1;
        long max = cnum;
        ans += (max - min + 1) / 2;
      } else {
        long min = cnum - n;
        long max = n;
        ans += (max - min + 1) / 2;
      }
    }

    System.out.println(ans);
    // end here
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new _899D()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}

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

import static java.lang.Math.*;

public class Main implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Main(),"Main",1<<26).start();
	}
    long findAns(int n) {
        long ans = 1;
        for(long i = 0; i < n; ++i)
            ans *= 10;
        return ans;
    }
    long findValue(int n) {
        long ans = 0;
        long val = 1;
        for(int i = 0; i < n; ++i) {
            ans += 9 * val;
            val *= 10;
        }
        return (ans - 1) / 2;
    }
	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

        int n = sc.nextInt();
        if(n <= 4) {
            int ans = n * (n - 1) / 2;
            w.print(ans);
            w.close();
            return;
        }
        long ans = 0;
        int temp = n;
        int digits = 0;
        while(temp != 0) {
            digits++;
            temp /= 10;
        }

        char s[] = Integer.toString(n).toCharArray();

        if(s[0] >= '5') {
            ans = (long)(s[0] - '5') * findAns(digits - 1);
            ans += (long)(n - ((s[0] - '0') * findAns(digits - 1)) + 1);
            int flag = 0;
            for(int i = 0; i < s.length; ++i) {
                if(s[i] != '9') {
                    flag = 1;
                    break;
                }
            }
            if(flag == 0)
                ans--;
        }
        else {
            long m = s[0] - '0';
            ans = m * (m - 1) / 2 * findAns(digits - 1);
            ans += findAns(digits - 1) / 2 * m;
            long left = (long)(n - ((s[0] - '0') * findAns(digits - 1)) + 1);
            ans += (left * m);
            ans += max(0, (left - (findValue(digits - 1) + 1)));
            ans -= m;
            int flag = 0;
            for(int i = 1; i < s.length; ++i) {
                if(s[i] != '9')
                    flag = 1;
            }
            if(flag == 0)
                ans--;
        }
        w.print(ans);
		w.close();
	}
}

import java.util.Scanner;

public class Shovel {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        sc.close();
        if (n < 5) {
            System.out.println(n * (n - 1) / 2);
            return;
        }
        long num = 1;
        long test = 5;
        while (test < n && test < Integer.MAX_VALUE / 10 + 1) {
            test *= 10;
            if (test <= n)
                num++;
        }
        long nines = 9;
        for (int i = 0; i < num - 1; ++i) {
            nines = nines * 10 + 9;
        }
        long tens = nines + 1;
        long amount = Math.min(n - nines / 2, nines - 1 - nines / 2);
        long current = nines + tens;
        while (n >= (current / 2 + 1) && current < nines * 10 + 9) {
            amount += Math.min(n - current / 2, current - 1 - current / 2);
            current += tens;
        }
        System.out.println(amount);
    }
}

//package round452;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		long t = 2*n;
		if(t < 9){
			out.println(n*(n-1)/2);
			return;
		}
		long d = 1;
		for(;t/d > 0;d*=10);
		// sum <= 8
		long ideal = t / (d/10) * (d/10) - 1;
		long ret = 0;
		while(ideal > 0){
			long inf = ideal / 2 + 1;
			long sup = Math.min(ideal-1, n);
			if(inf <= sup)ret += sup-inf+1;
			ideal -= d/10;
		}
		out.println(ret);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

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

public class D899 {
    private static long[][][][][][][] dp;

    private static char[] limit;
    private static int maxNum9;

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

        int num = Integer.parseInt(br.readLine());
        if (num <= 4) {
            System.out.println((num * (num - 1)) / 2);
            return;
        }

        String max9 = "" + (num + num - 1);
        maxNum9 = max9.length();
        boolean flag = true;
        for (char e : max9.toCharArray()) {
            if (e != '9') {
                flag = false;
                break;
            }
        }
        if (flag) {
            System.out.println(1);
            return;
        }

        maxNum9--;
        limit = ("" + (num + 1)).toCharArray();
        for (int i = 0, j = limit.length - 1; i < j; i++, j--) {
            char temp = limit[i];
            limit[i] = limit[j];
            limit[j] = temp;
        }
        dp = new long[limit.length + 1][maxNum9 + 1][2][2][2][2][2];
        for (int i = 0; i <= limit.length; i++) {
            for (int j = 0; j <= maxNum9; j++) {
                for (int k = 0; k < 2; k++) {
                    for (int l = 0; l < 2; l++) {
                        for (int m = 0; m < 2; m++) {
                            for (int o = 0; o < 2; o++) {
                                dp[i][j][k][l][m][o][0] = -1;
                                dp[i][j][k][l][m][o][1] = -1;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(count(0, 0, 1,
                0, 0, 1, 1) / 2);
    }

    private static long count(int index, int num9, int hasAll9,
                             int isASmaller, int isBSmaller,
                             int isAZero, int isBZero) {
        if (index == limit.length) {
            if (num9 != maxNum9 || isASmaller == 0 || isBSmaller == 0
                    || isAZero == 1 || isBZero == 1) {
                return 0;
            }
            return 1;
        }

        if (dp[index][num9][hasAll9][isASmaller][isBSmaller][isAZero][isBZero] > -1) {
            return dp[index][num9][hasAll9][isASmaller][isBSmaller][isAZero][isBZero];
        }

        long count = 0;
        boolean isAStillSmaller;
        boolean isBStillSmaller;
        int nextHasAll9;
        for (int i = 0; i < 10; i++) {
            if (i == limit[index] - '0') {
                isAStillSmaller = isASmaller == 1;
            } else {
                isAStillSmaller = i < (limit[index] - '0');
            }
            for (int j = 0; j < 10; j++) {
                if (j == limit[index] - '0') {
                    isBStillSmaller = isBSmaller == 1;
                } else {
                    isBStillSmaller = j < (limit[index] - '0');
                }
                int k = i + j;
                int nextNum9 = num9;
                if (k == 9 && hasAll9 == 1) {
                    nextNum9++;
                    nextHasAll9 = 1;
                } else {
                    nextHasAll9 = 0;
                }
                count += count(index + 1, nextNum9, nextHasAll9,
                        isAStillSmaller ? 1 : 0, isBStillSmaller ? 1 : 0,
                        isAZero == 0 ? isAZero : (i > 0 ? 0 : 1),
                        isBZero == 0 ? isBZero : (j > 0 ? 0 : 1)
                );
            }
        }
        dp[index][num9][hasAll9][isASmaller][isBSmaller][isAZero][isBZero] = count;
        return count;
    }
}

/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         if(N <= 4)
         {
            System.out.println(N*(N-1)/2);
            return;
         }
         String lol = "9";
         while(true)
         {
            long val = Long.parseLong(lol);
            if(2*N-1 < val)
               break;
            lol += 9;
         }
         lol = lol.substring(1);
         long res = 0L;
         long check = Long.parseLong(lol);
         while(2*N-1 >= check)
         {
            long min = Math.max(1, check-N);
   			long max = check/2;
   			res += max-min+1;
   			check += Long.parseLong(lol)+1;
         }
         System.out.println(res);
      }
   }

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(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, ScanReader in, PrintWriter out) {
            long n = in.scanLong();
            long Max = n + (n - 1);
            if (Max < 9) {
                out.println((n * (n - 1)) / 2);
                return;
            }
            if (allNine(Max)) {
                out.println(1);
                return;
            }
            long ans = 0;
            long num = (long) Math.floor(Math.log10(Max));
            long adder = (long) Math.pow(10, num);
            num = adder - 1;
            while (num <= Max) {
                if (num <= n) ans += (num / 2);
                else ans += (n - num / 2);
                num += adder;
            }
            out.println(ans);

        }

        private boolean allNine(long n) {
            while (n > 0) {
                if ((n % 10) != 9) return false;
                n /= 10;
            }
            return true;
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public long scanLong() {
            long integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

    }
}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class D {

	public static long naive(long n){
		long cnt = 0;

		int max_tail = 0;
		for(int fst = 1; fst <= n; fst++){
			for(int snd = fst + 1; snd <= n; snd++){
				int tail = 0;
				int sum = fst + snd;

				//System.out.println(n + " : " + sum);
				while(sum > 0){
					if(sum % 10 != 9){ break; }

					tail++;
					sum /= 10;
				}

				if(max_tail < tail){ max_tail = tail; cnt = 1; }
				else if(max_tail == tail){ cnt += 1; }
			}
		}

		return max_tail == 0 ? n * (n - 1) / 2 : cnt;
	}

	public static long smart(long n){
		int tail = 0;
		for(long val = 5; val <= n; val *= 10){ tail++; }

		if(tail == 0){ return n * (n - 1) / 2; }

		long base = 1;
		for(int i = 0; i < tail; i++){ base *= 10; }

		long answer = 0;
		for(long sum = base - 1; sum < 10 * base; sum += base){
			final long pair_low  = sum / 2;
			final long pair_high = pair_low + 1;

			final long can_use = Math.max(0, Math.min(sum - 1, n) - pair_low);

			//System.out.println(sum + " " + can_use);
			answer += Math.max(0, can_use);
		}

		return answer;

	}

	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			final long n = sc.nextLong();

			/*
			for(int i = 1; i <= n; i++){
				if(naive(i) != smart(i)){
					System.out.println(i + " : " + naive(i));
					System.out.println(i + " : " + smart(i));
				}
			}
			//*/
			//System.out.println(smart(n) + " " + naive(n));
			System.out.println(smart(n));
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

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

		private void getLine() {
			try {
				while (!hasNext()) {
					tok = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) { /* ignore */
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() {
			getLine();
			return tok.nextToken();
		}

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

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

		public void close() {
			try {
				br.close();
			} catch (IOException e) { /* ignore */
			}
		}
	}
}

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

public class Solution{

    public static void main(String[] args) {

    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);

    	int tt = 1;
    	while(tt-->0) {

    		int n = fs.nextInt();

    		if(n<5) {
    			out.println(n*(n-1)/2);
    			out.flush();
    			return;
    		}

    		int t = n;
    		long num = 1;
    		while(t>0) {
    			num *= 10;
    			t /= 10;
    		}

    		if(n>=(num/2)) {
    			num /= 2;
    			out.println(num - 1 - max(2*num - 1 - n, 1) + 1);
    		}
    		else {
    			long ans = 0;
    			for(int i=0;i<9;i++) {
    				long x = num/10*i + (num/10)-1;
    				long s = max(1, x - n);
    				if(s<=n) ans += (x-2*s+1)/2;
    			}
    			out.println(ans);
    		}

    	}

    	out.close();

    }

    static long min(long a, long b) {
    	if(a<b) return a;
    	return b;
    }

    static long max(long a, long b) {
    	if(a>b) return a;
    	return b;
    }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");

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

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

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

    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}

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

    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }

}

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

public class Main{
	public static void main(String[] args) throws Exception{
		PrintWriter pw=new PrintWriter(System.out);
		MScanner sc = new MScanner(System.in);
		int n=sc.nextInt();
		if(n<=4) {
			pw.println(n*(n-1)/2);
			pw.flush();
			return;
		}
		int maxNumber=n+n-1;
		int firstDigit=maxNumber;
		int digits=0;
		boolean allNines=true;
		while(firstDigit>=10) {
			int last=firstDigit%10;
			if(last!=9) {
				allNines=false;
			}
			firstDigit/=10;
			digits++;
		}
		if(firstDigit!=9) {
			allNines=false;
		}
		if(allNines) {
			pw.println(1);
			pw.flush();
			return;
		}
		int ans=0;
		while(firstDigit>=0) {
			int val=firstDigit;
			for(int i=0;i<digits;i++) {
				val*=10;
				val+=9;
			}
			firstDigit--;
			if(val>maxNumber)continue;
			int upper=((val+1)/2)-1;
			int lower=1;
			int remove=Math.max(0, val-1-n);

			ans+=(upper-lower+1-remove);
		}
		pw.println(ans);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx = i + (int)(Math.random() * (in.length - i));
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx = i + (int)(Math.random() * (in.length - i));
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static String arrToString(int[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(long[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(Integer[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(Long[]x) {
		return Arrays.toString(x);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        int countSuffix(String s) {
            int len = s.length();
            int ct = 0;
            for (int i = len - 1; i >= 0; i--) {
                if (s.charAt(i) == '9')
                    ct++;
            }
            return ct;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();

            if (n <= 4) {
                out.println((n * (n - 1)) / 2);
                return;
            }

            long sum = (n - 1 + n);
            String max = sum + "";
            int len = max.length();

            long lo, hi, diff;
            if (countSuffix(max) == len) {
                lo = hi = Long.parseLong(max);
                diff = 1L;
            } else {
                StringBuilder nine = new StringBuilder();
                StringBuilder zero = new StringBuilder();
                for (int i = 1; i < len; i++) {
                    nine.append('9');
                    zero.append('0');
                }

                diff = Long.parseLong(1 + zero.toString());
                lo = Long.parseLong(nine.toString());
                hi = Long.parseLong(9 + nine.toString());
            }

            long ct = 0;
            for (long i = hi; i >= lo; i -= diff) {
                if (i > sum) {
                    continue;
                }
                ct += (i / 2);
                ct -= Math.max(0, i - n - 1);
            }
            out.println(ct);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.InputMismatchException;

public class CFD {
    private static final long MOD = 1_000_000_007L;
    private static final long LIMIT = 1L << 60; //10^18

    static FastScanner sc;
//    static int[] as;

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

        int n = sc.nextInt();
//        as = readIntArray(n);
//        Map<Integer, Integer> map = Arrays.stream(as).boxed().collect(Collectors.toMap(i -> i, i -> 1, (a, b) -> a + 1));

        int sum = 0;
        if (n < 5) { //0
            if (n == 2) System.out.println(1);
            if (n == 3) System.out.println(3);
            if (n == 4) System.out.println(6);
        } else {
            long lim = 5;
            long mul = 1;
            while (n >= lim * mul) mul *= 10;
            // n < lim * mul
            for (long i = mul-1; i <= mul*9-1; i += mul) { //mul=10 for(9, 89, +10)
                if (n*2 > i) {
                    if (n < i) {
                        sum += n - i/2;
                    } else {
                        sum += i/2;
                    }
                }
            }
            System.out.println(sum);
        }
    }

    //********************************************************************************************
    //********************************************************************************************
    //********************************************************************************************

    private static int ceil(double d) {
        int ret = (int) d;
        return ret == d ? ret : ret + 1;
    }

    private static int round(double d) {
        return (int) (d + 0.5);
    }

    @SuppressWarnings("SameParameterValue")
    private static <T> T elvis(T obj, T defValue) {
        return obj == null ? defValue : obj;
    }

    private static int gcd(int a, int b) {
        BigInteger b1 = BigInteger.valueOf(a);
        BigInteger b2 = BigInteger.valueOf(b);
        BigInteger gcd = b1.gcd(b2);
        return gcd.intValue();
    }

    private static int[] readIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextInt();
        }
        return res;
    }

    private static long[] readLongArray(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = sc.nextLong();
        }
        return res;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

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

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

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class CFD {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] dx = {0, -1, 0, 1};
    int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        long n = nextLong();
        long max = n + n - 1;
        long nine = 9;
        while (nine <= max) {
            nine = 10 * nine + 9;
        }

        nine = nine / 10;
        int cnt = Long.toString(nine).toCharArray().length;
        char[] arr = Long.toString(n).toCharArray();
        long res = 0;

        if (nine == 0) {
            long ret = 1L * n * (n - 1) / 2;
            out(ret);
            return;
        }

        if (arr.length == cnt) {
            if (nine <= n) {
                out(nine / 2);
            }
            else if (nine < 2 * n) {
                out((2 * n - nine + 1) / 2);
            }
            else {
                out(0);
            }
            return;
        }

        long base = 1;
        for (int i = 0; i < cnt; i++) {
            base = 10 * base;
        }

        for (int i = 0; i <= 2 * (arr[0] - '0'); i++) {
            long sum = i * base + nine;

            if (sum <= n) {
                res += sum / 2;
            }
            else if (sum < 2 * n) {
                res += (2 * n - sum + 1) / 2;
            }
        }

        out(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFD() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFD();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

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

public class Main {

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

        // Code goes here
        int n = sc.nextInt();
        int swap = n;
        int firstDigit = 0;
        int numDigits = 0;
        while (swap > 0) {
            if (swap < 10)
                firstDigit = swap;
            swap /= 10;
            numDigits++;
        }
        ArrayList<Integer> targets = new ArrayList<>();
        if (firstDigit < 5) {
            targets.add((int) Math.pow(10, numDigits - 1) - 1);
            for (int i = 1; i <= firstDigit * 2; i++) {
                int k = (int) Math.pow(10, numDigits - 1) - 1 + i * (int) Math.pow(10, numDigits - 1);
                if (k <= 2 * n + 1 && k > 0)
                    targets.add(k);
            }
        } else {
            targets.add((int) Math.pow(10, numDigits) - 1);
        }
        int res = 0;
        for (int t: targets) {
            if (t <= n)
                res += (t - 1) / 2;
            else {
                int diff = (t - 1) / 2 - (t - n) + 1;
                if (diff < 0) diff = 0;
                res += diff;
            }
        }
        out.println(res);
        out.close();
    }

    static Random rand = new Random();
    static void sort(int[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            int tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static void sort(long[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            long tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static void sort(double[] a) {
        int n = a.length;
        for (int i = a.length - 1; i > 0; i--) {
            int j = rand.nextInt(i + 1);
            double tmp = a[i];
            a[i] = a[j];
            a[j] = tmp;
        }
        Arrays.sort(a);
    }
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    static long[] eEuclid(long a, long b) {
        if (b == 0) return new long[] { a, 1, 0 };
        long[] ans = eEuclid(b, a % b);
        long temp = ans[1] - ans[2] * (a / b);
        ans[1] = ans[2];  ans[2] = temp;
        return ans;
    }
    static long modInverse(long a, long m) {
        return ((eEuclid(a, m)[1] % m) + m) % m;
    }
    static class IntList {
        static int[] EMPTY = {};
        int[] a = EMPTY;
        int n = 0;
        void add(int v) {
            if (n >= a.length)
                a = Arrays.copyOf(a, (n << 2) + 8);
            a[n++] = v;
        }
        int get(int idx) {
            return a[idx];
        }
        int size() {
            return n;
        }
    }
    static class DisjointSet {
        int[] s, r;
        public DisjointSet(int n) {
            s = new int[n]; r = new int[n];
            for (int i = 0; i < n; i++) s[i] = i;
        }
        public int find(int i) { return s[i] == i ? i : (s[i] = find(s[i])); }
        public void union(int a, int b) {
            if(r[a = find(a)] == r[b = find(b)]) r[a]++;
            if(r[a] >= r[b]) s[b] = a; else s[a] = b;
        }
    }
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream i) {
            br = new BufferedReader(new InputStreamReader(i));
            st = new StringTokenizer("");
        }
        public String next() throws IOException {
            if(st.hasMoreTokens())
                return st.nextToken();
            else
                st = new StringTokenizer(br.readLine());
            return next();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
        public int[] nextOffsetIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt() - 1;
            return arr;
        }
        public int[] nextIntArray(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextInt();
            return arr;
        }
        public int[][] nextIntArray(int n, int m) throws IOException {
            int[][] arr = new int[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextInt();
            return arr;
        }
        public long[] nextLongArray(int n) throws IOException {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextLong();
            return arr;
        }
        public long[][] nextLongArray(int n, int m) throws IOException {
            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextLong();
            return arr;
        }
        public double[] nextDoubleArray(int n) throws IOException {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++)
                arr[i] = nextDouble();
            return arr;
        }
        public double[][] nextDoubleArray(int n, int m) throws IOException {
            double[][] arr = new double[n][m];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < m; j++)
                    arr[i][j] = nextDouble();
            return arr;
        }
        public char[][] nextCharArray(int n, int m) throws IOException {
            char[][] arr = new char[n][];
            for (int i = 0; i < n; i++)
                arr[i] = next().toCharArray();
            return arr;
        }
    }
}

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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	void work() {
		long n=in.nextLong();
		if(n<=4) {
			out.println(n*(n-1)/2);
			return;
		}
		long num=0;
		while(num*10+9<=2*n-1) {
			num=num*10+9;
		}
		long ret=0;
		for(long i=num;i<=2*n-1;i+=num+1) {
			long v=(i+1)/2;
			ret+=Math.min(i-v,n-v+1);
		}
		out.println(ret);
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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

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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	void work() {
		long n=in.nextLong();
		if(n<=4) {
			out.println(n*(n-1)/2);
			return;
		}
		long sum=find(2*n);
		long ret=0;
		if((sum+"").charAt(0)!='9') {//2000  3999  2999 1999
			for(int i=0;i<=9;i++) {
				if(i>(sum+"").charAt(0)-'0')break;
				long num=Long.valueOf(i+""+(sum+"").substring(1));
				long v=(num+1)/2;
				if(num<=n)ret+=v-1;
				else {
					ret+=n-v+1;
				}
			}
		}else {
			long v=(sum+1)/2;//999
			ret=n-v+1;
			if(sum==n)ret--;
		}
		out.println(ret);
	}
	private long find(long n) {
		int len=(n+"").length()-1;
		int c=(n+"").charAt(0)-'1';
		StringBuilder sb=new StringBuilder();
		if(c!=0) {
			sb.append(c);
		}
		for(int i=0;i<len;i++) sb.append(9);
		return Long.valueOf(sb.toString());
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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

import java.util.Scanner;

public class CodeForces {
	public static void main(String args[]) throws Exception{
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		if(n < 5){
			System.out.println(n * (n-1) / 2);
		}else{
			int count = (n / 5 + "").length();
			int val = 0;
			for(int i = 0; i < count; i++){
				val += 9 * (int) Math.pow(10, i);
			}
			long step = (long) Math.pow(10, count);
			long ans = 0;
			for(int i = 0; i <= 9; i++){
				long look = step * i + val;
				if(n >= look){
					ans += look / 2;;
				}else if(n > look / 2){
					ans += n - look / 2;
				}else{
					break;
				}
			}
			System.out.println(ans);
		}
	}
}
/*

*/

import java.io.*;
	import java.math.BigInteger;
	import java.math.RoundingMode;
	import java.text.DecimalFormat;
	import java.util.*;

	public class Solution
	{

		static double eps=(double)1e-6;
		static long mod=(long)(1e9+9);
		//static int arr[] =new int[1000001];
		//private static DecimalFormat df2 = new DecimalFormat(".##");
		public static void main(String args[]){
			InputReader sc = new InputReader(System.in);
			//Scanner sc=new Scanner(System.in);
			OutputStream outputStream = System.out;
			PrintWriter out = new PrintWriter(outputStream);
			//----------my code----------
			int t1=1;
			while(t1-->0)
			{
				long n=sc.nextLong();
				if(n==2)
					out.println("1");
				if(n==3)
					out.println("3");
				if(n==4)
					out.println("6");
				else if(n>=5 && n<50)
				{
					long temp=n%10;
					long d=n/10;
					long ans=5*d*d;
					if(temp<5)
						ans+=temp*d;
					else if(temp<9)
						ans+=temp*d+(temp%5+1);
					else
						ans+=temp*d+4;
					out.println(ans);
				}
				else if(n>=50 && n<500)
				{
					long temp=n%100;
					long d=n/100;
					long ans=50*d*d;
					if(temp<50)
					{
						ans+=temp*d;
					}
					else if(temp<99)
					{
						ans+=temp*d+(temp%50+1);
					}
					else
						ans+=temp*d+49;
					out.println(ans);
				}
				else if(n>=500 && n<5000)
				{
					long temp=n%(long)(1e3);
					long d=n/(long)1e3;
					long ans=500*d*d;
					if(temp<500)
					{
						ans+=temp*d;
					}
					else if(temp<999)
					{
						ans+=temp*d+(temp%500+1);
					}
					else
						ans+=temp*d+499;
					out.println(ans);
				}
				else if(n>=(5*(long)1e3) && n<(5*(long)1e4))
				{
					long temp=n%(long)(1e4);
					long d=n/(long)1e4;
					long ans=(5*(long)1e3)*d*d;
					if(temp<(5*(long)1e3))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e4)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e3)+1);
					}
					else
						ans+=temp*d+(5*(long)1e3)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e4) && n<(5*(long)1e5))
				{
					long temp=n%(long)(1e5);
					long d=n/(long)1e5;
					long ans=(5*(long)1e4)*d*d;
					if(temp<(5*(long)1e4))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e5)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e4)+1);
					}
					else
						ans+=temp*d+(5*(long)1e4)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e5) && n<(5*(long)1e6))
				{
					long temp=n%(long)(1e6);
					long d=n/(long)1e6;
					long ans=(5*(long)1e5)*d*d;
					if(temp<(5*(long)1e5))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e6)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e5)+1);
					}
					else
						ans+=temp*d+(5*(long)1e5)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e6) && n<(5*(long)1e7))
				{
					long temp=n%(long)(1e7);
					long d=n/(long)1e7;
					long ans=(5*(long)1e6)*d*d;
					if(temp<(5*(long)1e6))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e7)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e6)+1);
					}
					else
						ans+=temp*d+(5*(long)1e6)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e7) && n<(5*(long)1e8))
				{
					long temp=n%(long)(1e8);
					long d=n/(long)1e8;
					long ans=(5*(long)1e7)*d*d;
					if(temp<(5*(long)1e7))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e8)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e7)+1);
					}
					else
						ans+=temp*d+(5*(long)1e7)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e8) && n<=((long)1e9))
				{
					long temp=n%(long)(1e9);
					long d=n/(long)1e9;
					long ans=(5*(long)1e8)*d*d;
					if(temp<(5*(long)1e8))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e9)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e8)+1);
					}
					else
						ans+=temp*d+(5*(long)1e8)-1;
					out.println(ans);
				}
			}
			//---------------------------------
			out.close();
		}

		static long modInverse(long A,long M)
		{
		    return modularExpon(A,M-2,M);
		}

		static long comb(int n,int r,long [][] c)
		{
			if(n<r)
				return 0;
			if(n-r < r)
			{
				c[n][r]=comb(n,n-r,c);
				return c[n][r];
			}
		    if(r == 0)
		    {
		    	c[n][r]=1;
		    	return 1;
		   	}
		    if(c[n][r]!=0)
		    	return c[n][r];
		    else
		    {
		    	c[n][r]=(n*comb(n-1, r-1,c))/r;
		    	return c[n][r];
		    }
		}

		static long modularExpon(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result%M;
		}

		static int IsPandigital(int n)
	    {
	        int digits = 0,temp=n; int count = 0; int tmp = 0;
	        int fr[]=new int[10];
	        for(int i=0;i<10;i++)
	        	fr[i]=0;
	        while(temp>0)
	        {
	        	int a=temp/10;
	        	//System.out.println(temp-a*10);
	        	fr[temp-a*10]++;
	        	temp=temp/10;
	        	digits++;
	        }
	        for(int i=1;i<=digits;i++)
	        {
	        	if(fr[i]==1)
	        	{
	        		tmp=1;
	        	}
	        	else
	        	{
	        		tmp=0;
	        		break;
	        	}
	        }
	        return tmp;
	    }

		static int Divisors(int n)
		{
			int sum=0;
		    for (int i=2; i*i<=n; i++)
		    {
		        if (n%i==0)
		        {
		            if (n/i == i)
		                {sum+=i;//System.out.println(sum+" "+i);
		                }

		            else
		                {sum+=i+(n/i);//System.out.println(sum+" "+i+" "+(n/i));
		                }
		        }
		    }
		    return sum;
		}

		static int findmax(int arr[], int n)
	    {
	        int incl = arr[0];
	        int excl = 0;
	        int excl_new;
	        int i;

	        for (i = 1; i < n; i++)
	        {
	            excl_new = (incl > excl) ? incl : excl;
	            incl = excl + arr[i];
	            excl = excl_new;
	        }
	        return ((incl > excl) ? incl : excl);
	    }

		static long ce(long x)
		{
			if(x%2!=0)
				return x/2+1;
			return x/2;
		}
		static boolean isSubSequence(String str1, String str2, int m, int n)
		{
		   int j = 0;
		   for (int i=0; i<n&&j<m; i++)
		       if (str1.charAt(j) == str2.charAt(i))
		         j++;

		   return (j==m);
		}

		static long fibo(long l) {
	        if (l < 0) {
	            throw new IllegalArgumentException("The fibo value cannot be negative");
	        }

	        if (l <= 1) return l;

	        long[][] result = {{1, 0}, {0, 1}}; // identity matrix.
	        long[][] fiboM = {{1, 1}, {1, 0}};

	        while (l > 0) {
	            if (l%2 == 1) {
	                multMatrix(result, fiboM);
	            }
	            l = l / 2;
	            multMatrix(fiboM, fiboM);
	        }

	        return result[1][0];
	    }

	    private static void multMatrix(long[][] result, long[][] fiboM) {
	        long a = (result[0][0]%mod * fiboM[0][0]%mod)%mod +  (result[0][1]%mod * fiboM[1][0]%mod)%mod;
	        long b = (result[0][0]%mod * fiboM[0][1]%mod)%mod + ( result[0][1]%mod * fiboM[1][1]%mod)%mod;
	        long c = (result[1][0]%mod * fiboM[0][0]%mod)%mod + ( result[1][1]%mod * fiboM[0][1]%mod)%mod;
	        long d = (result[1][0]%mod * fiboM[0][1]%mod)%mod +  (result[1][1]%mod * fiboM[1][1]%mod)%mod;

	        result[0][0] = a;
	        result[0][1] = b;
	        result[1][0] = c;
	        result[1][1] = d;
	    }

	    static HashSet<Long> gr(int size)
	    {
	    	long range=mod;
	    	long m0=2017;
	    	long m1=2027;
	    	long ln=0;
	    	long sln=1;
	    	long mn=0;
	    	HashSet<Long> hs=new HashSet<Long>();
	    	for(int i=0;i<size;i++)
	    	{
	    		long nn=((((ln%mod)*m0)%mod+((sln%mod)*m1)%mod+mn)%mod)+1;
	    		sln=ln;
	    		ln=nn;
	    		mn=Math.max(mn, nn);
	    		hs.add(nn);
	    	}
	    	return hs;
	    }

		static int[] sieve(int n,int[] arr)
		{
			arr[0]=1;
			arr[1]=1;
			for(int i=2;i*i<=n;i++)
			{
				if(arr[i]==0)
				{
					for(int j=i*2;j<=n;j+=i)
						arr[j]=1;
				}
			}
			return arr;
		}

		static int[] spfsieve(int arr[])
		{
			int n=5000000;
			arr[0]=1;
			arr[1]=1;
			for(int i=2;i<=n;i++)
				arr[i]=i;
			for(int i=4;i<=n;i+=2)
				arr[i]=2;
			for(int i=3;i*i<=n;i++)
			{
				if(arr[i]==i)
				{
					for(int j=i*i;j<=n;j+=i)
						if (arr[j]==j)
		                    arr[j] = i;
				}
			}
			return arr;
		}

		static boolean isPal(String s)
		{
			for(int i=0, j=s.length()-1;i<=j;i++,j--)
			{
				if(s.charAt(i)!=s.charAt(j)) return false;
			}
			return true;
		}
		public static String rev(String s)
		{
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
		}

		static long lcm(long a, long b)
		{
			long temp1=a,temp2=b;
		    return ((a * b) / gcd(temp1, temp2));
		}

		static long gcd(long a, long b)
		{
		    if (b==0)
		        return a;
		    return gcd(b, a%b);
		}
		static long modulo(long a,long b,long c) {
			long x=1;
			long y=a;
			while(b > 0){
				if(b%2 == 1){
					x=(x*y)%c;
				}
				y = (y*y)%c; // squaring the base
				b /= 2;
			}
			return  x%c;
		}
		public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}

		static class SegmentTree
		{
		    long st[];
		    public SegmentTree(long arr[], int n)
		    {
		        int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));

		        int max_size = 2 * (int) Math.pow(2, x) - 1;

		        st = new long[max_size];

		        constructSTUtil(arr, 0, n - 1, 0);
		    }
		    int getMid(int s, int e) {
		        return s + (e - s) / 2;
		    }

		    long getSumUtil(int ss, int se, int qs, int qe, int si)
		    {
		        if (qs <= ss && qe >= se)
		            return st[si];
		        if (se < qs || ss > qe)
		            return 0;
		        int mid = getMid(ss, se);
		        return getSumUtil(ss, mid, qs, qe, 2 * si + 1) +
		                getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
		    }

		    void updateValueUtil(int ss, int se, int i, int diff, int si)
		    {
		        if (i < ss || i > se)
		            return;
		        st[si] = st[si] + diff;
		        if (se != ss) {
		            int mid = getMid(ss, se);
		            updateValueUtil(ss, mid, i, diff, 2 * si + 1);
		            updateValueUtil(mid + 1, se, i, diff, 2 * si + 2);
		        }
		    }

		    void updateValue(int arr[], int n, int i, int new_val)
		    {
		        if (i < 0 || i > n - 1) {
		            System.out.println("Invalid Input");
		            return;
		        }

		        // Get the difference between new value and old value
		        int diff = new_val - arr[i];

		        // Update the value in array
		        arr[i] = new_val;

		        // Update the values of nodes in segment tree
		        updateValueUtil(0, n - 1, i, diff, 0);
		    }
		    long getSum(int n, int qs, int qe)
		    {
		        if (qs < 0 || qe > n - 1 || qs > qe) {
		            System.out.println("Invalid Input");
		            return -1;
		        }
		        return getSumUtil(0, n - 1, qs, qe, 0);
		    }

		    long constructSTUtil(long arr[], int ss, int se, int si)
		    {
		        if (ss == se) {
		            st[si] = arr[ss];
		            return arr[ss];
		        }
		        int mid = getMid(ss, se);
		        st[si] = constructSTUtil(arr, ss, mid, si * 2 + 1) +
		                 constructSTUtil(arr, mid + 1, se, si * 2 + 2);
		        return st[si];
		    }
		}
		static class Pair {
			long x;
			long y;
			/*Pair(int xx,int yy,int zz){
				x=xx;
				y=yy;
				z=zz;
			}*/
			public long getx()
			{
				return x;
			}
			public long gety()
			{
				return y;
			}
			public void setx(long xx)
			{
				x=xx;
			}
			public void sety(long yy)
			{
				y=yy;
			}
		}

		public final static Comparator<Pair> ORIGINAL = new Comparator<Pair>()
	    {
		public int compare(Pair p1,Pair p2)
		{
			if(p1.getx()<p2.getx())
				return -1;
			else if(p1.getx()==p2.getx() && p1.gety()<p2.gety())
				return -1;
			else //if(p1.getx()>p2.getx() || p1.gety()>p2.gety() || p1.getz()>p2.getz())
				return 1;
			/*else
			{
				if(p1.gety()<p2.gety())
					return -1;
				else if(p1.gety()>p2.gety())
					return 1;
				else
				{
					if(p1.getz()<p2.getz())
						return -1;
					else if(p1.getz()>p2.getz())
						return 1;
				}
			}*/
			//return 0;
		}
	    };

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

			public InputReader(InputStream inputstream) {
				reader = new BufferedReader(new InputStreamReader(inputstream));
				tokenizer = null;
			}

			public String nextLine(){
				String fullLine=null;
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						fullLine=reader.readLine();
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
					return fullLine;
				}
				return fullLine;
			}
			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 long nextLong() {
				return Long.parseLong(next());
			}
			public int nextInt() {
				return Integer.parseInt(next());
			}
		}

	}
	class Graph
	{
		int vertices;
		LinkedList<Integer> l[];
		Graph(int vertices)
		{
			this.vertices=vertices;
			l=new LinkedList[vertices];
			for(int i=0;i<vertices;i++)
			{
				l[i]=new LinkedList<Integer>();
			}
		}
		void addEdge(int s,int v)
		{
			l[s].add(v);
		}

		void BFS(int s)
		{
			LinkedList<Integer> queue=new LinkedList<Integer>();
			boolean []visited=new boolean[vertices];
			visited[s]=true;
			queue.add(s);
			while(queue.size()>0)
			{
				int r=queue.poll();
				System.out.println(r+" ");
				for(int i=0;i<l[r].size();i++)
				{
					int temp=l[r].get(i);
					if(!visited[temp])
					{
						queue.add(temp);
						visited[temp]=true;
					}
				}
			}
		}

	}

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

/**
 * Created by Pranav ps on 16-12-2017.
 */

/**
 * This is the template for all coding problems
 */
public class D {
    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 {
        private static long MOD = (long)(1e9+7);
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
//            int max9 = 0;
//            long ten = 10;
//            while(ten <= 2*n){
//                max9++;
//                ten *= 10;
//            }
//            long mod = (long)(Math.pow(10,max9));
//            long x = n/mod;
//            long end = n%mod;
//            long num2x = Math.max(0,end - (mod/2-1));
//            if(end == mod-1)
//                num2x--;
//            long numx2 = mod/2;
//            long numx = (end == 0)?0:(mod-1-end-1);
//            if(end == mod-1)
//                numx++;
//            if(max9 == 0)
//                out.println(((n)*(n-1))/2);
//            else
//                out.println(numx2*(x*x) + numx*x + num2x*((long)2)*x + num2x);

            //After Editorial
            long sum = n + n - 1;
            if(sum < 9){
                out.println(n*(n-1)/2);
                return;
            }
            String num = Long.toString(sum);
            int numDigits = num.length();
            long tenPow = (long)(Math.pow(10,numDigits));
            if(sum == tenPow-1){
                out.println(1);
                return;
            }
            tenPow /= 10;
            long nines = tenPow-1;
            long ans = 0;
            for (int i = 0; i < 10; i++) {
                if(nines <= n+1)
                    ans += (nines/2);
                else if(nines > 2*n-1){

                }
                else{
                    ans += 1 + (2*n-1 - nines)/2;
                }
                nines += tenPow;
            }
            out.println(ans);
        }

    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

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

    }
}

import java.util.*;
import java.io.*;
import java.math.*;
public class A{

    void solve(){

    //    for(long n=1;n<=100;n++) {
            long n = nl();
            String s = "";
            long ans = 0;
            long ans2 = 0;
            long l2 = getL(2 * n);
            for (int i = 1; i < l2; i++) s += "9";
            int p = 0;
            while (p < 10) {
                long d = Long.parseLong(p + "" + s);

                if (d > 2 * n) break;
                // pw.println(d);
                ans += (d / 2 - Math.max(0, (d - n) - 1));
                //  pw.println(d/2-Math.max(0,(d-n)-1));
                p++;
//                for (int i = 1; i <= n; i++) {
//                    for (int j = i + 1; j <= n; j++) if (i + j == d) ans2++;
//                }
            }
            if(n==1) pw.println(0);
            else if(n==2) pw.println(1);
            else if(n==3) pw.println(3);
            else if(n==4) pw.println(6);
            else
            pw.println(ans);
       // }

    }
    int getL(long n){
        int l=0;
        while(n>0){
            l++;
            n/=10;

        }
        return l;
    }

    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new A().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}

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

public class Main_Round452Div2_D {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
//		int[] nine = {500_000_000, 50_000_000, 5_000_000, 500_000, 50_000, 5_000, 500, 50, 5};
		int[] nine = {1_000_000_000, 100_000_000, 10_000_000, 1_000_000, 100_000, 10_000, 1_000, 100, 10};

		int n = sc.nextInt();

		for (int nn : nine) {
			if (n < nn / 2) {
				continue;
			}

			int tmp = n / nn;
			if (n % nn < nn / 2) {
				long ans = tmp * tmp;
				ans += (tmp + 1) * tmp * (n % nn);
				ans += tmp * tmp * (nn / 2 - 1 - n % nn);
				pr.println(ans);
//				pr.println((tmp) * (nn / 2 - 1) + tmp);
			} else {
				long ans = tmp * tmp;
				if (n % nn == nn - 1) {
					ans = tmp * (tmp + 1);
				}
				ans += (tmp + 1) * (tmp + 1) * (Math.min(nn - 2, n % nn) - nn / 2 + 1);
				ans += (tmp + 1) * tmp * (nn - 2 - Math.min(nn - 2, n % nn));
				pr.println(ans);
//				pr.println((n % nn - nn / 2 + 1) * (tmp + 1) + (nn - 1 - n % nn) * (tmp) + tmp);
			}
			return;
		}

		if (n == 2) {
			pr.println(1);
		} else if (n == 3) {
			pr.println(3);
		} else if (n == 4) {
			pr.println(6);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;

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

		private boolean isPrintable(int ch) {
			return ch >= '!' && ch <= '~';
		}

		private boolean isCRLF(int ch) {
			return ch == '\n' || ch == '\r' || ch == -1;
		}

		private int nextPrintable() {
			try {
				int ch;
				while (!isPrintable(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}

				return ch;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		String next() {
			try {
				int ch = nextPrintable();
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (isPrintable(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		int nextInt() {
			try {
				// parseInt from Integer.parseInt()
				boolean negative = false;
				int res = 0;
				int limit = -Integer.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Integer.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				int multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		long nextLong() {
			try {
				// parseLong from Long.parseLong()
				boolean negative = false;
				long res = 0;
				long limit = -Long.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Long.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				long multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

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

		String nextLine() {
			try {
				int ch;
				while (isCRLF(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (!isCRLF(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new NoSuchElementException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n=ir.nextInt();
		int t=Integer.toString(2*n).length()-1;
		if(t==0){
			out.println(n*(n-1)/2);
		}
		else{
			int x=(int)Math.pow(10,t);
			int p=n/x;
			int q=n%x;
			int ans=-1;
			int r=x/2-1-q;
			if(q==0){
				ans=(x/2-1)*p*p+p*p;
			}
			else if(q<=x/2-1){
					ans=q*(p+1)*p+r*p*p+p*p;
			}
			else if(q==x-1){
					ans=(x/2-1)*(p+1)*(p+1)+(p+1)*p;
			}
			else{
				r*=-1;
				ans=r*(p+1)*(p+1)+(x/2-1-r)*p*(p+1)+p*p;
			}
			out.println(ans);
		}
	}

	static ArrayList<Integer> f(int l,int r){
		ArrayList<Integer> ret=new ArrayList<>();
		int a=((r-l)+1)/2;
		for(int i=l;i<l+a;i+=2){
			ret.add(i);
			ret.add(l+r-i);
		}
		return ret;
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

import java.util.Scanner;

public class d {
	public static void main(String[] Args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		System.out.println(get(n));
		// for (int i = 1; i < 20; i++) {
		// System.out.print(" " + get(i));
		// }
		// System.out.println(ans);
	}

	public static long get(long n) {
		if (n <= 4) {
			return (n * (n - 1)) / 2;
		}
		long max = 5;
		while (max * 10 <= n)
			max *= 10;
		long rate = max * 2;
		long c = 1;
		long ans = 0;
		while (max + rate <= n) {
			ans += rate * c;
			ans--;
			c++;
			max += rate;
		}
		ans += (n - max + 1) * c;
		if ((n + 1) % rate <= rate / 2)
			ans--;
		return ans;
	}
}

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.concurrent.ThreadLocalRandom;

import static java.lang.Math.*;

public class Sol implements Runnable {

    static long mod = 1000000007;

    void solve(int total_test_cases, InputReader in, PrintWriter w) {
        for (int test_case = 1; test_case <= total_test_cases; test_case++) {
            long n = in.nextLong();
            long a[] = new long[15];
            a[1] = 5L;
            for(int i=2;i<15;i++) a[i] = a[i - 1] * 10L;

            int ind = 0;
            while(ind < 14) {
                if(a[ind + 1] > n) break;
                ind++;
            }

            if(ind == 0) w.println(n * (n - 1) / 2);
            else {
                long till = n + n - 1;

                long N = 9;
                for(int i=2;i<=ind;i++) N = N * 10 + 9L;
                long NN = N;
                long itr = 0;

                long ans = 0;

                while(true) {
                    N = itr * (long)pow(10, ind) + NN;
                    itr++;

                    if(N > till) break;

                    if(N > n) {
                        long initial = N - n;
                        long count = (n - initial + 1) / 2L;
                        ans += count;
                    }
                    else {
                        long count = N / 2L;
                        ans += count;
                    }

                    //w.println(ans+" "+N);
                }

                w.println(ans);
            }
        }
    }

    // ************* Code ends here ***************

    void init() throws Exception {
        //Scanner in;
        InputReader in;
        PrintWriter w;
        boolean online = false;

        String common_in_fileName = "\\in";
        String common_out_fileName = "\\out";
        int test_files = 0;

        for(int file_no = 0; file_no <= test_files; file_no++) {

            String x = "" + file_no;
            if (x.length() == 1) x = "0" + x;

            String in_fileName = common_in_fileName + "" + x;
            String out_fileName = common_out_fileName + "" + x;

            if (online) {
                //in = new Scanner(new File(in_fileName + ".txt"));
                in = new InputReader(new FileInputStream(new File(in_fileName + ".txt")));
                w = new PrintWriter(new FileWriter(out_fileName + ".txt"));
            } else {
                //in = new Scanner(System.in);
                in = new InputReader(System.in);
                w = new PrintWriter(System.out);
            }

            solve(1, in, w);
            w.close();
        }
    }

    public void run() {
        try {
            init();
        }
        catch(Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }

    public static void main(String args[]) throws Exception {
        new Thread(null, new Sol(),"Sol",1<<28).start();
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c)) {
                c = read();
            }

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D899{

	void solve()
	{
		int n = ni();
		if(n < 5)
		{
			out.println(n * (n - 1) / 2);
			return;
		}
		int max = 2 * n - 1;
		int k = nine(max);
		if(k == -1)
			out.println(1);
		else
		{
			long ans = 0;
			int d=1;
			for(int i=1;i<=k;d*=10,i++);
			for(long s=d-1;s<=max;s+=d)
			{
				if(s <= n)
					ans += (s - 1) / 2;
				else
					ans += (2 * n - s + 1) / 2;
			}
			out.println(ans);
		}
	}

	int nine(int k)
	{
		boolean nz = true;
		int cn = 0;
		while(k != 0)
		{
			nz &= (k % 10 == 9);
			k /= 10;
			cn++;
		}
		return nz ? -1 : cn - 1;
	}

	public static void main(String[] args){new D899().run();}

	private byte[] bufferArray = new byte[1024];
	private int bufLength = 0;
	private int bufCurrent = 0;
	InputStream inputStream;
	PrintWriter out;

	public void run()
	{
		inputStream = System.in;
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	int nextByte()
	{
		if(bufLength == -1)
			throw new InputMismatchException();
		if(bufCurrent >= bufLength)
		{
			bufCurrent = 0;
			try
			{bufLength = inputStream.read(bufferArray);}
			catch(IOException e)
			{ throw new InputMismatchException();}
			if(bufLength <= 0)
				return -1;
		}
		return bufferArray[bufCurrent++];
	}

	boolean isSpaceChar(int x)	{return (x < 33 || x > 126);}

	boolean isDigit(int x)	{return (x >= '0' && x <= '9');}

	int nextNonSpace()
	{
		int x;
		while((x=nextByte()) != -1 && isSpaceChar(x));
		return x;
	}

	int ni()
	{
		long ans = nl();
		if (ans >= Integer.MIN_VALUE && ans <= Integer.MAX_VALUE)
			return (int)ans;
		throw new InputMismatchException();
	}

	long nl()
	{
		long ans = 0;
		boolean neg = false;
		int x = nextNonSpace();
		if(x == '-')
		{
			neg = true;
			x = nextByte();
		}
		while(!isSpaceChar(x))
		{
			if(isDigit(x))
			{
				ans = ans * 10 + x -'0';
				x = nextByte();
			}
			else
				throw new InputMismatchException();
		}
		return neg ? -ans : ans;
	}

	String ns()
	{
		StringBuilder sb = new StringBuilder();
		int x = nextNonSpace();
		while(!isSpaceChar(x))
		{
			sb.append((char)x);
			x = nextByte();
		}
		return sb.toString();
	}

	char nc()	{ return (char)nextNonSpace();}

	double nd()	{ return (double)Double.parseDouble(ns()); }

	char[] ca()	{ return ns().toCharArray();}

	char[][] ca(int n)
	{
		char[][] ans = new char[n][];
		for(int i=0;i<n;i++)
			ans[i] = ca();
		return ans;
	}

	int[] ia(int n)
	{
		int[] ans = new int[n];
		for(int i=0;i<n;i++)
			ans[i] = ni();
		return ans;
	}

	void db(Object... o) {System.out.println(Arrays.deepToString(o));}

}

import java.io.PrintWriter;
import java.util.Scanner;

public class D {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mx = n + n - 1;
        PrintWriter out = new PrintWriter(System.out);
        if (mx < 9) {
            out.println((n * (n - 1)) / 2);
        } else {
            long res = 0;
            long nn = 0;
            long des = 1;
            while (mx >= nn) {
                nn = 10 * nn + 9;
                des *= 10;
            }
            des /= 10;
            nn /= 10;
            for (int i = 0; i <9; i++) {
                if (des * i + nn <= mx) {
                    long c = (des * i + nn) / 2;
                    res += Math.min(c, n - c);
                }
            }
            out.print(res);
        }
        out.close();
    }

    private static boolean subst(int[] a, int[] b) {
        for (int i = 0; i < b.length - a.length + 1; i++) {
            int j = 0;
            while (j < a.length && a[j] == b[i + j]) {
                j++;
            }
            if (j == a.length) {
                return true;
            }
        }
        return false;
    }
}

//package practice.pset1;

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

public class R452D {

    static int mxx = 0;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int max = n+n-1;
        int tmp = max;
        int digits = 0;
        int nines = 0;
        while(tmp > 0){
            digits++;
            nines = nines + ((tmp%10)==9?1:0);
            tmp /= 10;
        }

        num = new int[10];
        tmp = n;
        int ii = 9;
        while(tmp > 0){
            int d = tmp%10;
            tmp /= 10;
            num[ii--] = d;
        }

        dp = new long[11][11][2][2][2][2][2];
        for (int i = 0; i < dp.length; i++)
            for (int j = 0; j < dp[i].length; j++)
                for (int k = 0; k < dp[i][j].length; k++)
                    for (int l = 0; l < dp[i][j][k].length; l++)
                        for (int m = 0; m < dp[i][j][k][l].length; m++)
                            for (int o = 0; o < dp[i][j][k][l][m].length; o++) {
                                Arrays.fill(dp[i][j][k][l][m][o], -1);
                            }

        if(nines == digits)
            digits++;
        {
            mxx = digits - 1;
            pw.println(solve(0,0,0, 0, 0, 0, 0)/2);
        }

        pw.flush();
        pw.close();
    }

    static int[] num;
    static long dp[][][][][][][];
    static long solve(int idx, int nines, int less1, int less2, int zero1, int zero2, int notEq){
        if(idx == 10)
            if(nines == mxx && zero1 > 0 && zero2 > 0 && notEq > 0) {
                return 1;
            }
            else
                return 0;

        if(dp[idx][nines][less1][less2][zero1][zero2][notEq] != -1)
            return dp[idx][nines][less1][less2][zero1][zero2][notEq];

        long ans = 0;
        for (int i = 0; i <= 9; i++)
            for (int j = 0; j <= 9; j++) {
                int newZero1 = zero1;
                int newZero2 = zero2;
                int newnotEq = notEq;
                if(i != j)
                    newnotEq = 1;
                if(i > 0)
                    newZero1 = 1;
                if(j > 0)
                    newZero2 = 1;

                if(nines > 0){
                    if(i + j == 9 && (less1>0 || i <= num[idx]) && (less2>0 || j <= num[idx])){
                        int newLess1 = less1;
                        if(i < num[idx])
                            newLess1 = 1;
                        int newLess2 = less2;
                        if(j < num[idx])
                            newLess2 = 1;

                        ans += solve(idx+1, nines+1, newLess1, newLess2, newZero1, newZero2, newnotEq);
                    }
                }else
                {
                    if((less1>0 || i <= num[idx]) && (less2>0 || j <= num[idx])){
                        int newLess1 = less1;
                        if(i < num[idx])
                            newLess1 = 1;
                        int newLess2 = less2;
                        if(j < num[idx])
                            newLess2 = 1;
                        int newNines = 0;
                        if(i+j == 9)
                            newNines += 1;
                        ans += solve(idx+1, newNines, newLess1, newLess2, newZero1, newZero2, newnotEq);
                    }
                }
            }

        return dp[idx][nines][less1][less2][zero1][zero2][notEq] = ans;
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(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 boolean ready() throws IOException {return br.ready();}
    }
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.valueOf(st.nextToken());
		int sum = n + n - 1;
		//System.out.println("sum==" + sum);
		if (checkAllNine(sum) || sum == 9) {
			System.out.println(1);
			return;
		}
		if (sum < 9) {
			System.out.println(n * (n - 1) / 2);
			return;
		}

		//

		long ans = 0;

		// len >= 2
		int len = cntLen(sum);
		int left = sum / (int) (Math.pow(10, len - 1));

		int firstNum = getFirst(sum, len, left);

		len = cntLen(firstNum);
		int loop = (int) (Math.pow(10, len - 1));
		left = firstNum / (int) (Math.pow(10, len - 1));
		if (firstNum < 10)
			left = 0;
		if (left == 9) {
			if (firstNum <= n)
				System.out.println(firstNum / 2);
			else {
				System.out.println(n - firstNum / 2);
			}
			return;
		}
		// System.out.println("left==" + left);
		while (left >= 0) {
			// System.out.println("firstNum==" + firstNum);
			if (firstNum > n) {
				int half = firstNum / 2 + 1;
				ans += (n - half + 1);
			}

			else
				ans += firstNum / 2;
			// System.out.println("ans==" + ans);
			firstNum -= loop;
			left--;
		}
		System.out.println(ans);
	}

	public static int getFirst(int sum, int len, int left) {
		int firstNum = -1;
		int rightSum = 0;

		for (int i = 0; i < len - 1; i++) {
			rightSum *= 10;
			rightSum += 9;
		}
		if (sum % (int) (Math.pow(10, len - 1)) != rightSum)
			left--;
		// System.out.println("rightSum==" + rightSum);
		firstNum = left * (int) (Math.pow(10, len - 1)) + rightSum;
		//System.out.println("firstNum==" + firstNum);
		// System.out.println();
		return firstNum;
	}

	public static int cntLen(int n) {
		int i = 0;
		while (n != 0) {
			i++;
			n /= 10;
		}
		return i;
	}

	public static boolean checkAllNine(int n) {
		while (n != 0) {
			if (n % 9 != 0)
				return false;
			n /= 10;
		}
		return true;
	}

	public static void printArray(int a[], int n) {
		for (int i = 0; i < n; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

}

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

public class CODEFORCES
{
	@SuppressWarnings("rawtypes")
	static InputReader in;
	static PrintWriter out;

	static int digit = 0, n = 0;
	static boolean u = true;
	static long ans = 0;

	static void check()
	{
		if (n < 5)
		{
			out.println((n * (n - 1)) >> 1);
			return;
		}
		int p = 2 * n - 1;
		while (p > 0)
		{
			if (p % 10 != 9)
				u = false;
			p /= 10;
			digit++;
		}
		if (!u)
			digit--;
		long t = 1;
		long make = 0;
		for (int i = 0; i < digit; i++)
		{
			make += t * 9;
			t *= 10;
		}
		while (make <= 2 * n - 1)
		{
			ans += (make - 1) >> 1;
			if (make > n)
				ans -= make - n - 1;
			make += t;
		}
		// ans += (make - 1) >> 1;
		// ans -= make - n - 1;
		out.println(ans);
	}

	static void solve()
	{
		n = in.ni();
		check();
	}

	@SuppressWarnings("rawtypes")
	static void soln()
	{
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args)
	{
		new Thread(null, new Runnable()
		{
			public void run()
			{
				try
				{
					soln();
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	// To Get Input
	// Some Buffer Methods
	static class InputReader<SpaceCharFilter>
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				} catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = ni();
			}
			return a;
		}

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

		public String readString()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}

	}
}

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

public class Main {

	static InputReader in = new InputReader(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	static int oo = (int)1e9;
//	static long oo = (long)1e15;
	static int mod = 1_000_000_007;

	static int[] dx = {1, 0, -1, 0};
	static int[] dy = {0, -1, 0, 1};

	static int M = 1000005;
	static double EPS = 1e-13;
	static int num = 1;

	public static void main(String[] args) throws IOException {

		long n = in.nextLong();
		long x = 0;
		while(true) {
			long nx = x * 10 + 9;
			if(nx > n + n-1)
				break;
			x = nx;
		}
		if(x == 0) {
			long ans = n * (n-1) / 2;
			System.out.println(ans);
		}
		else {
			long y = x + 1;
			long ans = 0;
			for(int i = 0; i < 9; ++i) {
				long z = i * y + x;
				if(z > n + n-1)
					break;
				long l = z / 2 + 1;
				long r = Math.min(n, z - 1);
				ans += r - l + 1;
			}
			System.out.println(ans);
		}

		out.close();
	}

	static int find(int[] g, int x) {
		return g[x] = g[x] == x ? x : find(g, g[x]);
	}

	static void union(int[] g, int[] size, int x, int y) {
		x = find(g, x); y = find(g, y);
		if(x == y)
			return;
		if(size[x] < size[y]) {
			g[x] = y;
			size[y] += size[x];
		}
		else {
			g[y] = x;
			size[x] += size[y];
		}
	}

	static class Segment {
		Segment left, right;
		int size, minIdx;
//		int time, lazy;

		public Segment(int[] a, int l, int r) {
			super();
			if(l == r) {
				this.minIdx = l;
				this.size = 1;
				return;
			}
			int mid = (l + r) / 2;
			left = new Segment(a, l, mid);
			right = new Segment(a, mid+1, r);
			if(a[left.minIdx] <= a[right.minIdx])
				this.minIdx = left.minIdx;
			else
				this.minIdx = right.minIdx;
			this.size = left.size + right.size;
		}

		boolean covered(int ll, int rr, int l, int r) {
			return ll <= l && rr >= r;
		}

		boolean noIntersection(int ll, int rr, int l, int r) {
			return ll > r || rr < l;
		}

//		void lazyPropagation() {
//			if(lazy != 0) {
//				if(left != null) {
//					left.setLazy(this.time, this.lazy);
//					right.setLazy(this.time, this.lazy);
//				}
//				else {
//					val = lazy;
//				}
//			}
//		}

//		void setLazy(int time, int lazy) {
//			if(this.time != 0 && this.time <= time)
//				return;
//			this.time = time;
//			this.lazy = lazy;
//		}

		int querySize(int ll, int rr, int l, int r) {
//			lazyPropagation();
			if(noIntersection(ll, rr, l, r))
				return 0;
			if(covered(ll, rr, l, r))
				return size;
			int mid = (l + r) / 2;
			int leftSize = left.querySize(ll, rr, l, mid);
			int rightSize = right.querySize(ll, rr, mid+1, r);
			return leftSize + rightSize;
		}

		int query(int k, int l, int r) {
			Segment trace = this;
			while(l < r) {
				int mid = (l + r) / 2;
				if(trace.left.size > k) {
					trace = trace.left;
					r = mid;
				}
				else {
					k -= trace.left.size;
					trace = trace.right;
					l = mid + 1;
				}
			}
			return l;
		}

		void update(int ll, int rr, int l, int r) {
//			lazyPropagation();
			if(noIntersection(ll, rr, l, r))
				return;
			if(covered(ll, rr, l, r)) {
//				setLazy(time, knight);
				this.minIdx = -1;
				this.size = 0;
				return;
			}
			int mid = (l + r) / 2;
			left.update(ll, rr, l, mid);
			right.update(ll, rr, mid+1, r);
			this.size = left.size + right.size;
		}
	}

	static long pow(long a, long n, long mod) {
		if(n == 0)
			return 1;
		if(n % 2 == 1)
			return a * pow(a, n-1, mod) % mod;
		long x = pow(a, n / 2, mod);
		return x * x % mod;
	}

	static int[] getPi(char[] a) {
		int m = a.length;
		int j = 0;
		int[] pi = new int[m];
		for(int i = 1; i < m; ++i) {
			while(j > 0 && a[i] != a[j])
				j = pi[j-1];
			if(a[i] == a[j]) {
				pi[i] = j + 1;
				j++;
			}
		}
		return pi;
	}

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

	static BigInteger lcm2(long a, long b) {
		long g = gcd(a, b);
		BigInteger gg = BigInteger.valueOf(g);
		BigInteger aa = BigInteger.valueOf(a);
		BigInteger bb = BigInteger.valueOf(b);
		return aa.multiply(bb).divide(gg);
	}

	static boolean nextPermutation(int[] a) {
		for(int i = a.length - 2; i >= 0; --i) {
			if(a[i] < a[i+1]) {
				for(int j = a.length - 1; ; --j) {
					if(a[i] < a[j]) {
						int t = a[i];
						a[i] = a[j];
						a[j] = t;
						for(i++, j = a.length - 1; i < j; ++i, --j) {
							t = a[i];
							a[i] = a[j];
							a[j] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}

	static void shuffle(Object[] a) {
		Random r = new Random();
		for(int i = a.length - 1; i > 0; --i) {
			int si = r.nextInt(i);
			Object t = a[si];
			a[si] = a[i];
			a[i] = t;
		}
	}

	static void shuffle(int[] a) {
		Random r = new Random();
		for(int i = a.length - 1; i > 0; --i) {
			int si = r.nextInt(i);
			int t = a[si];
			a[si] = a[i];
			a[i] = t;
		}
	}

	static void shuffle(long[] a) {
		Random r = new Random();
		for(int i = a.length - 1; i > 0; --i) {
			int si = r.nextInt(i);
			long t = a[si];
			a[si] = a[i];
			a[i] = t;
		}
	}

	static int lower_bound(int[] a, int n, int k) {
		int s = 0;
		int e = n;
		int m;
		while (e - s > 0) {
			m = (s + e) / 2;
			if (a[m] < k)
				s = m + 1;
			else
				e = m;
		}
		return e;
	}
	static int lower_bound(long[] a, int n, long k) {
		int s = 0;
		int e = n;
		int m;
		while (e - s > 0) {
			m = (s + e) / 2;
			if (a[m] < k)
				s = m + 1;
			else
				e = m;
		}
		return e;
	}

	static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}
	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
	static BigInteger gcd(BigInteger a, BigInteger b) {
		return b.compareTo(BigInteger.ZERO) == 0 ? a : gcd(b, a.mod(b));
	}

	static class Pair implements Comparable<Pair> {
		int first, second;

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

		@Override
		public int compareTo(Pair o) {
			return this.first != o.first ? this.first - o.first : this.second - o.second;
		}

//		@Override
//		public int compareTo(Pair o) {
//			return this.first != o.first ? o.first - this.first : o.second - this.second;
//		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + first;
			result = prime * result + second;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (first != other.first)
				return false;
			if (second != other.second)
				return false;
			return true;
		}
	}
}

class InputReader {

	private final InputStream stream;
	private final byte[] buf = new byte[8192];
	private int curChar, snumChars;

	public InputReader(InputStream st) {
		this.stream = st;
	}

	public int read() {
		if (snumChars == -1)
			throw new InputMismatchException();
		if (curChar >= snumChars) {
			curChar = 0;
			try {
				snumChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (snumChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int[] nextIntArray(int n) {
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		return a;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

}

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

public class Main {
    private static FastReader sc = new FastReader(System.in);
    private static OutputWriter out = new OutputWriter(System.out);

    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        long maxSum = n + n - 1;
        long maxNines = 0;
        for (long i = 1; i <= 1e8; i *= 10) {
            if (maxNines + 9 * i <= maxSum) maxNines += 9 * i;
            else break;
        }

        long ans = 0;
        for (long i = Math.max(maxNines, 3); i <= maxSum; i += maxNines + 1) {
            long min = i / 2 + 1;
            long max = i - 1;
            long cnt = Math.max(0, Math.min(n - min + 1, max - min + 1));
            ans += cnt;
        }
        System.out.println(ans);
    }
}

class FastReader {
    private boolean finished = false;

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public FastReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1) {
            throw new InputMismatchException();
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0) {
                return -1;
            }
        }

        return buf[curChar++];
    }

    public int peek() {
        if (numChars == -1) {
            return -1;
        }
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                return -1;
            }
            if (numChars <= 0) {
                return -1;
            }
        }
        return buf[curChar];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c == ',') {
                c = read();
            }
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null) {
            return filter.isSpaceChar(c);
        }
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private String readLine0() {
        StringBuilder buf = new StringBuilder();
        int c = read();
        while (c != '\n' && c != -1) {
            if (c != '\r') {
                buf.appendCodePoint(c);
            }
            c = read();
        }
        return buf.toString();
    }

    public String nextLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    public String nextLine(boolean ignoreEmptyLines) {
        if (ignoreEmptyLines) {
            return nextLine();
        } else {
            return readLine0();
        }
    }

    public BigInteger nextBigInteger() {
        try {
            return new BigInteger(nextString());
        } catch (NumberFormatException e) {
            throw new InputMismatchException();
        }
    }

    public char nextCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public double nextDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E') {
                return res * Math.pow(10, nextInt());
            }
            if (c < '0' || c > '9') {
                throw new InputMismatchException();
            }
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }

    public boolean isExhausted() {
        int value;
        while (isSpaceChar(value = peek()) && value != -1)
            read();
        return value == -1;
    }

    public String next() {
        return nextString();
    }

    public SpaceCharFilter getFilter() {
        return filter;
    }

    public void setFilter(SpaceCharFilter filter) {
        this.filter = filter;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }

    public void flush() {
        writer.flush();
    }

}

import java.util.*;
public class sol
{
	public static void main(String args[])
	{
		int x ;
		Scanner scan = new Scanner(System.in);
		x = scan.nextInt();
		int p = 2*x-1;
		int r1 = p ;
		int a = 0,b=0,flag=0,ans=0;
		int t =0;
		while(p>0)
		{
              if(p%10==9)
              {
              	a++;
              }
              b++;
              p/=10;
		}
		p=r1;
		if(a==b)
		{
			ans = 1;
		}
		else if(x<5)
			{
              ans=x*(x-1)/2 ;
           }
		else
		{
			if(a==b-1)
			{
				flag = 1 ;
			}
			while(p>0)
			{
                 t = p%10 ;
                 p/=10    ;
			}
			//System.out.println( t + " " + y + " " +r);
			if(flag==0 || t==9)
			{
               t-- ;
			}
			int r = t ;
			long y = 1;
			b--;
			while(b>0)
			{
				t*=10;
				t+=9 ;
				y*=10;
				b--;
			}
			//System.out.println( t + " " + y + " " +r);
			//int ans = 0;
			for(int i = r ;i >=0 ;i--)
			{
			   if(t>x)
               ans += (t-1)/2+(x-t)+1;
               else
               ans +=(t-1)/2;
               t-=y;
			}
		}
		System.out.println(ans);
	}
}

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class Prac{
    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        public InputReader(InputStream st) {
            this.stream = st;
        }
        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
            c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public int[] nia(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public String rs() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                    c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
    public static class Key {

        private final int x;
        private final int y;

        public Key(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Key)) return false;
            Key key = (Key) o;
            return x == key.x && y == key.y;
        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }

    }
    static class Pair{
        int x,y;
        public Pair(int x,int y){
            this.y=y;
            this.x=x;
        }
    }

    static PrintWriter w = new PrintWriter(System.out);
    static long mod=998244353L,mod1=1000000007;

    static boolean count(int i){
        while(i>0){
            if(i%10!=9)return false;
            i/=10;
        }
        return true;
    }
    static int digit(int n){
        int c=0;
        while(n>0){
            c++;
            n/=10;
        }
        return c;
    }

    public static void main(String [] args){
        InputReader sc=new InputReader(System.in);
        int n=sc.ni();
        int num=2*n-1;
        if(count(num))w.println(1);

        else if(n<=4)w.println((n*(n-1))/2);
        else{
            int times=digit(num)-1;

            long x=(long)Math.pow(10,times)-1;
            int ans=0;
            while(x<=num){
                if(x<=n)ans+=x/2;
                else ans+=(n-x/2);
                x+=(long)Math.pow(10,times);
            }
            w.println(ans);
        }
        w.close();
    }
}

import java.io.*;
import java.util.*;
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);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
        static class TaskE {
         int a1[]={31,28,31,30,31,30,31,31,30,31,30,31};

         public void solve(int testNumber, InputReader in, PrintWriter out) {
          long n=in.nextInt();
          long max=2*n-1;
          int d=1;long m=10;
          while(max/m!=0){d++;m*=10;}
          StringBuilder sb=new StringBuilder();
          for(int i=1;i<d;i++)sb.append('9');//out.println(sb);
          ArrayList<Long> al=new ArrayList<>();
          for(int i=0;i<=9;i++){
           StringBuilder sb1=new StringBuilder(sb);
           sb1.insert(0,String.valueOf(i));//out.println(sb1);
           long v=Long.valueOf(sb1.toString());//out.println(v+" "+max);
           if(v>max){break;}
           if(i==9){al.clear();}
           al.add(v-1);
          }//out.println(al);
           long ans=0;
           for(int i=0;i<al.size();i++){
            long e=al.get(i)/2+1;if(2*e==al.get(i)+1)ans--;
            ans+=Math.max(Math.min(n,al.get(i))-e+1,0);
           }
           out.print(ans);
         }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

public class Codeforces {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        FastReader(final InputStream is) {
            if (is != null)
                br = new BufferedReader(new
                                        InputStreamReader(is));
            else new FastReader();
        }

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

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

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

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

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

    static PrintWriter writer;
    public static void main(String args[]) throws Exception {
        final FastReader reader = new FastReader();
        writer = new PrintWriter(new BufferedOutputStream(System.out));
        int n = reader.nextInt();
        if (n <= 4) {
            writer.println(n * (n - 1) / 2);
        } else {
            // writer.println("n=" + n);
            long max = 2 * n - 1;
            String maxS = Long.toString(max);
            // writer.println("maxS = " + maxS);
            //check if all nines
            boolean allNines = true;
            for (int i = 0; i < maxS.length(); i++) {
                if (maxS.charAt(i) != '9') {
                    allNines = false;
                    break;
                }
            }
            if (allNines) {
                writer.println(1);
            } else {
                // writer.println("not 9s");
                long total = 0;
                int nos = maxS.charAt(0) - 48;
                // writer.println("total no of targets with " + (maxS.length() - 1) + " nines is <=" + (nos+1));
                long multiplier = (long) Math.pow(10, maxS.length() - 1);
                // writer.println("multiplier is " + multiplier);
                for (int i = nos+1; i >= 1; i--) {
                    long target = multiplier * i - 1;
                    if(target > max) continue;
                    //writer.println("target is " + target);
                    if (target > n) {
                      //  writer.println("target(" + target + ") is higher than n(" + n + ")");
                        // writer.println("removing " + (target - 1) + " - " + (n + 1) + " + 1 = " + ((target - 1)  - (n + 1) + 1) + " invalid cases");
                        total -= (target - 1)  - (n + 1) + 1 ;
                    } else {
                        // writer.println("target is lesser than max " + n);
                    }
                    // writer.println("adding all cases " + ((target - 1) - (target + 1) / 2 + 1));
                    total += (target - 1) - (target + 1) / 2 + 1;
                }
                writer.println(total);
            }
        }
        writer.close();
    }
}

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

public class ProblemH
{

    static int mod = (int) (1e9+7);
    static InputReader in;
    static PrintWriter out;

    static long get(long max, long n){

        long x = max - 1;
        if(x % 2 != 0) return 0;
        x /= 2;
        if(!(x + 1 >= 1 && x + 1<= n) || !(x >= 1 && x <= n)) return 0;
        long l = 1;
        long r = x;
        long idx = x;
        while(r - l >= 0){
            long m = (r + l) >> 1;
            if(max - m >= 1 && max - m <= n){
                idx = m;
                r = m - 1;
            }
            else l = m + 1;
        }

        return x - idx + 1;
    }

    public static void main(String[] args) throws FileNotFoundException
    {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        int n = in.nextInt();

        long m = n + n - 1;
        long c = 0;
        long max = 0;

        while(true){
            c = c * 10 + 9;
            if(c <= m) max = c;
            else break;
        }
        long l = 0;
        m = max;
        while(m > 0){
            m /= 10;
            l++;
        }
        l = pow(10, l);
        long cnt = 0;

        for(long i = 0; i <= 9; i++){
//            debug(get(max + i * l, n), max + i * l);
            cnt += get(max + i * l, n);
        }
//        debug(cnt);
        if(n < 5){
            cnt = (n * (n - 1)) / 2;
        }
        out.println(cnt);
        out.close();
    }

    static void debug(Object... o)
    {
            System.out.println(Arrays.deepToString(o));
    }

    static class Pair implements Comparable<Pair>
    {

        int x,y;

        Pair (int x, int y)
        {
		this.x = x;
                this.y = y;
	}

	public int compareTo(Pair o) {
                return Integer.compare(this.y,o.y);
	}

        public boolean equals(Object o)
        {
            if (o instanceof Pair)
            {
                Pair p = (Pair)o;
                return p.x == x && p.y==y;
            }
            return false;
        }

        @Override
        public String toString()
        {
            return x + " "+ y;
        }

        public int hashCode()
        {
            return new Long(x).hashCode() * 31 + new Long(y).hashCode();
        }

    }

    static long add(long a,long b){
        long x=(a+b);
        while(x>=mod) x-=mod;
        return x;
    }

    static long sub(long a,long b){
        long x=(a-b);
        while(x<0) x+=mod;
        return x;
    }

    static long mul(long a,long b){
        long x=(a*b);
        while(x>=mod) x-=mod;
        return x;
    }

    static String rev(String s){
        StringBuilder sb=new StringBuilder(s);
        sb.reverse();
        return sb.toString();
    }

    static long gcd(long x,long y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static int gcd(int x,int y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static long pow(long n,long p,long m)
    {
         long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            if(result>=m)
            result%=m;
            p >>=1;
            n*=n;
            if(n>=m)
            n%=m;
        }
        return result;
    }

    static long pow(long n,long p)
    {
        long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            p >>=1;
            n*=n;
        }
        return result;
    }

    static class InputReader
    {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
                this.stream = stream;
        }

        public int snext()
        {
                if (snumChars == -1)
                        throw new InputMismatchException();
                if (curChar >= snumChars)
                {
                        curChar = 0;
                        try
                        {
                                snumChars = stream.read(buf);
                        } catch (IOException e)
                        {
                                throw new InputMismatchException();
                        }
                        if (snumChars <= 0)
                                return -1;
                }
                return buf[curChar++];
        }

        public int nextInt()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                int res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public long nextLong()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                long res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public int[] nextIntArray(int n)
        {
                int a[] = new int[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextInt();
                }
                return a;
        }

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

        public String readString()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
        }

        public String nextLine()
        {
                int c = snext();
                while (isSpaceChar(c))
                        c = snext();
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
                if (filter != null)
                        return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c)
        {
                return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter
        {
                public boolean isSpaceChar(int ch);
        }

    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class _v17 {

    static boolean allNine(long n){

        while (n!=0){
            if(n%10 != 9){
                return false;
            }
            n = n/10;
        }

        return true;
    }
    public static void main(String args[]){

        PrintWriter out = new PrintWriter(System.out);
        Reader in = new Reader();
        long n = in.nextInt();
        int len = String.valueOf(n).length();
        long limit = 5*(long)Math.pow(10,len-1);
        if(n<5){
            out.println((n*(n-1))/2);
        }
        else if(n>=limit){
                 if(allNine(n)){
                     out.println(n-limit);
                 }
                 else{
                     out.println(n-limit+1);
                 }
        }
        else{
            long res = 0;
            long num = (long)Math.pow(10,len-1);

            for(int i=1;i<10;i++){
                    long x = i*num - 1;
                    long l = x/2 + 1;

                    long r = Math.min(n,x-1);
                    if(l<=r){
                        res += (r-l+1);
                    }

                }

            out.println(res);
        }

        out.flush();
        out.close();
    }
    static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();

            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}

//Standard template for my java code: Arun Ganesh//
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[1000001]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
   static StringBuilder fin = new StringBuilder("");
   static long mod = 1000000007;

    public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		long n = in.nextLong();
		long ans =0;
		if(n<5)
			ans = n*(n-1)/2;
		else
	    {

		String s = Long.toString(n);
		int len = s.length();

		long ach = (long)Math.pow(10.0,len)-1;
		long limit = n + n-1;
		int z =0;
		if(limit >= ach)
		{
			ans = ans + (n-ach+n+1)/2;
			if(ach == n)
				ans--;
		}

		else
		{
			long bain = (long)Math.pow(10.0,len-1)-1;
			ans = ans + (bain-1)/2;
			int figs = len-1;
			long create = (long)Math.pow(10.0,figs)+bain;
			for(long i = create;i<=limit;i = i + (long)Math.pow(10.0,figs))
			{
				if(i >=n)
				{
				long lower = i - n;
				if(lower == 0)
				{
					ans = ans + (n-1)/2;
					continue;
				}
				ans = ans + (n-lower+1)/2;
				//System.out.println(i + " " + ans);
				}
				else
					ans = ans + (i-1)/2;
			}
		}
			}
		fin.append(ans);
		System.out.print(fin);

	}

 static long modInverse(long a, long m)
{

       return power(a, m-2, m);

}

// To compute x^y under modulo m
static long power(long x, long y, long m)
{
    if (y == 0)
        return (long)1;
    long p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
/*static class dj{
	int par[],n,rank[];
	List<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
	dj(int n)
	{
		this.n=n;
		par = new int[n+5];
		rank = new int[n+5];
		for(int i=0;i<=n;++i)
			par[i] = i;
	}
	public void mp(int x,int y)
	{
		int par1 = find(x);
		int par2 = find(y);
		if(rank[par1] >rank[par2])
		{
		par[par2] = par1;
		rank[par1]++;
		}
		else
		{
			par[par1] = par2;
			rank[par2]++;
		}
	}
	public int find(int x)
	{
		while(x!=par[x])
		{
			x = par[x];
		}
		return x;
	}
	public long finish()
	{
		for(int i=0;i<2005;++i)
			al.add(new ArrayList<Integer>());
		for(int i=0;i<n;++i)
			par[i] = find(i);
		for(int i=0;i<n;++i) System.out.print(par[i]+ " ");System.out.println();
		int ans[] = new int[2005];
		int cnt[] = new int[2005];
		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
				cnt[i] = cnt[i]+a[i][j];
		Arrays.fill(ans,-1);
		int ind=0;
		for(int i=0;i<n;++i)
		{
			int temp = par[i];
			if(ans[temp] == -1)
			{
				ans[temp] = ind;
				ind++;

			}
			al.get(ans[temp]).add(i);
		}
		long sum=0;
		for(int i=0;i<n;++i){
			for(int j=0;j<al.get(i).size();++j)
			{
				System.out.print(al.get(i).get(j) + " ");
			    sum = sum + (al.get(i).size() - cnt[al.get(i).get(j)] -1);
			}
			System.out.println();
	}

		return sum;
	}
}*/

  }

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

public class Test {
    Scanner sca = new Scanner(System.in);

    void start() {
        int n = sca.nextInt();
        long v = 0, b = 1;
        while (v < n+n-1) {
            v = v*10 + 9;
            b = b*10;
        }
        int ans = 0;
        if (v == n+n-1) ans = 1;
        else {
            v /= 10;
            b /= 10;
            for (int i = 0; i <= 9; i++) {
                long a = b*i + v;
                if (a <= n) ans += (a - 1) / 2;
                else if (a - n < n) ans += (n - (a - n) + 1) / 2;
            }
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class B {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        int MAX = 2*n-1;
        long nines = 9;
        int count = 0;
        while(MAX >= nines) {
          count++;
          nines = 10*nines + 9;
        }
        nines = (nines - 9)/(10);
        long ans = 0; long curval = nines;
        while(MAX >= curval) {
          if(curval <= n+1)
            ans += (curval-1)/2;
          else
            ans += (2*n - curval + 1)/2;
          curval += (int)Math.pow(10, count);
        }
        out.println(ans);
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int n =  Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }

}

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

/**
 * @author Don Li
 */
public class ShovelSale {
    void solve() {
        int n = in.nextInt();

        int cnt = 0;
        long val = 0;
        while (val * 10 + 9 <= 2 * n - 1) {
            cnt++;
            val = val * 10 + 9;
        }

        if (cnt == 0) {
            out.println(n * (n - 1) / 2);
            return;
        }

        long base = 1;
        for (int i = 0; i < cnt; i++) base *= 10;

        int ans = 0;
        for (int p = 0; p < 10; p++) {
            long t = p * base + val;
            if (t > 2 * n - 1) break;
            int fr = 1, to = (int) Math.min(n, t / 2);
            fr = (int) Math.max(fr, t - n);
            to = (int) Math.min(to, t - 1);
            if (to >= fr) ans += to - fr + 1;
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new ShovelSale().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sanket Makani
 */
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 sc, PrintWriter w) {

            long n = sc.nextLong();
            long ans = 0;

            long max = n + (n - 1);

            if (n <= 4) {
                w.println(n * (n - 1) / 2);
                return;
            }
            if (check(max)) {
                w.println("1");
                return;
            }

            String str = "" + max;
            int digits = str.length();
            int first = str.charAt(0) - '0';

            first--;
            if (check1(str))
                first++;

            long add = (long) Math.pow(10, digits - 1);

            long curr = 0;

            for (int i = 0; i < digits - 1; i++) {
                curr *= 10;
                curr += 9;
            }

            for (int i = 0; i <= first; i++) {
                long f = (curr + 1) / 2;
                long s = curr - f;

                ans += Math.min(n - f + 1, s);
                curr += add;
            }
            w.println(ans);

//        long ans1=brute(n);
//        w.println(ans1);
        }

        private boolean check1(String str) {
            for (int i = 1; i < str.length(); i++) {
                if (str.charAt(i) != '9')
                    return false;
            }

            return true;
        }

        private boolean check(long max) {
            HashSet<Long> set = new HashSet<Long>();
            while (max > 0) {
                set.add(max % 10);
                max /= 10;
            }

            if (set.size() == 1 && set.contains(9L))
                return true;
            return false;

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.Scanner;

public class probemD {
	public static boolean allnine(int x)
	{
		boolean gg=true;
		while(x!=0)
		{
			int k=x%10;
			if(k!=9)
			{
				return false;

			}
			x=x/10;
		}
		return true;
	}
	public static int nodig(int x)
	{
		int dig=0;
		while(x!=0)
		{
			x/=10;
			dig++;
		}
		return dig;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int maxn=n+n-1;
		if(maxn<9)
		{
			System.out.println(n*(n-1)/2);
		}else if(allnine(maxn))
		{
			System.out.println(1);
		}else {
			long ans=0;
			int nonine=nodig(maxn)-1;
			long num=(long) (Math.pow(10, nonine)-1);
		//	System.out.println(num);
			while(num<=maxn)
			{
				if(n>=num)
				{
					ans+=(num/2);
				}else {
					ans+=(n- num/2);
				}
				num+=Math.pow(10,nonine);

			}
			System.out.println(ans);
		}

	}
}

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

public class D452Div2
{
    public static void main(String[] args)
    {
        new D452Div2(System.in, System.out);
    }

    private static class Solver implements Runnable
    {
        int n;
        InputReader in;
        PrintWriter out;

        void solve() throws IOException
        {
            n = in.nextInt();

            long maxN = n + n - 1;

            if (n < 5)
                out.println((long) n * (n - 1) / 2);
            else if (areAllNines(maxN))
                out.println(1);
            else
            {
                long ans = 0;
                long numberOfNines = ("" + maxN).length() - 1;
                long num = (long) (Math.pow(10, numberOfNines)) - 1;

                while (num <= maxN)
                {
                    if (num <= n)
                        ans += num / 2;
                    else
                        ans += (n - num / 2);

                    num += Math.pow(10, numberOfNines);
                }

                out.println(ans);
            }
        }

        boolean areAllNines(long num)
        {
            String s = "" + num;

            for (char ch : s.toCharArray())
                if (ch != '9')
                    return false;

            return true;
        }

        Solver(InputReader in, PrintWriter out)
        {
            this.in = in;
            this.out = out;
        }

        @Override
        public void run()
        {
            try
            {
                solve();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

    }

    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        int nextInt()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        InputReader(InputStream stream)
        {
            this.stream = stream;
        }

    }

    private D452Div2(InputStream inputStream, OutputStream outputStream)
    {
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 29);

        try
        {
            thread.start();
            thread.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        in.close();
        out.flush();
        out.close();
    }

}

/**
 * @author derrick20
 */

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

public class ShovelSale {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

//        for (int N = 1; N <= 100; N++) {
        String s = sc.next();
        int N = Integer.parseInt(s);
        long S = 2 * N - 1;
        int max = 0;
        long x = 0;
        long sum = 0;
        while ((10 * x + 9) <= S) {
            max++;
            x = 10 * x + 9;
        }
        sum = x;
        x = 1;
        for (int i = 0; i < max; i++) {
            x *= 10;
        }
        while (sum + x <= S) {
            sum += x;
        }

//        int bruteans = brute(N, max);
//        System.out.println("Brute for " + N + " and max of " + max + ": " + bruteans);

//        System.out.println(sum);
//        System.out.println(x);
        long ans = 0;
        if (max == 0) {
            ans = N * (N - 1) / 2;
        }
        else {
            while (sum >= x) {
                ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
                sum -= x;
            }
            ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
        }
//            System.out.println(ans);
//            if (bruteans != ans) {
//                System.exit(0);
//            }
//        }
        out.println(ans);
        out.close();
    }

    static int brute(int N, int max) {
        int res = 0;
        for (int i = 1; i <= N; i++) {
            for (int j = i + 1; j <= N; j++) {
                int sum = i + j;
                int ct = 0;
                while (sum > 0) {
                    if (sum % 10 == 9) {
                        ct++;
                    }
                    else {
                        break;
                    }
                    sum /= 10;
                }
                if (ct == max) {
//                    System.out.println(i + j);
                    res++;
                }
            }
        }
        return res;
    }

    static class FastScanner {
        private int BS = 1 << 16;
        private char NC = (char) 0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt = 1;
            boolean neg = false;
            if (c == NC) c = getChar();
            for (; (c < '0' || c > '9'); c = getChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = getChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                cnt *= 10;
            }
            return neg ? -res : res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c != '.' ? cur : cur + nextLong() / cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c > 32) {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c != '\n') {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class d {

	public static long go(long v, long o) {
		long lowest = v - o;
		lowest = Math.max(1, lowest);
		long highest = v - 1;
		highest = Math.min(highest, v - lowest);
//		System.out.println(lowest + " " +highest);
		if(highest < lowest) return 0;
		return (highest - lowest + 1)/2;
	}
	public static void main(String args[]) throws IOException {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//BEGIN HERE
		long n = in.nextLong();
		long o = n;
		n += n-1;
		if(n < 9) {
			int ans = 0;
			for(int i = 1; i <= o; i++) {
				for(int j = i+1; j <= o; j++)
					ans ++;
			}
			System.out.println(ans);
			return;
		}
		long i = 0;
		while(i <= n){
			i *= 10l;
			i += 9l;
		}
		i/=10;

		String s = n+"";
		String is = i+"";
//		System.out.println(is);
		long ans = 0;
		for(int j = 0; j < 10; j++) {
			long v = Long.parseLong(j + is);
//			System.out.println(v);
			if(v > n) break;
//			System.out.println(v);
			ans += go(v, o);
//			System.out.println(go(v, o));
		}
		System.out.println(ans);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream i) {
			br = new BufferedReader(new InputStreamReader(i));
			st = null;
		}

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

		public String nextLine() throws IOException {
			if (st == null) {
				st = new StringTokenizer(br.readLine());
			}
			String line = st.nextToken("\n");
			st = null;
			return line;
		}

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

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

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

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

public class Solution {

    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    private static HashMap<Long, Long>[] mods;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();

        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));

        initData();
        solve();
        out.flush();
    }

    private static void initData() {

    }

    static String k;
    static long[] t0;
    static long[] t1;

    static long[] pow0;
    static long[] pow1;

    private static void solve() {
        int n = sc.nextInt();
        if (n <= 4) {
            out.print(n * (n - 1) / 2);
            return;
        }
        int max = n + n - 1;
        long r = 0;
        long mm = 1;
        while (max >= (r * 10 + 9)) {
            r = r * 10 + 9;
            mm *= 10;
        }
        long res = 0;
        for (int lm = 0; lm * mm + r <= max; lm++) {
            long sa = lm * mm + r;
            long min = Math.max(1, sa - n);
            res += Math.max(1, (sa - 1) / 2) - min + 1;
        }
        out.println(res);
    }

    private static String pr(int i, int l, int l1) {
        return k.substring(0, i) + "+" +
                k.substring(i, i + l) + "=" +
                k.substring(i + l);
    }

    private static boolean check1(int i1, int i2, int l) {
        if (i1 <= 0 || i1 <= 0) return false;
        if (i1 > l || i2 > l) return false;
        long s1 = t0[i1];
        long s2 = t0[i2 + i1] - t0[i1] * (pow0[i2]) % 1000000007;
        long s3 = t0[i1 + i2 + l] - t0[i2 + i1] * pow0[l] % 1000000007;

        long rr = s1 + s2 - s3;
        if (rr % 1000000007 != 0) return false;

        s1 = t1[i1];
        s2 = t1[i2 + i1] - t1[i1] * (pow1[i2]) % 1000000009;
        s3 = t1[i1 + i2 + l] - t1[i2 + i1] * pow1[l] % 1000000009;

        rr = s1 + s2 - s3;
        if (rr % 1000000009 != 0) return false;

        return true;

    }

    private static boolean solve(int n, int p, int p1, int i) {
        return false;
    }

    private static boolean isset(long i, int k) {
        return (i & (1 << k)) > 0;
    }

    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

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

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

}

import java.util.Scanner;

public class Main {

	public static long form(long n, long val) {
		long mid = (val - 1) >> 1;
		if(mid >= n) {
			return 0;
		}
		if(n >= val) {
			return mid;
		}
		return n - mid;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long count = 0, temp = 0;
		while(10 * temp + 9 <= n + (n - 1)) {
			count++;
			temp = temp * 10 + 9;
		}
		if(count == 0) {
			System.out.println(((n) * (n - 1)) / 2);
			return;
		}
		long ans = 0;
		for(int i = 0; i < 9; i++) {
			if(Math.pow(10, count) * i + temp > n + (n - 1)) {
				break;
			}
			long term = (long)Math.pow(10, count) * i + temp;
			ans += form(n, term);
		}
		System.out.println(ans);
	}

}

//package math_codet;
//at last done :( why am I getting WA
//shit such a silly mistake
import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    boolean check(long z) {
        boolean flag=false;
        if(z%10!=9)
            flag=true;
        else {
            boolean iss=false;
            while(z>0) {
                long r=z%10;
                if(r==9 && iss) {
                    flag=true;
                    break;
                }
                if(r!=9) {
                    iss=true;
                }
                z/=10;
            }
        }
        return flag;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
            //h.pn(arr[i]);;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1 ;i--){
            if(arr[i]-n<n){
                //h.pn(arr[i]);;
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<x1){
                        if(x2<=0)
                            x2=1;
                        if(sum1<n)
                            x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                        //h.pn(x1+" "+x2);;
                    }
                }
                h.pn(ans);;
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn((n*(n-1))/2);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

//package math_codet;
//I got so many WA's in such a simple question _-_
import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1 ;i--){
            if(arr[i]-n<n){
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    if(x2<x1){
                        if(x2<=0)
                            x2=1;
                        if(sum1<n)
                            x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                h.pn(ans);;
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn((n*(n-1))/2);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

import java.util.*;

/**
 * Created by evgeniyradchenko on 11/28/17.
 */
public class Main {

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

        int n = s.nextInt();

        long cur = 0;

        while (cur * 10 + 9 <= n + (n - 1)) {
            cur = cur * 10 + 9;
        }

        if (cur == 0) {
            System.out.println(n * (n - 1) / 2);

            return;
        }

        if (cur > n) {
            long ans = (2 * n - cur + 1) / 2;
            long add = cur + 1;

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }
            System.out.println(ans);
        } else {
            long add = cur + 1;
            long ans = (cur - 1) / 2;

            while (cur + add <= n) {
                cur += add;
                ans += (cur - 1) / 2;
            }

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }

            System.out.println(ans);
        }
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        private int pow10(int n) {
            int res = 1;
            for (int i = 0; i < n; i++) {
                res *= 10;
            }
            return res;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int MAX = 1_000_000_000;
            int lim = 2 * n;
            long ans = 0;
            if (n < 5) {
                out.println(n * (n - 1) / 2);
                return;
            }
            for (int i = 9; i > 0; i--) {
                int pow = pow10(i);
                if (pow > lim) continue;
                for (int d = 0; d < 9; d++) {
                    long num = (long) pow * (d + 1) - 1;
                    if ((num + 1) / 2 <= n) {
                        ans += Math.min(n, num - 1) - (num + 1) / 2 + 1;
                    } else
                        break;
                }
                out.println(ans);
                return;
            }
            out.println(0);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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.readInt();
            if (n < 5) {
                out.println((n * (n - 1)) / 2);
                return;
            }

            long max = maxNine(n);
            long ans = (max - 1) / 2;
            if (max > n) {
                ans -= max - n - 1;
            }

            long ten = (long) Math.pow(10L, (max + "").length());
            for (int i = 1; ten * i + max < 2 * n; i++) {
                long v = ten * i + max;
                ans += (v - 1) / 2;
                if (v > n) ans -= v - n - 1;
            }
            out.println(ans);

        }

        long maxNine(int n) {
            long t = n * 2 - 1, ans = 0;
            for (long i = 9; i <= t; i = i * 10 + 9) {
                ans = i;
            }
            return ans;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Task10029C {
    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Task10029C task = new Task10029C();
        task.open();
        task.solve();
        task.close();
    }

    private void close() {
        out.flush();
        out.close();
    }

    private void solve() throws IOException {
        int N = nextInt();

        int sum = N + (N - 1);

        if (sum < 9) {
            out.println(N * (N - 1) / 2);
            return;
        }

        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++) {
            long p = Long.parseLong(c + suffix);
            if (p <= N) {
                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;
    }

    private void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    private String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) return null;
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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) {
            long n = in.nextInt();
            if (n < 5) {
                out.println(n * (n - 1) / 2);
                return;
            }

            long d = 9;
            while (n > (d * 10 + 9) / 2) {
                d *= 10;
                d += 9;
            }

            long sum = 0;
            long nd = d;
            while (true) {
                long top = Math.min(n, nd - 1);
                long bot = (nd + 1) / 2;
                long add = (top - bot + 1);
                if (add <= 0)
                    break;

                sum += (top - bot + 1);
                nd = nd + d + 1;
            }

            out.println(sum);
        }

    }

    static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String next() {
            if (st == null || !st.hasMoreTokens()) {
                String nextLine = null;
                try {
                    nextLine = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (nextLine == null)
                    return null;
                st = new StringTokenizer(nextLine);
            }
            return st.nextToken();
        }

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

    }
}

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

public class D899 {

	private void solve() throws Exception {
		long n = nextInt();
		long sum = 0;
		long digits = 1;
		while(sum <= 2*n-1) {
			sum = 10*sum+9;
			digits *= 10;
		}
		sum = (sum-9)/10;
		digits /= 10;
		long res = 0;
		for(int i = 0; i < 9; i++) {
			res = res + Math.max(0, Math.min(n, sum-1)-sum/2);
			sum = sum+digits;
		}
		out.println(res);
	}

	public static void main(String[] args) {
		new D899().run();
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

	private String nextLine() throws IOException {
		return new String(in.readLine());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(in.readLine());
		}
		return tokenizer.nextToken();
	}
}

class State{
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + last;
		result = prime * result + set;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		State other = (State) obj;
		if (last != other.last)
			return false;
		if (set != other.set)
			return false;
		return true;
	}

	int set;
	int last;

	public State(int set, int last){
		this.set = set;
		this.last = last;
	}
}

/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         if(N <= 4)
         {
            System.out.println(0);
            return;
         }
         String lol = "9";
         while(true)
         {
            long val = Long.parseLong(lol);
            if(2*N-1 < val)
               break;
            lol += 9;
         }
         int max9 = lol.length()-1;
         lol = lol.substring(1);
         long res = 0L;
         long check = Long.parseLong(lol);
         while(2*N-1 >= check)
         {
            long min = Math.max(1, check-N);
   			long max = check/2;
   			res += max-min+1;
   			check += Long.parseLong(lol)+1;
         }
         System.out.println(res);
      }
   }

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*(long)Math.pow(10,i-1))+9;
            arr[i]=sum;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1;i--){
            if(arr[i]-n<n){
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                        	x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                h.pn(ans);
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn(0);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        int countSuffix(String s) {
            int len = s.length();
            int ct = 0;
            for (int i = len - 1; i >= 0; i--) {
                if (s.charAt(i) == '9')
                    ct++;
            }
            return ct;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();

            if (n <= 4) {
                out.println((n * (n - 1)) / 2);
                return;
            }

            String max = (n - 1 + n) + "";
            int len = max.length();

            long lo, hi, diff;
            if (countSuffix(max) == len) {
                lo = hi = Long.parseLong(max);
                diff = 1L;
            } else {
                StringBuilder nine = new StringBuilder();
                StringBuilder zero = new StringBuilder();
                for (int i = 1; i < len; i++) {
                    nine.append('9');
                    zero.append('0');
                }

                diff = Long.parseLong(1 + zero.toString());
                lo = Long.parseLong(nine.toString());
                hi = Long.parseLong((max.charAt(0) - '1') + nine.toString());
            }

            if (countSuffix(max) == len - 1) {
                hi += diff;
            }

            long ct = 0;
            for (long i = hi; i >= lo; i -= diff) {
                ct += (i / 2);
                ct -= Math.max(0, i - n - 1);
            }
            out.println(ct);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = 2 * n - 1;
		int l = Integer.toString(m).length();
		char[] c = Integer.toString(m).toCharArray();
		boolean b = true;
		for (int i = 0; i < c.length; i++) {
			if (c[i] != '9')
				b = false;
		}
		if (b)
			System.out.println(1);
		else {
			if (n >= 5) {
				l--;
				String s = "";
				for (int i = 0; i < l; i++)
					s += "9";
				int k = Integer.parseInt(s);
				int k1 = k + 1;
				int n1 = k;

				int count = 0;
				while (n1 <= m) {
					if (n1 < n)
						count += (n1 / 2);
					else {
						count += n1 / 2;
						count -= Math.max((n1 - n - 1), 0);
					}

					n1 += k1;
				}
				System.out.println(count);
			} else
				System.out.println(n*(n-1)/2);
		}
	}

}

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    boolean check(long z) {
        boolean flag=false;
        if(z%10!=0)
            flag=true;
        else {
            boolean iss=false;
            while(z>0) {
                long r=z%10;
                if(r==9 && iss) {
                    flag=true;
                    break;
                }
                if(r!=9) {
                    iss=true;
                }
                z/=10;
            }
        }
        return flag;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
            //h.pn(arr[i]);;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1 ;i--){
            if(arr[i]-n<n){
                //h.pn(arr[i]);;
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                            x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                if(check(n))
                    h.pn(ans-1);
                else
                    h.pn(ans);;
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn((n*(n-1))/2);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

import java.util.*;
public class sol
{
	public static void main(String args[])
	{
		int x ;
		Scanner scan = new Scanner(System.in);
		x = scan.nextInt();
		int p = 2*x-1;
		int r1 = p ;
		int a = 0,b=0,flag=0,ans=0;
		int t =0;
		while(p>0)
		{
              if(p%10==9)
              {
              	a++;
              }
              b++;
              p/=10;
		}
		p=r1;
		if(a==b)
		{
			ans = 1;
		}
		else if(x<5)
			ans=0 ;
		else
		{
			if(a==b-1)
			{
				flag = 1 ;
			}
			while(p>0)
			{
                 t = p%10 ;
                 p/=10    ;
			}
			if(flag==0)
			{
               t-- ;
			}
			int r = t ;
			long y = 1;
			b--;
			while(b>0)
			{
				t*=10;
				t+=9 ;
				y*=10;
				b--;
			}
			//System.out.println( t + " " + y + " " +r);
			//int ans = 0 ;
			for(int i = r ;i >=0 ;i--)
			{
			   if(t>x)
               ans += (t-1)/2+(x-t)+1;
               else
               ans +=(t-1)/2;
               t-=y;
			}
		}
		System.out.println(ans);
	}
}

import java.util.*;

/**
 * Created by evgeniyradchenko on 11/28/17.
 */
public class Main {

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

        int n = s.nextInt();

        int cur = 0;

        while (cur * 10 + 9 <= n + (n - 1)) {
            cur = cur * 10 + 9;
        }

        if (cur == 0) {
            System.out.println(n / 2);

            return;
        }

        if (cur > n) {
            int ans = (2 * n - cur + 1) / 2;
            int add = cur + 1;

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }
            System.out.println(ans);
        } else {
            int add = cur + 1;
            int ans = (cur - 1) / 2;

            while (cur + add <= n) {
                cur += add;
                ans += (cur - 1) / 2;
            }

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }

            System.out.println(ans);
        }
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        private int pow10(int n) {
            int res = 1;
            for (int i = 0; i < n; i++) {
                res *= 10;
            }
            return res;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int MAX = 1_000_000_000;
            int lim = 2 * n;
            long ans = 0;
            for (int i = 9; i > 0; i--) {
                int pow = pow10(i);
                if (pow > lim) continue;
                for (int d = 0; d < 9; d++) {
                    long num = (long) pow * (d + 1) - 1;
                    if ((num + 1) / 2 <= n) {
                        ans += Math.min(n, num - 1) - (num + 1) / 2 + 1;
                    } else
                        break;
                }
                out.println(ans);
                return;
            }
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n=ir.nextInt();
		int t=Integer.toString(2*n).length()-1;
		if(t==0){
			out.println(0);
		}
		else{
			int x=(int)Math.pow(10,t);
			int p=n/x;
			int q=n%x;
			int ans=-1;
			int r=x/2-1-q;
			if(q==0){
				ans=(x/2-1)*p*p+p*p;
			}
			else{
				if(q<=x/2-1){
					ans=q*(p+1)*p+r*p*p+p*p;
				}
				else if(q==x-1){
					ans=(x/2-1)*(p+1)*(p+1)+(p+1)*p;
				}
				else{
					r*=-1;
					ans=r*(p+1)*(p+1)+(x/2-1-r)*p*(p+1)+p*p;
				}
			}
			out.println(ans);
		}
	}

	static ArrayList<Integer> f(int l,int r){
		ArrayList<Integer> ret=new ArrayList<>();
		int a=((r-l)+1)/2;
		for(int i=l;i<l+a;i+=2){
			ret.add(i);
			ret.add(l+r-i);
		}
		return ret;
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

import java.util.Scanner;

public class Main {

	public static long form(long n, long val) {
		long mid = (val - 1) >> 1;
		if(mid >= n) {
			return 0;
		}
		if(n >= val) {
			return mid;
		}
		return n - mid;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long count = 0, temp = 0;
		while(10 * temp + 9 <= n + (n - 1)) {
			count++;
			temp = temp * 10 + 9;
		}
		long ans = 0;
		for(int i = 0; i < 9; i++) {
			if(Math.pow(10, count) * i + temp > n + (n - 1)) {
				break;
			}
			long term = (long)Math.pow(10, count) * i + temp;
			ans += form(n, term);
		}
		System.out.println(ans);
	}

}

/* package codechef; // 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		MyScanner sc = new MyScanner();
		long n = sc.nextLong();
		long maxNum = n + (n - 1);
// 		System.out.println(maxNum);
		long[] ten = new long[10];
		long z = 1L;
		long cur = 0L;
		int numNine = 0;
		for (int i = 0; i < 10; ++i){
		    cur = z * 9L + cur;
		    if (cur <= maxNum){
		        numNine = i + 1;
		    }
		    ten[i] = z;
		    z *= 10L;
		}

		cur = 0L;

		for (int i = 0 ; i < numNine; ++i){
		    cur = 9L * ten[i] + cur;
		}
		long res = 0L;
		for (int i = 0; i <= 9; ++i){
		    long k = ten[numNine] * i + cur;
		  //  System.out.println(k);
		    if (k > maxNum) continue;
		    long g = Math.min(k-1, n);
		    long t = (k + 1L) / 2L;
		    if (k % 2L != 0) t++;
		  //  System.out.println("k: " + k + " g: " + g + " t: " + t);
		    res += Math.max(0L, g - t + 1L);
		}

		System.out.println(res);

	}

	public static int GCD(int a, int b){
	    while (b > 0){
	        int tmp = b;
	        b = a % b;
	        a = tmp;
	    }
	    return a;
	}

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static 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.*;
import java.util.*;
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);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
        static class TaskE {
         int a1[]={31,28,31,30,31,30,31,31,30,31,30,31};

         public void solve(int testNumber, InputReader in, PrintWriter out) {
          long n=in.nextInt();
          long max=2*n-1;
          int d=1;long m=10;
          while(max/m!=0){d++;m*=10;}
          StringBuilder sb=new StringBuilder();
          for(int i=1;i<d;i++)sb.append('9');
          int l=1;//out.println(d);
          ArrayList<Long> al=new ArrayList<>();
          for(int i=0;i<=9;i++){
           StringBuilder sb1=new StringBuilder(sb);
           sb1.insert(0,String.valueOf(i));//out.println(sb1);
           if(Long.valueOf(sb1.toString())>max){l=i-1;break;}
           if(i==9){al.clear();}
           al.add(Long.valueOf(sb1.toString())-1);
          }
          int ans=0;
           for(int i=0;i<al.size();i++){
            long e=al.get(i)/2+1;
            ans+=Math.min(n,al.get(i))-e+1;
           }
           out.print(ans);
         }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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 = 0;
        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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class codeforces {
	static int N;
	public static void main(String[] args) {
		FS scan = new FS(System.in);

		int N = scan.nextInt();

		int cap = 0;
		long ten = 10;
		int max = 0;
		for(int i=1;i<=10;i++){
			if(ten-N-1<N)
				max++;
			else{
				ten/=10;
				break;
			}
			ten*=10;
		}

		long sol = 0;
		for(long i=0;i<10;i++){
			long val = ten*i + (ten-1);

			long lo = 1, hi = val/2, ans = 0;
			while(lo<=hi){
				long mid = lo+hi>>1;
				if(mid <= N && mid != val-mid && val-mid <= N){
					ans = mid;
					hi = mid-1;
				}else{
					lo = mid+1;
				}
			}

			if(ans>0)sol+=val/2 - ans + 1;
		}
		System.out.println(sol);
	}
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(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());}
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();

            if (n <= 4) {
                out.println((n * (n - 1)) / 2);
                return;
            }

            long max = n - 1 + n;

            String s = max + "";
            int x = countSuffix(s);
            String ss;
            String sl;
            if (s.length() - 1 > x) {
                char t[] = new char[s.length()];
                t[0] = (char) (s.charAt(0) - 1);
                for (int i = 1; i < s.length(); i++) {
                    t[i] = '9';
                }
                ss = new String(t);
                sl = ss.substring(1);
            } else {
                sl = ss = s;
            }

            long j = Long.parseLong(sl);
            long ct = 0;

            for (long i = Long.parseLong(ss); i >= j; i -= 10L) {
                ct += (i / 2);
                ct -= Math.max(0, i - n - 1);
            }

            out.println(ct);
        }

        int countSuffix(String s) {
            int len = s.length();
            int ct = 0;
            for (int i = len - 1; i >= 0; i--) {
                if (s.charAt(i) == '9')
                    ct++;
            }
            return ct;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

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

public class Main_Round452Div2_D {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
//		int[] nine = {500_000_000, 50_000_000, 5_000_000, 500_000, 50_000, 5_000, 500, 50, 5};
		int[] nine = {1_000_000_000, 100_000_000, 10_000_000, 1_000_000, 100_000, 10_000, 1_000, 100, 10};

		int n = sc.nextInt();

		for (int nn : nine) {
			if (n < nn / 2) {
				continue;
			}

			int tmp = n / nn;
			if (n % nn < nn / 2) {
				long ans = tmp * tmp;
				ans += (tmp + 1) * tmp * (n % nn);
				ans += tmp * tmp * (nn / 2 - 1 - n % nn);
				pr.println(ans);
//				pr.println((tmp) * (nn / 2 - 1) + tmp);
			} else {
				long ans = tmp * tmp;
				ans += (tmp + 1) * (tmp + 1) * (Math.min(nn - 2, n % nn) - nn / 2 + 1);
				ans += (tmp + 1) * tmp * (nn - 2 - n % nn);
				pr.println(ans);
//				pr.println((n % nn - nn / 2 + 1) * (tmp + 1) + (nn - 1 - n % nn) * (tmp) + tmp);
			}
			return;
		}

		pr.println(0);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;

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

		private boolean isPrintable(int ch) {
			return ch >= '!' && ch <= '~';
		}

		private boolean isCRLF(int ch) {
			return ch == '\n' || ch == '\r' || ch == -1;
		}

		private int nextPrintable() {
			try {
				int ch;
				while (!isPrintable(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}

				return ch;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		String next() {
			try {
				int ch = nextPrintable();
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (isPrintable(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		int nextInt() {
			try {
				// parseInt from Integer.parseInt()
				boolean negative = false;
				int res = 0;
				int limit = -Integer.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Integer.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				int multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		long nextLong() {
			try {
				// parseLong from Long.parseLong()
				boolean negative = false;
				long res = 0;
				long limit = -Long.MAX_VALUE;
				int radix = 10;

				int fc = nextPrintable();
				if (fc < '0') {
					if (fc == '-') {
						negative = true;
						limit = Long.MIN_VALUE;
					} else if (fc != '+') {
						throw new NumberFormatException();
					}
					fc = br.read();
				}
				long multmin = limit / radix;

				int ch = fc;
				do {
					int digit = ch - '0';
					if (digit < 0 || digit >= radix) {
						throw new NumberFormatException();
					}
					if (res < multmin) {
						throw new NumberFormatException();
					}
					res *= radix;
					if (res < limit + digit) {
						throw new NumberFormatException();
					}
					res -= digit;

				} while (isPrintable(ch = br.read()));

				return negative ? res : -res;
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

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

		String nextLine() {
			try {
				int ch;
				while (isCRLF(ch = br.read())) {
					if (ch == -1) {
						throw new NoSuchElementException();
					}
				}
				StringBuilder sb = new StringBuilder();
				do {
					sb.appendCodePoint(ch);
				} while (!isCRLF(ch = br.read()));

				return sb.toString();
			} catch (IOException e) {
				throw new NoSuchElementException();
			}
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new NoSuchElementException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}

//package practice.pset1;

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

public class R452D {

    static int mxx = 0;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int max = n+n-1;
        int tmp = max;
        int digits = 0;
        int nines = 0;
        while(tmp > 0){
            digits++;
            nines = nines + ((tmp%10)==9?1:0);
            tmp /= 10;
        }

        num = new int[10];
        tmp = n;
        int ii = 9;
        while(tmp > 0){
            int d = tmp%10;
            tmp /= 10;
            num[ii--] = d;
        }

        int pairs[] = new int[10];
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                for (int k = 0; k <= 9; k++) {
                    if(k+j == i)
                        pairs[i]++;
                }
            }
        }

        dp = new long[11][11][3][3];
        for (int i = 0; i < dp.length; i++)
            for (int j = 0; j < dp[i].length; j++)
                for (int k = 0; k < dp[i][j].length; k++)
                    Arrays.fill(dp[i][j][k], -1);

        if(nines == digits)
            digits++;
        {
            mxx = digits - 1;
            if(mxx == 0)
                pw.println(0);
            else
                pw.println(solve(0,0,0, 0, 0, 0)/2);
        }

        pw.flush();
        pw.close();
    }

    static int[] num;
    static long dp[][][][];
    static long solve(int idx, int nines, int less1, int less2, int p1, int p2){
        if(idx == 10)
            if(nines == mxx && p1 != 0 && p2 != 0) {
                return 1;
            }
            else
                return 0;

        if(dp[idx][nines][less1][less2] != -1)
            return dp[idx][nines][less1][less2];

        long ans = 0;
        for (int i = 0; i <= 9; i++)
            for (int j = 0; j <= 9; j++) {
                if(nines > 0){
                    if(i + j == 9 && (less1>0 || i <= num[idx]) && (less2>0 || j <= num[idx])){
                        int newLess1 = less1;
                        if(i < num[idx])
                            newLess1 = 1;
                        int newLess2 = less2;
                        if(j < num[idx])
                            newLess2 = 1;
                        ans += solve(idx+1, nines+1, newLess1, newLess2, p1*10 + i, p2*10 + j);
                    }
                }else
                {
                    if((less1>0 || i <= num[idx]) && (less2>0 || j <= num[idx])){
                        int newLess1 = less1;
                        if(i < num[idx])
                            newLess1 = 1;
                        int newLess2 = less2;
                        if(j < num[idx])
                            newLess2 = 1;
                        int newNines = 0;
                        if(i+j == 9)
                            newNines += 1;
                        ans += solve(idx+1, newNines, newLess1, newLess2, p1*10 + i, p2*10 + j);
                    }
                }
            }

        return dp[idx][nines][less1][less2] = ans;
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(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 boolean ready() throws IOException {return br.ready();}
    }
}

//package com.company;
//
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner(System.in);
        int n = sc.nextInt();
        if (n < 5){
            System.out.println(n * (n - 1) / 2);
            return;
        }
        int ll = n + n - 1;
        int di = Integer.toString(ll + 1).length();
        boolean ref = false;
        if (Integer.toString(n).length() != Integer.toString(n + 1).length()){
            ref = true;
        }
        int tt = 1;
        for (int i = 0; i < di - 1; i++) {
            tt *= 10;
        }
        long cbt = tt - 1;
        int res = ref ? -1 : 0;
        if (cbt < n){
            res += cbt / 2;
        } else {
            res += n - cbt / 2;
            System.out.println(res);
            return;
        }
        while (cbt + tt < n){
            cbt += tt;
            res += tt;
        }
        res += n - cbt;
        System.out.println(res);
    }

    static class MyScanner {
        StringTokenizer st;
        BufferedReader br;

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

        public MyScanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(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 { return Double.parseDouble(next()); }

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

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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();
            if (N <= 4) {
                out.println(N * (N - 1) / 2);
                return;
            }

            long max = N + N - 1;
            long ten = 1;
            while (ten * 10 <= max) ten *= 10L;
            long maxNines = getMaxNines(max, ten); //x99999

            String str = "" + maxNines;
            long ans = 0;
            if (str.charAt(0) == '9') {
                long half = (maxNines + 1) / 2;
                ans = Math.min(maxNines, N) - half + 1;
            } else {
                long cnt = ten * 10L - 1;
                while (cnt >= ten) {
                    if (cnt <= maxNines) {
                        ans += compute(cnt, N);
                    }
                    cnt -= ten;
                }
                if (cnt > 0) {
                    long half = (cnt + 1) / 2;
                    long tmp = Math.min(cnt, N) - half;
                    ans += tmp;
                }
            }

            out.println(ans);
        }

        private long compute(long cnt, long n) {//39999
            long half = (cnt + 1) / 2;
            return n - half + 1;
        }

        private long getMaxNines(long max, long ten) {
            if ((max + 1) % ten == 0) return max; //x9999999

            return (max / ten) * ten - 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());
        }

    }
}

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 N = Integer.parseInt(n);
        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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        int countSuffix(String s) {
            int len = s.length();
            int ct = 0;
            for (int i = len - 1; i >= 0; i--) {
                if (s.charAt(i) == '9')
                    ct++;
            }
            return ct;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();

            if (n <= 4) {
                out.println((n * (n - 1)) / 2);
                return;
            }

            String max = (n - 1 + n) + "";
            int len = max.length();

            long lo, hi, diff;
            if (countSuffix(max) == len) {
                lo = hi = Long.parseLong(max);
                diff = 1L;
            } else {
                StringBuilder nine = new StringBuilder();
                StringBuilder zero = new StringBuilder();
                for (int i = 1; i < len; i++) {
                    nine.append('9');
                    zero.append('0');
                }

                diff = Long.parseLong(1 + zero.toString());
                lo = Long.parseLong(nine.toString());
                hi = Long.parseLong((max.charAt(0) - '1') + nine.toString());
            }

            long ct = 0;
            for (long i = hi; i >= lo; i -= diff) {
                ct += (i / 2);
                ct -= Math.max(0, i - n - 1);
            }
            out.println(ct);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

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

public class Main {
	public static void main(String args[]) {new Main().run();}

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	void work() {
		long n=in.nextLong();
		if(n<=4) {
			out.println(n*(n-1)/2);
			return;
		}
		long sum=find(2*n);
		long ret=0;
		if((sum+"").charAt(0)!='9') {//2000  3999  2999 1999
			for(int i=1;i<=9;i++) {
				if(i>(sum+"").charAt(0)-'0')break;
				long num=Long.valueOf(i+""+(sum+"").substring(1));
				long v=(sum+1)/2;
				if(v<n)ret+=sum/2;
				else {
					ret=n-v+1;
				}
			}
		}else {
			long v=(sum+1)/2;//999
			ret=n-v+1;
			if(sum==n)ret--;
		}
		out.println(ret);
	}
	private long find(long n) {
		int len=(n+"").length()-1;
		int c=(n+"").charAt(0)-'1';
		StringBuilder sb=new StringBuilder();
		if(c!=0) {
			sb.append(c);
		}
		for(int i=0;i<len;i++) sb.append(9);
		return Long.valueOf(sb.toString());
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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

/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         if(N <= 4)
         {
            System.out.println(0);
            return;
         }
         String lol = "9";
         while(true)
         {
            long val = Long.parseLong(lol);
            if(2*N-1 < val)
               break;
            lol += 9;
         }
         int max9 = lol.length()-1;
         lol = lol.substring(1);
         long res = 0L;
         long check = Long.parseLong(lol);
         while(2*N-1 >= check)
         {
            long min = Math.max(1, check-N);
   			long max = check/2;
   			res += max-min+1;
   			check += Long.parseLong(lol)+1;
         }
         System.out.println(res);
      }
   }

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        private int pow10(int n) {
            int res = 1;
            for (int i = 0; i < n; i++) {
                res *= 10;
            }
            return res;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int MAX = 1_000_000_000;
            int lim = 2 * n;
            long ans = 0;
            if (n < 5) {
                out.println(n);
                return;
            }
            for (int i = 9; i > 0; i--) {
                int pow = pow10(i);
                if (pow > lim) continue;
                for (int d = 0; d < 9; d++) {
                    long num = (long) pow * (d + 1) - 1;
                    if ((num + 1) / 2 <= n) {
                        ans += Math.min(n, num - 1) - (num + 1) / 2 + 1;
                    } else
                        break;
                }
                out.println(ans);
                return;
            }
            out.println(0);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
            //h.pn(arr[i]);;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1;i--){
        	if(arr[i]==n) {
        		h.pn(arr[i]/2);
        		flag=true;
        		break;
        	}
        	else if(arr[i]-n<n){
        		//h.pn(arr[i]);;
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                        	x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                h.pn(ans);
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn(0);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

        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.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{

    public static void main(String[] args) {

    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);

    	int tt = 1;
    	while(tt-->0) {

    		int n = fs.nextInt();

    		if(n<5) {
    			out.println(n*(n-1)/2);
    			out.flush();
    			return;
    		}

    		int t = n;
    		long num = 1;
    		while(t>0) {
    			num *= 10;
    			t /= 10;
    		}

    		out.println(num);

    		if(n>=(num/2)) {
    			num /= 2;
    			out.println(num - 1 - max(2*num - 1 - n, 1) + 1);
    		}
    		else {
    			long ans = 0;
    			for(int i=0;i<9;i++) {
    				long x = num/10*i + (num/10)-1;
    				long s = max(1, x - n);
    				if(s<=n) ans += (x-2*s+1)/2;
    			}
    			out.println(ans);
    		}

    	}

    	out.close();

    }

    static long min(long a, long b) {
    	if(a<b) return a;
    	return b;
    }

    static long max(long a, long b) {
    	if(a>b) return a;
    	return b;
    }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");

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

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

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

    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}

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

    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }

}

import java.util.*;

/**
 * Created by evgeniyradchenko on 11/28/17.
 */
public class Main {

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

        int n = s.nextInt();

        long cur = 0;

        while (cur * 10 + 9 <= n + (n - 1)) {
            cur = cur * 10 + 9;
        }

        if (cur == 0) {
            System.out.println(n / 2);

            return;
        }

        if (cur > n) {
            long ans = (2 * n - cur + 1) / 2;
            long add = cur + 1;

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }
            System.out.println(ans);
        } else {
            long add = cur + 1;
            long ans = (cur - 1) / 2;

            while (cur + add <= n) {
                cur += add;
                ans += (cur - 1) / 2;
            }

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }

            System.out.println(ans);
        }
    }

}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.valueOf(st.nextToken());
		int sum = n + n - 1;
		if (checkAllNine(sum) || sum == 9) {
			System.out.println(1);
			return;
		}
		if (sum < 9) {
			System.out.println(n * (n - 1) / 2);
			return;
		}

		// System.out.println("sum==" + sum);

		int ans = 0;

		// len >= 2
		int len = cntLen(sum);
		int left = sum / (int) (Math.pow(10, len - 1));

		int firstNum = getFirst(sum, len, left);

		len = cntLen(firstNum);
		int loop = (int) (Math.pow(10, len - 1));
		left = firstNum / (int) (Math.pow(10, len - 1));
		if (firstNum < 10)
			left = 0;

		//System.out.println("left==" + left);
		while (left >= 0) {
			//System.out.println("firstNum==" + firstNum);
			if (firstNum > n)
			{
				int half = firstNum / 2 + 1;
				ans += (n - half + 1);
			}

			else
				ans += firstNum / 2;
			//System.out.println("ans==" + ans);
			firstNum -= loop;
			left--;
		}
		System.out.println(ans);
	}

	public static int getFirst(int sum, int len, int left) {
		int firstNum = -1;
		int rightSum = 0;

		for (int i = 0; i < len - 1; i++) {
			rightSum *= 10;
			rightSum += 9;
		}
		if (sum % (int) (Math.pow(10, len - 1)) != rightSum)
			left--;
		// System.out.println("rightSum==" + rightSum);
		firstNum = left * (int) (Math.pow(10, len - 1)) + rightSum;
		//System.out.println("firstNum==" + firstNum);System.out.println();
		return firstNum;
	}

	public static int cntLen(int n) {
		int i = 0;
		while (n != 0) {
			i++;
			n /= 10;
		}
		return i;
	}

	public static boolean checkAllNine(int n) {
		while (n != 0) {
			if (n % 9 != 0)
				return false;
			n /= 10;
		}
		return true;
	}

	public static void printArray(int a[], int n) {
		for (int i = 0; i < n; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

}

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

import static java.lang.Math.*;

public class Main implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Main(),"Main",1<<26).start();
	}
    long findAns(int n) {
        long ans = 1;
        for(long i = 0; i < n; ++i)
            ans *= 10;
        return ans;
    }
    long findValue(int n) {
        long ans = 0;
        long val = 1;
        for(int i = 0; i < n; ++i) {
            ans += 4 * val;
            val *= 10;
        }
        return ans;
    }
	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

        int n = sc.nextInt();
        if(n <= 4) {
            w.print("0");
            w.close();
            return;
        }
        long ans = 0;
        int temp = n;
        int digits = 0;
        while(temp != 0) {
            digits++;
            temp /= 10;
        }

        char s[] = Integer.toString(n).toCharArray();

        if(s[0] >= '5') {
            ans = (long)(s[0] - '5') * findAns(digits - 1);
            ans += (long)(n - ((s[0] - '0') * findAns(digits - 1)) + 1);
            int flag = 0;
            for(int i = 0; i < s.length; ++i) {
                if(s[i] != '9') {
                    flag = 1;
                    break;
                }
            }
            if(flag == 0)
                ans--;
        }
        else {
            long m = s[0] - '0';
            ans = m * (m - 1) / 2 * findAns(digits - 1);
            ans += findAns(digits - 1) / 2 * m;
            long left = (long)(n - ((s[0] - '0') * findAns(digits - 1)) + 1);
            ans += (left * m);
            ans += (left - (findValue(digits - 1) + 1));
            ans -= m;
            int flag = 0;
            for(int i = 1; i < s.length; ++i) {
                if(s[i] != '9')
                    flag = 1;
            }
            if(flag == 0)
                ans--;
        }
        w.print(ans);
		w.close();
	}
}

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();
		}
		long result;
		if (ninesCountMax == 0)
		{
			result = n * (n - 1) / 2;
		}
		else
		{
            int mod = mod(ninesCountMax);
            result = 0;
            for (int index = mod - 1; index <= n + n - 1; index+=mod)
            {
                int largestMax = Math.min(index - 1, n);
                int largestMin = Math.max(index / 2 + 1, index - (n - 1));
                result +=  largestMax + 1 - largestMin;
            }
		}
		out.println(result);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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.readInt();
            if (n < 5) {
                out.println(n / 2);
                return;
            }

            long max = maxNine(n);
            long ans = (max - 1) / 2;
            if (max > n) {
                ans -= max - n - 1;
            }

            long ten = (long) Math.pow(10L, (max + "").length());
            for (int i = 1; ten * i + max < 2 * n; i++) {
                long v = ten * i + max;
                ans += (v - 1) / 2;
                ans -= v - n - 1;
            }
            out.println(ans);

        }

        long maxNine(int n) {
            long ans = n * 2 - 1;

            boolean valid = true;
            for (long i = ans; i > 0; i /= 10) {
                if (i % 10 != 9) {
                    valid = false;
                    break;
                }
            }
            if (valid) return ans;
            long res = 0;
            for (int i = 0; i < (ans + "").length() - 1; i++) {
                res = res * 10 + 9;
            }
            return res;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sanket Makani
 */
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 sc, PrintWriter w) {

            long n = sc.nextLong();
            long ans = 0;

            long max = n + (n - 1);

            if (n == 5) {
                w.println("1");
                return;
            }

            if (n <= 4) {
                w.println(n * (n - 1) / 2);
                return;
            }
            if (check(max)) {
                w.println("1");
                return;
            }

            String str = "" + max;
            int digits = str.length();
            int first = str.charAt(0) - '0';

            long add = (long) Math.pow(10, digits - 1);

            long curr = 0;

            for (int i = 0; i < digits - 1; i++) {
                curr *= 10;
                curr += 9;
            }

            for (int i = 0; i < first; i++) {
                long f = (curr + 1) / 2;
                long s = curr - f;

                ans += Math.min(n - f + 1, s);
                curr += add;
            }
            w.println(ans);
        }

        private boolean check(long max) {
            HashSet<Long> set = new HashSet<Long>();
            while (max > 0) {
                set.add(max % 10);
                max /= 10;
            }

            if (set.size() == 1 && set.contains(9L))
                return true;
            return false;

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class ShovelSale {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        String s = sc.next();
        int N = Integer.parseInt(s);
        int S = 2 * N - 1;
        int max = 0;
        int x = 0;
        int sum = 0;
        while ((10 * x + 9) <= S) {
            max++;
            x = 10 * x + 9;
        }
        sum = x;
        x = 1;
        for (int i = 0; i < max; i++) {
            x *= 10;
        }
        while (sum + x <= S) {
            sum += x;
        }

        int ans = 0;
        if (max == 0) {
            ans = N / 2;
        }
        else {
            ans = 0;
            while (sum >= x) {
                ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
                sum -= x;
            }
            ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
        }
        out.println(ans);
        out.close();
    }

    static class FastScanner {
        private int BS = 1<<16;
        private char NC = (char)0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            }
            catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar(){
            while(bId==size) {
                try {
                    size = in.read(buf);
                }catch(Exception e) {
                    return NC;
                }
                if(size==-1)return NC;
                bId=0;
            }
            return (char)buf[bId++];
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt=1;
            boolean neg = false;
            if(c==NC)c=getChar();
            for(;(c<'0' || c>'9'); c = getChar()) {
                if(c=='-')neg=true;
            }
            long res = 0;
            for(; c>='0' && c <='9'; c=getChar()) {
                res = (res<<3)+(res<<1)+c-'0';
                cnt*=10;
            }
            return neg?-res:res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c!='.' ? cur:cur+nextLong()/cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c>32) {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c!='\n') {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if(c>32)return true;
            while(true) {
                c=getChar();
                if(c==NC)return false;
                else if(c>32)return true;
            }
        }
    }
}

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

public class ProblemH
{

    static int mod = (int) (1e9+7);
    static InputReader in;
    static PrintWriter out;

    static long get(long max, long n){

        long x = max - 1;
        if(x % 2 != 0) return 0;
        x /= 2;
        if(!(x + 1 >= 1 && x + 1<= n) || !(x >= 1 && x <= n)) return 0;
        long l = 1;
        long r = x;
        long idx = x;
        while(r - l >= 0){
            long m = (r + l) >> 1;
            if(max - m >= 1 && max - m <= n){
                idx = m;
                r = m - 1;
            }
            else l = m + 1;
        }

        return x - idx + 1;
    }

    public static void main(String[] args) throws FileNotFoundException
    {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        int n = in.nextInt();

        long m = n + n - 1;
        int c = 0;
        long max = 0;

        while(true){
            c = c * 10 + 9;
            if(c <= m) max = c;
            else break;
        }
        long l = 0;
        m = max;
        while(m > 0){
            m /= 10;
            l++;
        }
        l = pow(10, l);
        long cnt = 0;

        for(long i = 0; i <= 9; i++){
//            debug(get(max + i * l, n), max + i * l);
            cnt += get(max + i * l, n);
        }
        if(n < 5){
            cnt = (n * (n - 1)) / 2;
        }
        out.println(cnt);
        out.close();
    }

    static void debug(Object... o)
    {
            System.out.println(Arrays.deepToString(o));
    }

    static class Pair implements Comparable<Pair>
    {

        int x,y;

        Pair (int x, int y)
        {
		this.x = x;
                this.y = y;
	}

	public int compareTo(Pair o) {
                return Integer.compare(this.y,o.y);
	}

        public boolean equals(Object o)
        {
            if (o instanceof Pair)
            {
                Pair p = (Pair)o;
                return p.x == x && p.y==y;
            }
            return false;
        }

        @Override
        public String toString()
        {
            return x + " "+ y;
        }

        public int hashCode()
        {
            return new Long(x).hashCode() * 31 + new Long(y).hashCode();
        }

    }

    static long add(long a,long b){
        long x=(a+b);
        while(x>=mod) x-=mod;
        return x;
    }

    static long sub(long a,long b){
        long x=(a-b);
        while(x<0) x+=mod;
        return x;
    }

    static long mul(long a,long b){
        long x=(a*b);
        while(x>=mod) x-=mod;
        return x;
    }

    static String rev(String s){
        StringBuilder sb=new StringBuilder(s);
        sb.reverse();
        return sb.toString();
    }

    static long gcd(long x,long y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static int gcd(int x,int y)
    {
        if(y==0)
                return x;
        else
                return gcd(y,x%y);
    }

    static long pow(long n,long p,long m)
    {
         long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            if(result>=m)
            result%=m;
            p >>=1;
            n*=n;
            if(n>=m)
            n%=m;
        }
        return result;
    }

    static long pow(long n,long p)
    {
        long  result = 1;
          if(p==0)
            return 1;

        while(p!=0)
        {
            if(p%2==1)
                result *= n;
            p >>=1;
            n*=n;
        }
        return result;
    }

    static class InputReader
    {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
                this.stream = stream;
        }

        public int snext()
        {
                if (snumChars == -1)
                        throw new InputMismatchException();
                if (curChar >= snumChars)
                {
                        curChar = 0;
                        try
                        {
                                snumChars = stream.read(buf);
                        } catch (IOException e)
                        {
                                throw new InputMismatchException();
                        }
                        if (snumChars <= 0)
                                return -1;
                }
                return buf[curChar++];
        }

        public int nextInt()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                int res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public long nextLong()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                int sgn = 1;
                if (c == '-')
                {
                        sgn = -1;
                        c = snext();
                }
                long res = 0;
                do
                {
                        if (c < '0' || c > '9')
                                throw new InputMismatchException();
                        res *= 10;
                        res += c - '0';
                        c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
        }

        public int[] nextIntArray(int n)
        {
                int a[] = new int[n];
                for (int i = 0; i < n; i++)
                {
                        a[i] = nextInt();
                }
                return a;
        }

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

        public String readString()
        {
                int c = snext();
                while (isSpaceChar(c))
                {
                        c = snext();
                }
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
        }

        public String nextLine()
        {
                int c = snext();
                while (isSpaceChar(c))
                        c = snext();
                StringBuilder res = new StringBuilder();
                do
                {
                        res.appendCodePoint(c);
                        c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
                if (filter != null)
                        return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c)
        {
                return c == '\n' || c == '\r' || c == -1;
        }

        public interface SpaceCharFilter
        {
                public boolean isSpaceChar(int ch);
        }

    }
}

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

public class D899 {
    private static int[][][][][][][] dp;

    private static char[] limit;
    private static int maxNum9;

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

        int num = Integer.parseInt(br.readLine());
        if (num <= 4) {
            System.out.println((num * (num - 1)) / 2);
            return;
        }

        String max9 = "" + (num + num - 1);
        maxNum9 = max9.length();
        boolean flag = true;
        for (char e : max9.toCharArray()) {
            if (e != '9') {
                flag = false;
                break;
            }
        }
        if (flag) {
            System.out.println(1);
            return;
        }

        maxNum9--;
        limit = ("" + (num + 1)).toCharArray();
        for (int i = 0, j = limit.length - 1; i < j; i++, j--) {
            char temp = limit[i];
            limit[i] = limit[j];
            limit[j] = temp;
        }
        dp = new int[limit.length + 1][maxNum9 + 1][2][2][2][2][2];
        for (int i = 0; i <= limit.length; i++) {
            for (int j = 0; j <= maxNum9; j++) {
                for (int k = 0; k < 2; k++) {
                    for (int l = 0; l < 2; l++) {
                        for (int m = 0; m < 2; m++) {
                            for (int o = 0; o < 2; o++) {
                                dp[i][j][k][l][m][o][0] = -1;
                                dp[i][j][k][l][m][o][1] = -1;
                            }
                        }
                    }
                }
            }
        }
        System.out.println(count(0, 0, 1,
                0, 0, 1, 1) / 2);
    }

    private static int count(int index, int num9, int hasAll9,
                             int isASmaller, int isBSmaller,
                             int isAZero, int isBZero) {
        if (index == limit.length) {
            if (num9 != maxNum9 || isASmaller == 0 || isBSmaller == 0
                    || isAZero == 1 || isBZero == 1) {
                return 0;
            }
            return 1;
        }

        if (dp[index][num9][hasAll9][isASmaller][isBSmaller][isAZero][isBZero] > -1) {
            return dp[index][num9][hasAll9][isASmaller][isBSmaller][isAZero][isBZero];
        }

        int count = 0;
        boolean isAStillSmaller;
        boolean isBStillSmaller;
        int nextHasAll9;
        for (int i = 0; i < 10; i++) {
            if (i == limit[index] - '0') {
                isAStillSmaller = isASmaller == 1;
            } else {
                isAStillSmaller = i < (limit[index] - '0');
            }
            for (int j = 0; j < 10; j++) {
                if (j == limit[index] - '0') {
                    isBStillSmaller = isBSmaller == 1;
                } else {
                    isBStillSmaller = j < (limit[index] - '0');
                }
                int k = i + j;
                int nextNum9 = num9;
                if (k == 9 && hasAll9 == 1) {
                    nextNum9++;
                    nextHasAll9 = 1;
                } else {
                    nextHasAll9 = 0;
                }
                count += count(index + 1, nextNum9, nextHasAll9,
                        isAStillSmaller ? 1 : 0, isBStillSmaller ? 1 : 0,
                        isAZero == 0 ? isAZero : (i > 0 ? 0 : 1),
                        isBZero == 0 ? isBZero : (j > 0 ? 0 : 1)
                );
            }
        }
        dp[index][num9][hasAll9][isASmaller][isBSmaller][isAZero][isBZero] = count;
        return count;
    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.*;
import java.util.InputMismatchException;
public class solution{
	public static int numofdigits(int n)
	{
		int ans = 0;
		while(n!=0)
		{
			ans++;
			n/=10;
		}
		return ans;
	}
	public static boolean check(int n)
	{
		while(n!=0)
		{
			if(n%10!=9)
			{
				return false;
			}
			n = n/10;
		}
		return true;
	}
	public static int getMax(int n,boolean flag)
	{
		if(n/10==0)
		{
			if(flag)
			return n-1;
			else
			return n;
		}
		if(n%10!=9)
		{
			flag = true;
		}
		return getMax(n/10,flag)*10+9;
	}
	public static void main(String args[]) throws Exception
		{
			InputReader sc = new InputReader(System.in);
			PrintWriter out = new PrintWriter(System.out);
			int n = sc.nextInt();
			int max = 2*n-1;
			if(max<9)
			{
				out.println((n*(n-1))/2);
			}
			else if(check(max))
			{
				int min = max-n;
				out.println((n-min+1)/2);
			}
			else
			{
				long ans = 0;
				int num = getMax(max,false);
				if(check(num))
				{
					int min = num-n;
					out.println((n-min+1)/2);
				}
				else
				{
					int digits = numofdigits(num);
					int diff = (int)Math.pow(10,digits-1);
					while(numofdigits(num)!=digits-1)
					{
						if(num>=n)
						{
							int min = num-n;
							ans+=(n-min+1)/2;
						}
						else
						{
							ans+=(num-1)/2;
						}
						num-=diff;
					}
					if(num>=n)
					{
						int min = num-n;
						ans+=(n-min+1)/2;
					}
					else
					{
						ans+=(num-1)/2;
					}
					out.println(ans);
				}
			}
			out.close();
		}
	static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int[] readCharCount() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int[] map = new int[256];
            do {
                int val = c ;
                map[val]++;
                c = snext();
            } while (!isSpaceChar(c));
            return map;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class Prac{
    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        public InputReader(InputStream st) {
            this.stream = st;
        }
        public int read() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
        public int ni() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public long nl() {
            int c = read();
            while (isSpaceChar(c)) {
            c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public int[] nia(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public String rs() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                    c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
    }
    public static class Key {

        private final int x;
        private final int y;

        public Key(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof Key)) return false;
            Key key = (Key) o;
            return x == key.x && y == key.y;
        }

        @Override
        public int hashCode() {
            int result = x;
            result = 31 * result + y;
            return result;
        }

    }
    static class Pair{
        int x,y;
        public Pair(int x,int y){
            this.y=y;
            this.x=x;
        }
    }

    static PrintWriter w = new PrintWriter(System.out);
    static long mod=998244353L,mod1=1000000007;

    static boolean count(int i){
        while(i>0){
            if(i%10!=9)return false;
            i/=10;
        }
        return true;
    }
    static int digit(int n){
        int c=0;
        while(n>0){
            c++;
            n/=10;
        }
        return c;
    }

    public static void main(String [] args){
        InputReader sc=new InputReader(System.in);
        int n=sc.ni();
        int num=2*n-1;
        if(count(num))w.println(1);

        else if(n<=4)w.println((n*(n-1))/2);
        else{
            int times=digit(num)-1;

            int x=0;
            while(times-->0){
                x=x*10+9;
            }
            int ans=0;
            while(x<=num){
                if(x<=n)ans+=x/2;
                else ans+=(n-x/2);
                x=x*2+1;
            }
            w.println(ans);
        }
        w.close();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class CFD {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] dx = {0, -1, 0, 1};
    int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        long n = nextLong();
        long max = n + n - 1;
        long nine = 9;
        while (nine <= max) {
            nine = 10 * nine + 9;
        }

        nine = nine / 10;
        int cnt = Long.toString(nine).toCharArray().length;
        char[] arr = Long.toString(n).toCharArray();
        long res = 0;
        if (arr.length == cnt) {
            if (nine <= n) {
                out(nine / 2);
            }
            else if (nine < 2 * n) {
                out((2 * n - nine + 1) / 2);
            }
            else {
                out(0);
            }
            return;
        }

        long base = 1;
        for (int i = 0; i < cnt; i++) {
            base = 10 * base;
        }

        for (int i = 0; i <= arr[0] - '0'; i++) {
            long sum = i * base + nine;

            if (sum <= n) {
                res += sum / 2;
            }
            else if (sum < 2 * n) {
                res += (2 * n - sum + 1) / 2;
            }
        }

        out(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFD() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFD();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*(long)Math.pow(10,i-1))+9;
            arr[i]=sum;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1;i--){
            if(arr[i]-n<=n){
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                        	x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                h.pn(ans);
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn(0);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

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

public class CODEFORCES
{
	@SuppressWarnings("rawtypes")
	static InputReader in;
	static PrintWriter out;

	static int digit = 0, n = 0;
	static boolean u = true;
	static long ans = 0;

	static void check()
	{
		int p = 2 * n - 1;
		while (p > 0)
		{
			if (p % 10 != 9)
				u = false;
			p /= 10;
			digit++;
		}
		if (!u)
			digit--;
		long t = 1;
		long make = 0;
		for (int i = 0; i < digit; i++)
		{
			make += t * 9;
			t *= 10;
		}
		while (make <= 2 * n - 1)
		{
			ans += (make - 1) >> 1;
			if (make > n)
				ans -= make - n - 1;
			make += t;
		}
		// ans += (make - 1) >> 1;
		// ans -= make - n - 1;
		out.println(ans);
	}

	static void solve()
	{
		n = in.ni();
		check();
	}

	@SuppressWarnings("rawtypes")
	static void soln()
	{
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args)
	{
		new Thread(null, new Runnable()
		{
			public void run()
			{
				try
				{
					soln();
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	// To Get Input
	// Some Buffer Methods
	static class InputReader<SpaceCharFilter>
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				} catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = ni();
			}
			return a;
		}

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

		public String readString()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}

	}
}

/**
 * @author derrick20
 */

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

public class ShovelSale {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

//        for (int N = 1; N <= 100; N++) {
        String s = sc.next();
        int N = Integer.parseInt(s);
        int S = 2 * N - 1;
        int max = 0;
        int x = 0;
        int sum = 0;
        while ((10 * x + 9) <= S) {
            max++;
            x = 10 * x + 9;
        }
        sum = x;
        x = 1;
        for (int i = 0; i < max; i++) {
            x *= 10;
        }
        while (sum + x <= S) {
            sum += x;
        }

//            int bruteans = brute(N, max);
//            System.out.println("Brute for " + N + " and max of " + max + ": " + bruteans);

        int ans = 0;
        if (max == 0) {
            ans = N * (N - 1) / 2;
        }
        else {
            ans = 0;
            while (sum >= x) {
                ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
                sum -= x;
            }
            ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
        }
//            System.out.println(ans);
//            if (bruteans != ans) {
//                System.exit(0);
//            }
//        }
        out.println(ans);
        out.close();
    }

    static int brute(int N, int max) {
        int res = 0;
        for (int i = 1; i <= N; i++) {
            for (int j = i + 1; j <= N; j++) {
                int sum = i + j;
                int ct = 0;
                while (sum > 0) {
                    if (sum % 10 == 9) {
                        ct++;
                    }
                    else {
                        break;
                    }
                    sum /= 10;
                }
                if (ct == max) {
//                    System.out.println(i + j);
                    res++;
                }
            }
        }
        return res;
    }

    static class FastScanner {
        private int BS = 1 << 16;
        private char NC = (char) 0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt = 1;
            boolean neg = false;
            if (c == NC) c = getChar();
            for (; (c < '0' || c > '9'); c = getChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = getChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                cnt *= 10;
            }
            return neg ? -res : res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c != '.' ? cur : cur + nextLong() / cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c > 32) {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c != '\n') {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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.readInt();
            if (n < 5) {
                out.println(0);
                return;
            }

            long max = maxNine(n);
            long ans = (max - 1) / 2;
            if (max > n) {
                ans -= max - n - 1;
            }

            long ten = (long) Math.pow(10L, (max + "").length());
            for (int i = 1; ten * i + max < 2 * n; i++) {
                long v = ten * i + max;
                ans += (v - 1) / 2;
                if (v > n) ans -= v - n - 1;
            }
            out.println(ans);

        }

        long maxNine(int n) {
            long t = n * 2 - 1, ans = 0;
            for (long i = 9; i <= t; i = i * 10 + 9) {
                ans = i;
            }
            return ans;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class codeforces {
	static int N;
	public static void main(String[] args) {
		FS scan = new FS(System.in);

		int N = scan.nextInt();
		if(N <= 4){
			System.out.println(0);
			return;
		}
		int cap = 0;
		long ten = 10;
		int max = 0;
		for(int i=1;i<=10;i++){
			if(ten-N-1<N)
				max++;
			else{
				ten/=10;
				break;
			}
			ten*=10;
		}

		long sol = 0;
		for(long i=0;i<10;i++){
			long val = ten*i + (ten-1);

			long lo = 1, hi = val/2, ans = 0;
			while(lo<=hi){
				long mid = lo+hi>>1;
				if(mid <= N && mid != val-mid && val-mid <= N){
					ans = mid;
					hi = mid-1;
				}else{
					lo = mid+1;
				}
			}

			if(ans>0)sol+=val/2 - ans + 1;
		}
		System.out.println(sol);
	}
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(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());}
	}

}

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

public class D452Div2
{
    public static void main(String[] args)
    {
        new D452Div2(System.in, System.out);
    }

    private static class Solver implements Runnable
    {
        int n;
        InputReader in;
        PrintWriter out;

        void solve() throws IOException
        {
            n = in.nextInt();

            long test = 5;

            while (test <= n)
            {
                test *= 10;

                if (test > n)
                {
                    test /= 10;

                    break;
                }
            }

            long low = test;
            long high = n;
            long ans = test;

            while (low <= high)
            {
                long mid = low + high >> 1;

                if (mid <= n)
                {
                    if (mid + 1 > n)
                    {
                        ans = mid;

                        break;
                    }

                    low = mid + 1;
                }
                else
                    high = mid - 1;
            }

            ans -= test;
            ans++;

            long temp = 2 * test - 1;

//            System.out.println("test : " + test + ", temp : " + temp);

            if (temp <= n)
                ans--;

            if (3 * test <= n)
                ans++;

            out.println(ans);
        }

        Solver(InputReader in, PrintWriter out)
        {
            this.in = in;
            this.out = out;
        }

        @Override
        public void run()
        {
            try
            {
                solve();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

    }

    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        int nextInt()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        InputReader(InputStream stream)
        {
            this.stream = stream;
        }

    }

    private D452Div2(InputStream inputStream, OutputStream outputStream)
    {
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 29);

        try
        {
            thread.start();
            thread.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        in.close();
        out.flush();
        out.close();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class codeforces {
	static int N;
	public static void main(String[] args) {
		FS scan = new FS(System.in);

		int N = scan.nextInt();

		int cap = 0;
		long ten = 10;
		int max = 0;
		for(int i=1;i<=10;i++){
			if(ten-N-1<N)
				max++;
			else{
				ten/=10;
				break;
			}
			ten*=10;
		}

		long sol = 0;
		for(long i=0;i<10;i++){
			long val = ten*i + (ten-1);

			long lo = 1, hi = val/2, ans = 0;
			while(lo<=hi){
				long mid = lo+hi>>1;
				if(mid <= N && mid != val-mid && val-mid <= N){
					ans = mid;
					hi = mid-1;
				}else{
					lo = mid+1;
				}
			}

			if(ans>0)sol+=val/2 - ans + 1;
		}
		System.out.println(sol);
	}
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(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());}
	}

}

import java.util.ArrayList;
import java.util.Scanner;

public class CodeForces {
	public static void main(String args[]) throws Exception{
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int count = (n / 5 + "").length();

		int val = 0;
		for(int i = 0; i < count; i++){
			val += 9 * (int) Math.pow(10, i);
		}
		long step = (int) Math.pow(10, count);
		long ans = 0;
		for(int i = 0; i <= 9; i++){
			long look = step * i + val;
			if(n >= look){
				ans += look / 2;
			}else if(n > look / 2){
				look = look / 2;
				ans += n - look;
			}
		}
		System.out.println(ans);
	}
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.valueOf(st.nextToken());
		int sum = n + n - 1;
		if (checkAllNine(sum) || sum == 9) {
			System.out.println(1);
			return;
		}
		if (sum < 9) {
			System.out.println(n * (n - 1) / 2);
			return;
		}

		// System.out.println("sum==" + sum);

		int ans = 0;

		// len >= 2
		int len = cntLen(sum);
		int left = sum / (int) (Math.pow(10, len - 1));

		int firstNum = getFirst(sum, len, left);

		len = cntLen(firstNum);
		int loop = (int) (Math.pow(10, len - 1));
		left = firstNum / (int) (Math.pow(10, len - 1));
		if (firstNum < 10)
			left = 0;

		//System.out.println("left==" + left);
		while (left >= 0) {
			//System.out.println("firstNum==" + firstNum);
			if (firstNum > n)
			{
				int half = firstNum / 2 + 1;
				ans += (n - half + 1);
			}

			else
				ans += firstNum / 2;
			//System.out.println("ans==" + ans);
			firstNum -= loop;
			left--;
		}
		System.out.println(ans);
	}

	public static int getFirst(int sum, int len, int left) {
		int firstNum = -1;
		int rightSum = 0;

		for (int i = 0; i < len - 1; i++) {
			rightSum *= 10;
			rightSum += 9;
		}
		if (sum % (int) (Math.pow(10, len - 1)) != rightSum)
			left--;
		// System.out.println("rightSum==" + rightSum);
		firstNum = left * (int) (Math.pow(10, len - 1)) + rightSum;
		//System.out.println("firstNum==" + firstNum);System.out.println();
		return firstNum;
	}

	public static int cntLen(int n) {
		int i = 0;
		while (n != 0) {
			i++;
			n /= 10;
		}
		return i;
	}

	public static boolean checkAllNine(int n) {
		while (n != 0) {
			if (n % 9 != 0)
				return false;
			n /= 10;
		}
		return true;
	}

	public static void printArray(int a[], int n) {
		for (int i = 0; i < n; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

}

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;

    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 = 0;
        for(int i = 1; i <= n.length() ; i++){
            int v = cal(n.length() - 1, i, 0, 0, n);

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

    static int cal(int index, int total,  int a, int b, String n) {
        if (index == -1) {
            if (a <= 1 && b <= 1) {
                return 1;
            }
            return 0;
        }
        int result = 0;
        int cur = n.charAt(index) - '0';
        if (total > 0) {

            for (int i = 0; i < 9; i++) {
                int left = 9 - i;
                //System.out.println(i + " " + left);
                result += cal(index - 1, total - 1, i > cur ? 2 : (i < cur ? 1 : a), left > cur ? 2 : (left < cur ? 1 : b), n);
            }
        } else {
            for (int i = 0; i < 9; i++) {
                for (int j = 0; j < 9; j++) {
                    result += cal(index - 1, total, i > cur ? 2 : (i < cur ? 1 : a), j > cur ? 2 : (j < cur ? 1 : b), n);
                }
            }
        }
        return 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();
            }
        }
    }
}

//package round452;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		long t = 2*n;
		if(t < 9){
			out.println(n*(n+1)/2);
			return;
		}
		long d = 1;
		for(;t/d > 0;d*=10);
		// sum <= 8
		long ideal = t / (d/10) * (d/10) - 1;
		long ret = 0;
		while(ideal > 0){
			long inf = ideal / 2 + 1;
			long sup = Math.min(ideal-1, n);
			if(inf <= sup)ret += sup-inf+1;
			ideal -= d/10;
		}
		out.println(ret);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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.readInt();
            if (n < 5) {
                out.println(n / 2);
                return;
            }

            long max = maxNine(n);
            long ans = (max - 1) / 2;
            if (max > n) {
                ans -= max - n - 1;
            }

            long ten = (long) Math.pow(10L, (max + "").length());
            for (int i = 1; ten * i + max < 2 * n; i++) {
                long v = ten * i + max;
                ans += (v - 1) / 2;
                if (v > n) ans -= v - n - 1;
            }
            out.println(ans);

        }

        long maxNine(int n) {
            long t = n * 2 - 1, ans = 0;
            for (long i = 9; i <= t; i = i * 10 + 9) {
                ans = i;
            }
            return ans;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class _v17 {

    static boolean allNine(int n){

        while (n!=0){
            if(n%10 != 9){
                return false;
            }
            n = n/10;
        }

        return true;
    }
    public static void main(String args[]){

        PrintWriter out = new PrintWriter(System.out);
        Reader in = new Reader();
        int n = in.nextInt();
        int len = String.valueOf(n).length();
        int limit = 5*(int)Math.pow(10,len-1);
        if(n<5){
            out.println((n*(n-1))/2);
        }
        else if(n>=limit){
                 if(allNine(n)){
                     out.println(n-limit);
                 }
                 else{
                     out.println(n-limit+1);
                 }
        }
        else{
            int res = 0;
            int num = (int)Math.pow(10,len-1);

            for(int i=1;i<10;i++){
                    int x = i*num - 1;
                    int l = x/2 + 1;

                    int r = Math.min(n,x-1);
                    if(l<=r){
                        res += (r-l+1);
                    }

                }

            out.println(res);
        }

        out.flush();
        out.close();
    }
    static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();

            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}

import java.util.*;

/**
 * Created by evgeniyradchenko on 11/28/17.
 */
public class Main {

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

        int n = s.nextInt();

        int cur = 0;

        while (cur * 10 + 9 <= n + (n - 1)) {
            cur = cur * 10 + 9;
        }

        if (cur == 0) {
            System.out.println(n / 2);

            return;
        }

        if (cur > n) {
            int ans = (2 * n - cur + 1) / 2;
            int add = cur + 1;

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }
            System.out.println(ans);
        } else {
            int add = cur + 1;
            int ans = (cur - 1) / 2;

            while (cur + add <= n) {
                cur += add;
                ans += (cur - 1) / 2;
            }

            while (cur + add <= n + n - 1) {
                cur += add;
                ans += (2 * n - cur + 1) / 2;
            }

            System.out.println(ans);
        }
    }

}

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    boolean check(long z) {
    	boolean flag=false;
    	if(z%10!=0)
    		flag=true;
    	else {
    		boolean iss=false;
    		while(z>0) {
    			long r=z%10;
    			if(r==9 && iss) {
    				flag=true;
    				break;
    			}
    			if(r!=9) {
    				iss=true;
    			}
    			z/=10;
    		}
    	}
    	return flag;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
            //h.pn(arr[i]);;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1 ;i--){
        	if(arr[i]-n<n){
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                        	x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                if(!check(n))
                	h.pn(ans-1);
                else
                	h.pn(ans);;
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn((n*(n-1))/2);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

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 N = Integer.parseInt(n);
        int result = N*(N - 1);
        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.*;
import java.util.*;
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);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }
        static class TaskE {
         int a1[]={31,28,31,30,31,30,31,31,30,31,30,31};

         public void solve(int testNumber, InputReader in, PrintWriter out) {
          long n=in.nextInt();
          long max=2*n-1;
          int d=1;long m=10;
          while(max/m!=0){d++;m*=10;}
          StringBuilder sb=new StringBuilder();
          for(int i=1;i<d;i++)sb.append('9');
          int l=1;//out.println(d);
          ArrayList<Long> al=new ArrayList<>();
          for(int i=0;i<=9;i++){
           StringBuilder sb1=new StringBuilder(sb);
           sb1.insert(0,String.valueOf(i));//out.println(sb1);
           if(Long.valueOf(sb1.toString())>max){l=i-1;break;}
           if(i==9){al.clear();}
           al.add(Long.valueOf(sb1.toString())-1);
          }
          int ans=0;
           for(int i=0;i<al.size();i++){
            long e=al.get(i)/2+1;
            ans+=Math.min(n,al.get(i))-e+1;
           }
           out.print(ans);
         }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.concurrent.ThreadLocalRandom;

import static java.lang.Math.*;

public class Sol implements Runnable {

    static long mod = 1000000007;

    void solve(int total_test_cases, InputReader in, PrintWriter w) {
        for (int test_case = 1; test_case <= total_test_cases; test_case++) {
            long n = in.nextLong();
            long a[] = new long[15];
            a[1] = 5L;
            for(int i=2;i<15;i++) a[i] = a[i - 1] * 10L;

            int ind = 0;
            while(ind < 14) {
                if(a[ind + 1] > n) break;
                ind++;
            }

            if(ind == 0) w.println(0);
            else {
                long till = n + n - 1;

                long N = 9;
                for(int i=2;i<=ind;i++) N = N * 10 + 9L;
                long NN = N;
                long itr = 0;

                long ans = 0;

                while(true) {
                    N = itr * (long)pow(10, ind) + NN;
                    itr++;

                    if(N > till) break;

                    if(N > n) {
                        long initial = N - n;
                        long count = (n - initial + 1) / 2L;
                        ans += count;
                    }
                    else {
                        long count = N / 2L;
                        ans += count;
                    }

                    //w.println(ans+" "+N);
                }

                w.println(ans);
            }
        }
    }

    // ************* Code ends here ***************

    void init() throws Exception {
        //Scanner in;
        InputReader in;
        PrintWriter w;
        boolean online = false;

        String common_in_fileName = "\\in";
        String common_out_fileName = "\\out";
        int test_files = 0;

        for(int file_no = 0; file_no <= test_files; file_no++) {

            String x = "" + file_no;
            if (x.length() == 1) x = "0" + x;

            String in_fileName = common_in_fileName + "" + x;
            String out_fileName = common_out_fileName + "" + x;

            if (online) {
                //in = new Scanner(new File(in_fileName + ".txt"));
                in = new InputReader(new FileInputStream(new File(in_fileName + ".txt")));
                w = new PrintWriter(new FileWriter(out_fileName + ".txt"));
            } else {
                //in = new Scanner(System.in);
                in = new InputReader(System.in);
                w = new PrintWriter(System.out);
            }

            solve(1, in, w);
            w.close();
        }
    }

    public void run() {
        try {
            init();
        }
        catch(Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }

    public static void main(String args[]) throws Exception {
        new Thread(null, new Sol(),"Sol",1<<28).start();
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c)) {
                c = read();
            }

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }
}

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

import static java.lang.Math.*;

public class Main implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Main(),"Main",1<<26).start();
	}
    long findAns(int n) {
        long ans = 1;
        for(long i = 0; i < n; ++i)
            ans *= 10;
        return ans;
    }
    long findValue(int n) {
        long ans = 0;
        long val = 1;
        for(int i = 0; i < n; ++i) {
            ans += 4 * val;
            val *= 10;
        }
        return ans;
    }
	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

        int n = sc.nextInt();
        if(n <= 4) {
            int ans = n * (n - 1) / 2;
            w.print(ans);
            w.close();
            return;
        }
        long ans = 0;
        int temp = n;
        int digits = 0;
        while(temp != 0) {
            digits++;
            temp /= 10;
        }

        char s[] = Integer.toString(n).toCharArray();

        if(s[0] >= '5') {
            ans = (long)(s[0] - '5') * findAns(digits - 1);
            ans += (long)(n - ((s[0] - '0') * findAns(digits - 1)) + 1);
            int flag = 0;
            for(int i = 0; i < s.length; ++i) {
                if(s[i] != '9') {
                    flag = 1;
                    break;
                }
            }
            if(flag == 0)
                ans--;
        }
        else {
            long m = s[0] - '0';
            ans = m * (m - 1) / 2 * findAns(digits - 1);
            ans += findAns(digits - 1) / 2 * m;
            long left = (long)(n - ((s[0] - '0') * findAns(digits - 1)) + 1);
            ans += (left * m);
            ans += (left - (findValue(digits - 1) + 1));
            ans -= m;
            int flag = 0;
            for(int i = 1; i < s.length; ++i) {
                if(s[i] != '9')
                    flag = 1;
            }
            if(flag == 0)
                ans--;
        }
        w.print(ans);
		w.close();
	}
}

/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

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

public class Code270
{

	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		long n = in.nextLong();
		if(n<=4)
		{
			pw.print(0);
		}
		else
		{
			long max = 999999999;

			while(true)
			{
				long x = max/2;
				x++;
				if(n>=x)
					break;
				max/=10;
			}
			//System.out.println(max);
			long ans = 0;
			long temp = max;
			long count = 0;

			while(temp>0)
			{
				count++;
				temp/=10;
			}

			long multi = 1;
			while(count>0)
			{
				multi*=10;
				count--;
			}

			for(long i=0;i<=8;i++)
			{
				long cur = i*multi + max;
				if(n>=cur)
					ans += (cur/2);
				else if(n<cur/2)
					break;
				else
					ans += (n - cur/2);
			}

			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}

	static class InputReader
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}

	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static HashSet<Integer> primeFactorization(int n)
	{
		HashSet<Integer> a =new HashSet<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(2*i);j<n;j+=i)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

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

	public static void extendedEuclid(int A,int B)
	{
		if(B==0)
		{
			d = A;
			p = 1 ;
			q = 0;
		}
		else
		{
			extendedEuclid(B, A%B);
			int temp = p;
			p = q;
			q = temp - (A/B)*q;
		}
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static boolean isPrime(int n)
	{

	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    if (n%2 == 0 || n%3 == 0)
	    	return false;

	    for (int i=5; i*i<=n; i=i+6)
	    {
	        if (n%i == 0 || n%(i+2) == 0)
	           return false;
	    }

	    return true;
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString()
		{
			return x+" "+y;
		}

		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}

		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}

import java.io.*;
	import java.math.BigInteger;
	import java.math.RoundingMode;
	import java.text.DecimalFormat;
	import java.util.*;

	public class Solution
	{

		static double eps=(double)1e-6;
		static long mod=(long)(1e9+9);
		//static int arr[] =new int[1000001];
		//private static DecimalFormat df2 = new DecimalFormat(".##");
		public static void main(String args[]){
			InputReader sc = new InputReader(System.in);
			//Scanner sc=new Scanner(System.in);
			OutputStream outputStream = System.out;
			PrintWriter out = new PrintWriter(outputStream);
			//----------my code----------
			int t1=1;
			while(t1-->0)
			{
				long n=sc.nextLong();
				if(n<5)
					out.println("0");
				else if(n>=5 && n<50)
				{
					long temp=n%10;
					long d=n/10;
					long ans=5*d*d;
					if(temp<5)
						ans+=temp*d;
					else if(temp<9)
						ans+=temp*d+(temp%5+1);
					else
						ans+=temp*d+4;
					out.println(ans);
				}
				else if(n>=50 && n<500)
				{
					long temp=n%100;
					long d=n/100;
					long ans=50*d*d;
					if(temp<50)
					{
						ans+=temp*d;
					}
					else if(temp<99)
					{
						ans+=temp*d+(temp%50+1);
					}
					else
						ans+=temp*d+49;
					out.println(ans);
				}
				else if(n>=500 && n<5000)
				{
					long temp=n%1000;
					long d=n/1000;
					long ans=500*d*d;
					if(temp<500)
					{
						ans+=temp*d;
					}
					else if(temp<999)
					{
						ans+=temp*d+(temp%500+1);
					}
					else
						ans+=temp*d+499;
					out.println(ans);
				}
				else if(n>=5000 && n<50000)
				{
					long temp=n%10000;
					long d=n/10000;
					long ans=5000*d*d;
					if(temp<5000)
					{
						ans+=temp*d;
					}
					else if(temp<9999)
					{
						ans+=temp*d+(temp%5000+1);
					}
					else
						ans+=temp*d+4999;
					out.println(ans);
				}
				else if(n>=50000 && n<500000)
				{
					long temp=n%100000;
					long d=n/100000;
					long ans=50000*d*d;
					if(temp<50000)
					{
						ans+=temp*d;
					}
					else if(temp<99999)
					{
						ans+=temp*d+(temp%50000+1);
					}
					else
						ans+=temp*d+49999;
					out.println(ans);
				}
				else if(n>=500000 && n<5000000)
				{
					long temp=n%1000000;
					long d=n/1000000;
					long ans=500000*d*d;
					if(temp<500000)
					{
						ans+=temp*d;
					}
					else if(temp<999999)
					{
						ans+=temp*d+(temp%500000+1);
					}
					else
						ans+=temp*d+499999;
					out.println(ans);
				}
				else if(n>=5000000 && n<50000000)
				{
					long temp=n%10000000;
					long d=n/10000000;
					long ans=5000000*d*d;
					if(temp<5000000)
					{
						ans+=temp*d;
					}
					else if(temp<9999999)
					{
						ans+=temp*d+(temp%5000000+1);
					}
					else
						ans+=temp*d+4999999;
					out.println(ans);
				}
				else if(n>=50000000 && n<500000000)
				{
					long temp=n%100000000;
					long d=n/100000000;
					long ans=50000000*d*d;
					if(temp<50000000)
					{
						ans+=temp*d;
					}
					else if(temp<99999999)
					{
						ans+=temp*d+(temp%50000000+1);
					}
					else
						ans+=temp*d+49999999;
					out.println(ans);
				}
				else if(n>=500000000 && n<=1000000000)
				{
					long temp=n%1000000000;
					long d=n/1000000000;
					long ans=500000000*d*d;
					if(temp<500000000)
					{
						ans+=temp*d;
					}
					else if(temp<999999999)
					{
						ans+=temp*d+(temp%500000000+1);
					}
					else
						ans+=temp*d+499999999;
					out.println(ans);
				}
			}
			//---------------------------------
			out.close();
		}

		static long modInverse(long A,long M)
		{
		    return modularExpon(A,M-2,M);
		}

		static long comb(int n,int r,long [][] c)
		{
			if(n<r)
				return 0;
			if(n-r < r)
			{
				c[n][r]=comb(n,n-r,c);
				return c[n][r];
			}
		    if(r == 0)
		    {
		    	c[n][r]=1;
		    	return 1;
		   	}
		    if(c[n][r]!=0)
		    	return c[n][r];
		    else
		    {
		    	c[n][r]=(n*comb(n-1, r-1,c))/r;
		    	return c[n][r];
		    }
		}

		static long modularExpon(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result%M;
		}

		static int IsPandigital(int n)
	    {
	        int digits = 0,temp=n; int count = 0; int tmp = 0;
	        int fr[]=new int[10];
	        for(int i=0;i<10;i++)
	        	fr[i]=0;
	        while(temp>0)
	        {
	        	int a=temp/10;
	        	//System.out.println(temp-a*10);
	        	fr[temp-a*10]++;
	        	temp=temp/10;
	        	digits++;
	        }
	        for(int i=1;i<=digits;i++)
	        {
	        	if(fr[i]==1)
	        	{
	        		tmp=1;
	        	}
	        	else
	        	{
	        		tmp=0;
	        		break;
	        	}
	        }
	        return tmp;
	    }

		static int Divisors(int n)
		{
			int sum=0;
		    for (int i=2; i*i<=n; i++)
		    {
		        if (n%i==0)
		        {
		            if (n/i == i)
		                {sum+=i;//System.out.println(sum+" "+i);
		                }

		            else
		                {sum+=i+(n/i);//System.out.println(sum+" "+i+" "+(n/i));
		                }
		        }
		    }
		    return sum;
		}

		static int findmax(int arr[], int n)
	    {
	        int incl = arr[0];
	        int excl = 0;
	        int excl_new;
	        int i;

	        for (i = 1; i < n; i++)
	        {
	            excl_new = (incl > excl) ? incl : excl;
	            incl = excl + arr[i];
	            excl = excl_new;
	        }
	        return ((incl > excl) ? incl : excl);
	    }

		static long ce(long x)
		{
			if(x%2!=0)
				return x/2+1;
			return x/2;
		}
		static boolean isSubSequence(String str1, String str2, int m, int n)
		{
		   int j = 0;
		   for (int i=0; i<n&&j<m; i++)
		       if (str1.charAt(j) == str2.charAt(i))
		         j++;

		   return (j==m);
		}

		static long fibo(long l) {
	        if (l < 0) {
	            throw new IllegalArgumentException("The fibo value cannot be negative");
	        }

	        if (l <= 1) return l;

	        long[][] result = {{1, 0}, {0, 1}}; // identity matrix.
	        long[][] fiboM = {{1, 1}, {1, 0}};

	        while (l > 0) {
	            if (l%2 == 1) {
	                multMatrix(result, fiboM);
	            }
	            l = l / 2;
	            multMatrix(fiboM, fiboM);
	        }

	        return result[1][0];
	    }

	    private static void multMatrix(long[][] result, long[][] fiboM) {
	        long a = (result[0][0]%mod * fiboM[0][0]%mod)%mod +  (result[0][1]%mod * fiboM[1][0]%mod)%mod;
	        long b = (result[0][0]%mod * fiboM[0][1]%mod)%mod + ( result[0][1]%mod * fiboM[1][1]%mod)%mod;
	        long c = (result[1][0]%mod * fiboM[0][0]%mod)%mod + ( result[1][1]%mod * fiboM[0][1]%mod)%mod;
	        long d = (result[1][0]%mod * fiboM[0][1]%mod)%mod +  (result[1][1]%mod * fiboM[1][1]%mod)%mod;

	        result[0][0] = a;
	        result[0][1] = b;
	        result[1][0] = c;
	        result[1][1] = d;
	    }

	    static HashSet<Long> gr(int size)
	    {
	    	long range=mod;
	    	long m0=2017;
	    	long m1=2027;
	    	long ln=0;
	    	long sln=1;
	    	long mn=0;
	    	HashSet<Long> hs=new HashSet<Long>();
	    	for(int i=0;i<size;i++)
	    	{
	    		long nn=((((ln%mod)*m0)%mod+((sln%mod)*m1)%mod+mn)%mod)+1;
	    		sln=ln;
	    		ln=nn;
	    		mn=Math.max(mn, nn);
	    		hs.add(nn);
	    	}
	    	return hs;
	    }

		static int[] sieve(int n,int[] arr)
		{
			arr[0]=1;
			arr[1]=1;
			for(int i=2;i*i<=n;i++)
			{
				if(arr[i]==0)
				{
					for(int j=i*2;j<=n;j+=i)
						arr[j]=1;
				}
			}
			return arr;
		}

		static int[] spfsieve(int arr[])
		{
			int n=5000000;
			arr[0]=1;
			arr[1]=1;
			for(int i=2;i<=n;i++)
				arr[i]=i;
			for(int i=4;i<=n;i+=2)
				arr[i]=2;
			for(int i=3;i*i<=n;i++)
			{
				if(arr[i]==i)
				{
					for(int j=i*i;j<=n;j+=i)
						if (arr[j]==j)
		                    arr[j] = i;
				}
			}
			return arr;
		}

		static boolean isPal(String s)
		{
			for(int i=0, j=s.length()-1;i<=j;i++,j--)
			{
				if(s.charAt(i)!=s.charAt(j)) return false;
			}
			return true;
		}
		public static String rev(String s)
		{
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
		}

		static long lcm(long a, long b)
		{
			long temp1=a,temp2=b;
		    return ((a * b) / gcd(temp1, temp2));
		}

		static long gcd(long a, long b)
		{
		    if (b==0)
		        return a;
		    return gcd(b, a%b);
		}
		static long modulo(long a,long b,long c) {
			long x=1;
			long y=a;
			while(b > 0){
				if(b%2 == 1){
					x=(x*y)%c;
				}
				y = (y*y)%c; // squaring the base
				b /= 2;
			}
			return  x%c;
		}
		public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}

		static class SegmentTree
		{
		    long st[];
		    public SegmentTree(long arr[], int n)
		    {
		        int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));

		        int max_size = 2 * (int) Math.pow(2, x) - 1;

		        st = new long[max_size];

		        constructSTUtil(arr, 0, n - 1, 0);
		    }
		    int getMid(int s, int e) {
		        return s + (e - s) / 2;
		    }

		    long getSumUtil(int ss, int se, int qs, int qe, int si)
		    {
		        if (qs <= ss && qe >= se)
		            return st[si];
		        if (se < qs || ss > qe)
		            return 0;
		        int mid = getMid(ss, se);
		        return getSumUtil(ss, mid, qs, qe, 2 * si + 1) +
		                getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
		    }

		    void updateValueUtil(int ss, int se, int i, int diff, int si)
		    {
		        if (i < ss || i > se)
		            return;
		        st[si] = st[si] + diff;
		        if (se != ss) {
		            int mid = getMid(ss, se);
		            updateValueUtil(ss, mid, i, diff, 2 * si + 1);
		            updateValueUtil(mid + 1, se, i, diff, 2 * si + 2);
		        }
		    }

		    void updateValue(int arr[], int n, int i, int new_val)
		    {
		        if (i < 0 || i > n - 1) {
		            System.out.println("Invalid Input");
		            return;
		        }

		        // Get the difference between new value and old value
		        int diff = new_val - arr[i];

		        // Update the value in array
		        arr[i] = new_val;

		        // Update the values of nodes in segment tree
		        updateValueUtil(0, n - 1, i, diff, 0);
		    }
		    long getSum(int n, int qs, int qe)
		    {
		        if (qs < 0 || qe > n - 1 || qs > qe) {
		            System.out.println("Invalid Input");
		            return -1;
		        }
		        return getSumUtil(0, n - 1, qs, qe, 0);
		    }

		    long constructSTUtil(long arr[], int ss, int se, int si)
		    {
		        if (ss == se) {
		            st[si] = arr[ss];
		            return arr[ss];
		        }
		        int mid = getMid(ss, se);
		        st[si] = constructSTUtil(arr, ss, mid, si * 2 + 1) +
		                 constructSTUtil(arr, mid + 1, se, si * 2 + 2);
		        return st[si];
		    }
		}
		static class Pair {
			long x;
			long y;
			/*Pair(int xx,int yy,int zz){
				x=xx;
				y=yy;
				z=zz;
			}*/
			public long getx()
			{
				return x;
			}
			public long gety()
			{
				return y;
			}
			public void setx(long xx)
			{
				x=xx;
			}
			public void sety(long yy)
			{
				y=yy;
			}
		}

		public final static Comparator<Pair> ORIGINAL = new Comparator<Pair>()
	    {
		public int compare(Pair p1,Pair p2)
		{
			if(p1.getx()<p2.getx())
				return -1;
			else if(p1.getx()==p2.getx() && p1.gety()<p2.gety())
				return -1;
			else //if(p1.getx()>p2.getx() || p1.gety()>p2.gety() || p1.getz()>p2.getz())
				return 1;
			/*else
			{
				if(p1.gety()<p2.gety())
					return -1;
				else if(p1.gety()>p2.gety())
					return 1;
				else
				{
					if(p1.getz()<p2.getz())
						return -1;
					else if(p1.getz()>p2.getz())
						return 1;
				}
			}*/
			//return 0;
		}
	    };

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

			public InputReader(InputStream inputstream) {
				reader = new BufferedReader(new InputStreamReader(inputstream));
				tokenizer = null;
			}

			public String nextLine(){
				String fullLine=null;
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						fullLine=reader.readLine();
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
					return fullLine;
				}
				return fullLine;
			}
			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 long nextLong() {
				return Long.parseLong(next());
			}
			public int nextInt() {
				return Integer.parseInt(next());
			}
		}

	}
	class Graph
	{
		int vertices;
		LinkedList<Integer> l[];
		Graph(int vertices)
		{
			this.vertices=vertices;
			l=new LinkedList[vertices];
			for(int i=0;i<vertices;i++)
			{
				l[i]=new LinkedList<Integer>();
			}
		}
		void addEdge(int s,int v)
		{
			l[s].add(v);
		}

		void BFS(int s)
		{
			LinkedList<Integer> queue=new LinkedList<Integer>();
			boolean []visited=new boolean[vertices];
			visited[s]=true;
			queue.add(s);
			while(queue.size()>0)
			{
				int r=queue.poll();
				System.out.println(r+" ");
				for(int i=0;i<l[r].size();i++)
				{
					int temp=l[r].get(i);
					if(!visited[temp])
					{
						queue.add(temp);
						visited[temp]=true;
					}
				}
			}
		}

	}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();

            long max = n - 1 + n;

            String s = max + "";
            int x = countSuffix(s);
            String ss;
            String sl;
            if (s.length() - 1 > x) {
                char t[] = new char[s.length()];
                t[0] = (char) (s.charAt(0) - 1);
                for (int i = 1; i < s.length(); i++) {
                    t[i] = '9';
                }
                ss = new String(t);
                sl = ss.substring(1);
            } else {
                sl = ss = s;
            }

            long j = Long.parseLong(sl);
            long ct = 0;

            for (long i = Long.parseLong(ss); i >= j; i -= 10L) {
                ct += (i / 2);
                ct -= Math.max(0, i - n - 1);
            }

            out.println(ct);
        }

        int countSuffix(String s) {
            int len = s.length();
            int ct = 0;
            for (int i = len - 1; i >= 0; i--) {
                if (s.charAt(i) == '9')
                    ct++;
            }
            return ct;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class CFD {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    int[] dx = {0, -1, 0, 1};
    int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        long n = nextLong();
        long max = n + n - 1;
        long nine = 9;
        while (nine <= max) {
            nine = 10 * nine + 9;
        }

        nine = nine / 10;
        int cnt = Long.toString(nine).toCharArray().length;
        char[] arr = Long.toString(n).toCharArray();
        long res = 0;

        if (nine == 0) {
            long ret = 1L * n * (n - 1) / 2;
            out(ret);
            return;
        }

        if (arr.length == cnt) {
            if (nine <= n) {
                out(nine / 2);
            }
            else if (nine < 2 * n) {
                out((2 * n - nine + 1) / 2);
            }
            else {
                out(0);
            }
            return;
        }

        long base = 1;
        for (int i = 0; i < cnt; i++) {
            base = 10 * base;
        }

        for (int i = 0; i <= arr[0] - '0'; i++) {
            long sum = i * base + nine;

            if (sum <= n) {
                res += sum / 2;
            }
            else if (sum < 2 * n) {
                res += (2 * n - sum + 1) / 2;
            }
        }

        out(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public CFD() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFD();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        int countSuffix(String s) {
            int len = s.length();
            int ct = 0;
            for (int i = len - 1; i >= 0; i--) {
                if (s.charAt(i) == '9')
                    ct++;
            }
            return ct;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long n = in.nextLong();

            if (n <= 4) {
                out.println((n * (n - 1)) / 2);
                return;
            }

            long max = n - 1 + n;
            int len = (max + "").length();

            long lo, hi, diff;
            if (countSuffix(max + "") == len) {
                lo = hi = max;
                diff = 1L;
            } else {
                StringBuilder nine = new StringBuilder();
                StringBuilder zero = new StringBuilder();
                for (int i = 1; i < len; i++) {
                    nine.append('9');
                    zero.append('0');
                }

                diff = Long.parseLong(1 + zero.toString());
                lo = Long.parseLong(nine.toString());
                hi = Long.parseLong(((max + "").charAt(0) - '1') + nine.toString());
            }

            long ct = 0;
            for (long i = hi; i >= lo; i -= diff) {
                ct += (i / 2);
                ct -= Math.max(0, i - n - 1);
            }
            out.println(ct);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

//Standard template for my java code: Arun Ganesh//
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[1000001]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
   static StringBuilder fin = new StringBuilder("");
   static long mod = 1000000007;

    public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		long n = in.nextLong();
		long ans =0;
		if(n<5)
			ans = n/2;
		else
	    {

		String s = Long.toString(n);
		int len = s.length();

		long ach = (long)Math.pow(10.0,len)-1;
		long limit = n + n-1;
		int z =0;
		if(limit >= ach)
		{
			ans = ans + (n-ach+n+1)/2;
			int figs = len;
			long create = (long)Math.pow(10.0,figs)+ach;
			for(long i = create;i<=limit;i = i + (long)Math.pow(10.0,figs))
			{
				long lower = create - n;
				ans = ans + (n-lower+1)/2;
			}
			z=1;
		}
		else
		{
			long bain = (long)Math.pow(10.0,len-1)-1;
			ans = ans + (bain-1)/2;
			int figs = len-1;
			long create = (long)Math.pow(10.0,figs)+bain;
			for(long i = create;i<=limit;i = i + (long)Math.pow(10.0,figs))
			{
				long lower = create - n;
				ans = ans + (n-lower+1)/2;
			}
		}
			}
		fin.append(ans);
		System.out.print(fin);

	}

 static long modInverse(long a, long m)
{

       return power(a, m-2, m);

}

// To compute x^y under modulo m
static long power(long x, long y, long m)
{
    if (y == 0)
        return (long)1;
    long p = power(x, y/2, m) % m;
    p = (p * p) % m;

    return (y%2 == 0)? p : (x * p) % m;
}
/*static class dj{
	int par[],n,rank[];
	List<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
	dj(int n)
	{
		this.n=n;
		par = new int[n+5];
		rank = new int[n+5];
		for(int i=0;i<=n;++i)
			par[i] = i;
	}
	public void mp(int x,int y)
	{
		int par1 = find(x);
		int par2 = find(y);
		if(rank[par1] >rank[par2])
		{
		par[par2] = par1;
		rank[par1]++;
		}
		else
		{
			par[par1] = par2;
			rank[par2]++;
		}
	}
	public int find(int x)
	{
		while(x!=par[x])
		{
			x = par[x];
		}
		return x;
	}
	public long finish()
	{
		for(int i=0;i<2005;++i)
			al.add(new ArrayList<Integer>());
		for(int i=0;i<n;++i)
			par[i] = find(i);
		for(int i=0;i<n;++i) System.out.print(par[i]+ " ");System.out.println();
		int ans[] = new int[2005];
		int cnt[] = new int[2005];
		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
				cnt[i] = cnt[i]+a[i][j];
		Arrays.fill(ans,-1);
		int ind=0;
		for(int i=0;i<n;++i)
		{
			int temp = par[i];
			if(ans[temp] == -1)
			{
				ans[temp] = ind;
				ind++;

			}
			al.get(ans[temp]).add(i);
		}
		long sum=0;
		for(int i=0;i<n;++i){
			for(int j=0;j<al.get(i).size();++j)
			{
				System.out.print(al.get(i).get(j) + " ");
			    sum = sum + (al.get(i).size() - cnt[al.get(i).get(j)] -1);
			}
			System.out.println();
	}

		return sum;
	}
}*/

  }

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
            //h.pn(arr[i]);;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1 ;i--){

        	if(arr[i]-n<n){
        		//h.pn(arr[i]);;
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                        	x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                if(ans%10==9)
                	h.pn(ans-1);
                else
                	h.pn(ans);;
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn((n*(n-1))/2);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

//package round452;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		long t = 2*n;
		if(t < 9){
			out.println(n*(n+1)/2);
			return;
		}
		long d = 1;
		for(;t/d > 0;d*=10);
		// sum <= 8
		long ideal = t / (d/10) * (d/10) - 1;
		long ret = 0;
		while(ideal > 0){
			long inf = ideal / 2 + 1;
			long sup = Math.min(ideal-1, n);
			if(inf <= sup)ret += sup-inf+1;
			ideal -= d/10;
		}
		out.println(ret);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.util.*;
public class sol
{
	public static void main(String args[])
	{
		int x ;
		Scanner scan = new Scanner(System.in);
		x = scan.nextInt();
		int p = 2*x-1;
		int r1 = p ;
		int a = 0,b=0,flag=0,ans=0;
		int t =0;
		while(p>0)
		{
              if(p%10==9)
              {
              	a++;
              }
              b++;
              p/=10;
		}
		p=r1;
		if(a==b)
		{
			ans = 1;
		}
		else if(x<5)
			{
              ans=x*(x-1)/2 ;
           }
		else
		{
			if(a==b-1)
			{
				flag = 1 ;
			}
			while(p>0)
			{
                 t = p%10 ;
                 p/=10    ;
			}
			if(flag==0)
			{
               t-- ;
			}
			int r = t ;
			long y = 1;
			b--;
			while(b>0)
			{
				t*=10;
				t+=9 ;
				y*=10;
				b--;
			}
			//System.out.println( t + " " + y + " " +r);
			//int ans = 0 ;
			for(int i = r ;i >=0 ;i--)
			{
			   if(t>x)
               ans += (t-1)/2+(x-t)+1;
               else
               ans +=(t-1)/2;
               t-=y;
			}
		}
		System.out.println(ans);
	}
}

import java.util.Scanner;

public class probemD {
	public static boolean allnine(int x)
	{
		boolean gg=true;
		while(x!=0)
		{
			int k=x%10;
			if(k!=9)
			{
				return false;

			}
			x=x/10;
		}
		return true;
	}
	public static int nodig(int x)
	{
		int dig=0;
		while(x!=0)
		{
			x/=10;
			dig++;
		}
		return dig;
	}
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int maxn=n+n-1;
		if(maxn<9)
		{
			System.out.println(n*(n-1)/2);
		}else if(allnine(maxn))
		{
			System.out.println(1);
		}else {
			long ans=0;
			int nonine=nodig(maxn)-1;
			long num=(long) (Math.pow(10, nonine)-1);
		//	System.out.println(num);
			while(num<maxn)
			{
				if(n>=num)
				{
					ans+=(num/2);
				}else {
					ans+=(n-num/2);
				}
				num+=Math.pow(10,nonine);

			}
			System.out.println(ans);
		}

	}
}

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++) {
                long p = Long.parseLong(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.io.*;
	import java.math.BigInteger;
	import java.math.RoundingMode;
	import java.text.DecimalFormat;
	import java.util.*;

	public class Solution
	{

		static double eps=(double)1e-6;
		static long mod=(long)(1e9+9);
		//static int arr[] =new int[1000001];
		//private static DecimalFormat df2 = new DecimalFormat(".##");
		public static void main(String args[]){
			InputReader sc = new InputReader(System.in);
			//Scanner sc=new Scanner(System.in);
			OutputStream outputStream = System.out;
			PrintWriter out = new PrintWriter(outputStream);
			//----------my code----------
			int t1=1;
			while(t1-->0)
			{
				long n=sc.nextLong();
				if(n<5)
					out.println("0");
				else if(n>=5 && n<50)
				{
					long temp=n%10;
					long d=n/10;
					long ans=5*d*d;
					if(temp<5)
						ans+=temp*d;
					else if(temp<9)
						ans+=temp*d+(temp%5+1);
					else
						ans+=temp*d+4;
					out.println(ans);
				}
				else if(n>=50 && n<500)
				{
					long temp=n%100;
					long d=n/100;
					long ans=50*d*d;
					if(temp<50)
					{
						ans+=temp*d;
					}
					else if(temp<99)
					{
						ans+=temp*d+(temp%50+1);
					}
					else
						ans+=temp*d+49;
					out.println(ans);
				}
				else if(n>=500 && n<5000)
				{
					long temp=n%(long)(1e3);
					long d=n/(long)1e3;
					long ans=500*d*d;
					if(temp<500)
					{
						ans+=temp*d;
					}
					else if(temp<999)
					{
						ans+=temp*d+(temp%500+1);
					}
					else
						ans+=temp*d+499;
					out.println(ans);
				}
				else if(n>=(5*(long)1e3) && n<(5*(long)1e4))
				{
					long temp=n%(long)(1e4);
					long d=n/(long)1e4;
					long ans=(5*(long)1e3)*d*d;
					if(temp<(5*(long)1e3))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e4)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e3)+1);
					}
					else
						ans+=temp*d+(5*(long)1e3)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e4) && n<(5*(long)1e5))
				{
					long temp=n%(long)(1e5);
					long d=n/(long)1e5;
					long ans=(5*(long)1e4)*d*d;
					if(temp<(5*(long)1e4))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e5)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e4)+1);
					}
					else
						ans+=temp*d+(5*(long)1e4)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e5) && n<(5*(long)1e6))
				{
					long temp=n%(long)(1e6);
					long d=n/(long)1e6;
					long ans=(5*(long)1e5)*d*d;
					if(temp<(5*(long)1e5))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e6)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e5)+1);
					}
					else
						ans+=temp*d+(5*(long)1e5)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e6) && n<(5*(long)1e7))
				{
					long temp=n%(long)(1e7);
					long d=n/(long)1e7;
					long ans=(5*(long)1e6)*d*d;
					if(temp<(5*(long)1e6))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e7)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e6)+1);
					}
					else
						ans+=temp*d+(5*(long)1e6)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e7) && n<(5*(long)1e8))
				{
					long temp=n%(long)(1e8);
					long d=n/(long)1e8;
					long ans=(5*(long)1e7)*d*d;
					if(temp<(5*(long)1e7))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e8)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e7)+1);
					}
					else
						ans+=temp*d+(5*(long)1e7)-1;
					out.println(ans);
				}
				else if(n>=(5*(long)1e8) && n<=((long)1e9))
				{
					long temp=n%(long)(1e9);
					long d=n/(long)1e9;
					long ans=(5*(long)1e8)*d*d;
					if(temp<(5*(long)1e8))
					{
						ans+=temp*d;
					}
					else if(temp<(long)(1e9)-1)
					{
						ans+=temp*d+(temp%(5*(long)1e8)+1);
					}
					else
						ans+=temp*d+(5*(long)1e8)-1;
					out.println(ans);
				}
			}
			//---------------------------------
			out.close();
		}

		static long modInverse(long A,long M)
		{
		    return modularExpon(A,M-2,M);
		}

		static long comb(int n,int r,long [][] c)
		{
			if(n<r)
				return 0;
			if(n-r < r)
			{
				c[n][r]=comb(n,n-r,c);
				return c[n][r];
			}
		    if(r == 0)
		    {
		    	c[n][r]=1;
		    	return 1;
		   	}
		    if(c[n][r]!=0)
		    	return c[n][r];
		    else
		    {
		    	c[n][r]=(n*comb(n-1, r-1,c))/r;
		    	return c[n][r];
		    }
		}

		static long modularExpon(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result%M;
		}

		static int IsPandigital(int n)
	    {
	        int digits = 0,temp=n; int count = 0; int tmp = 0;
	        int fr[]=new int[10];
	        for(int i=0;i<10;i++)
	        	fr[i]=0;
	        while(temp>0)
	        {
	        	int a=temp/10;
	        	//System.out.println(temp-a*10);
	        	fr[temp-a*10]++;
	        	temp=temp/10;
	        	digits++;
	        }
	        for(int i=1;i<=digits;i++)
	        {
	        	if(fr[i]==1)
	        	{
	        		tmp=1;
	        	}
	        	else
	        	{
	        		tmp=0;
	        		break;
	        	}
	        }
	        return tmp;
	    }

		static int Divisors(int n)
		{
			int sum=0;
		    for (int i=2; i*i<=n; i++)
		    {
		        if (n%i==0)
		        {
		            if (n/i == i)
		                {sum+=i;//System.out.println(sum+" "+i);
		                }

		            else
		                {sum+=i+(n/i);//System.out.println(sum+" "+i+" "+(n/i));
		                }
		        }
		    }
		    return sum;
		}

		static int findmax(int arr[], int n)
	    {
	        int incl = arr[0];
	        int excl = 0;
	        int excl_new;
	        int i;

	        for (i = 1; i < n; i++)
	        {
	            excl_new = (incl > excl) ? incl : excl;
	            incl = excl + arr[i];
	            excl = excl_new;
	        }
	        return ((incl > excl) ? incl : excl);
	    }

		static long ce(long x)
		{
			if(x%2!=0)
				return x/2+1;
			return x/2;
		}
		static boolean isSubSequence(String str1, String str2, int m, int n)
		{
		   int j = 0;
		   for (int i=0; i<n&&j<m; i++)
		       if (str1.charAt(j) == str2.charAt(i))
		         j++;

		   return (j==m);
		}

		static long fibo(long l) {
	        if (l < 0) {
	            throw new IllegalArgumentException("The fibo value cannot be negative");
	        }

	        if (l <= 1) return l;

	        long[][] result = {{1, 0}, {0, 1}}; // identity matrix.
	        long[][] fiboM = {{1, 1}, {1, 0}};

	        while (l > 0) {
	            if (l%2 == 1) {
	                multMatrix(result, fiboM);
	            }
	            l = l / 2;
	            multMatrix(fiboM, fiboM);
	        }

	        return result[1][0];
	    }

	    private static void multMatrix(long[][] result, long[][] fiboM) {
	        long a = (result[0][0]%mod * fiboM[0][0]%mod)%mod +  (result[0][1]%mod * fiboM[1][0]%mod)%mod;
	        long b = (result[0][0]%mod * fiboM[0][1]%mod)%mod + ( result[0][1]%mod * fiboM[1][1]%mod)%mod;
	        long c = (result[1][0]%mod * fiboM[0][0]%mod)%mod + ( result[1][1]%mod * fiboM[0][1]%mod)%mod;
	        long d = (result[1][0]%mod * fiboM[0][1]%mod)%mod +  (result[1][1]%mod * fiboM[1][1]%mod)%mod;

	        result[0][0] = a;
	        result[0][1] = b;
	        result[1][0] = c;
	        result[1][1] = d;
	    }

	    static HashSet<Long> gr(int size)
	    {
	    	long range=mod;
	    	long m0=2017;
	    	long m1=2027;
	    	long ln=0;
	    	long sln=1;
	    	long mn=0;
	    	HashSet<Long> hs=new HashSet<Long>();
	    	for(int i=0;i<size;i++)
	    	{
	    		long nn=((((ln%mod)*m0)%mod+((sln%mod)*m1)%mod+mn)%mod)+1;
	    		sln=ln;
	    		ln=nn;
	    		mn=Math.max(mn, nn);
	    		hs.add(nn);
	    	}
	    	return hs;
	    }

		static int[] sieve(int n,int[] arr)
		{
			arr[0]=1;
			arr[1]=1;
			for(int i=2;i*i<=n;i++)
			{
				if(arr[i]==0)
				{
					for(int j=i*2;j<=n;j+=i)
						arr[j]=1;
				}
			}
			return arr;
		}

		static int[] spfsieve(int arr[])
		{
			int n=5000000;
			arr[0]=1;
			arr[1]=1;
			for(int i=2;i<=n;i++)
				arr[i]=i;
			for(int i=4;i<=n;i+=2)
				arr[i]=2;
			for(int i=3;i*i<=n;i++)
			{
				if(arr[i]==i)
				{
					for(int j=i*i;j<=n;j+=i)
						if (arr[j]==j)
		                    arr[j] = i;
				}
			}
			return arr;
		}

		static boolean isPal(String s)
		{
			for(int i=0, j=s.length()-1;i<=j;i++,j--)
			{
				if(s.charAt(i)!=s.charAt(j)) return false;
			}
			return true;
		}
		public static String rev(String s)
		{
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
		}

		static long lcm(long a, long b)
		{
			long temp1=a,temp2=b;
		    return ((a * b) / gcd(temp1, temp2));
		}

		static long gcd(long a, long b)
		{
		    if (b==0)
		        return a;
		    return gcd(b, a%b);
		}
		static long modulo(long a,long b,long c) {
			long x=1;
			long y=a;
			while(b > 0){
				if(b%2 == 1){
					x=(x*y)%c;
				}
				y = (y*y)%c; // squaring the base
				b /= 2;
			}
			return  x%c;
		}
		public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}

		static class SegmentTree
		{
		    long st[];
		    public SegmentTree(long arr[], int n)
		    {
		        int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));

		        int max_size = 2 * (int) Math.pow(2, x) - 1;

		        st = new long[max_size];

		        constructSTUtil(arr, 0, n - 1, 0);
		    }
		    int getMid(int s, int e) {
		        return s + (e - s) / 2;
		    }

		    long getSumUtil(int ss, int se, int qs, int qe, int si)
		    {
		        if (qs <= ss && qe >= se)
		            return st[si];
		        if (se < qs || ss > qe)
		            return 0;
		        int mid = getMid(ss, se);
		        return getSumUtil(ss, mid, qs, qe, 2 * si + 1) +
		                getSumUtil(mid + 1, se, qs, qe, 2 * si + 2);
		    }

		    void updateValueUtil(int ss, int se, int i, int diff, int si)
		    {
		        if (i < ss || i > se)
		            return;
		        st[si] = st[si] + diff;
		        if (se != ss) {
		            int mid = getMid(ss, se);
		            updateValueUtil(ss, mid, i, diff, 2 * si + 1);
		            updateValueUtil(mid + 1, se, i, diff, 2 * si + 2);
		        }
		    }

		    void updateValue(int arr[], int n, int i, int new_val)
		    {
		        if (i < 0 || i > n - 1) {
		            System.out.println("Invalid Input");
		            return;
		        }

		        // Get the difference between new value and old value
		        int diff = new_val - arr[i];

		        // Update the value in array
		        arr[i] = new_val;

		        // Update the values of nodes in segment tree
		        updateValueUtil(0, n - 1, i, diff, 0);
		    }
		    long getSum(int n, int qs, int qe)
		    {
		        if (qs < 0 || qe > n - 1 || qs > qe) {
		            System.out.println("Invalid Input");
		            return -1;
		        }
		        return getSumUtil(0, n - 1, qs, qe, 0);
		    }

		    long constructSTUtil(long arr[], int ss, int se, int si)
		    {
		        if (ss == se) {
		            st[si] = arr[ss];
		            return arr[ss];
		        }
		        int mid = getMid(ss, se);
		        st[si] = constructSTUtil(arr, ss, mid, si * 2 + 1) +
		                 constructSTUtil(arr, mid + 1, se, si * 2 + 2);
		        return st[si];
		    }
		}
		static class Pair {
			long x;
			long y;
			/*Pair(int xx,int yy,int zz){
				x=xx;
				y=yy;
				z=zz;
			}*/
			public long getx()
			{
				return x;
			}
			public long gety()
			{
				return y;
			}
			public void setx(long xx)
			{
				x=xx;
			}
			public void sety(long yy)
			{
				y=yy;
			}
		}

		public final static Comparator<Pair> ORIGINAL = new Comparator<Pair>()
	    {
		public int compare(Pair p1,Pair p2)
		{
			if(p1.getx()<p2.getx())
				return -1;
			else if(p1.getx()==p2.getx() && p1.gety()<p2.gety())
				return -1;
			else //if(p1.getx()>p2.getx() || p1.gety()>p2.gety() || p1.getz()>p2.getz())
				return 1;
			/*else
			{
				if(p1.gety()<p2.gety())
					return -1;
				else if(p1.gety()>p2.gety())
					return 1;
				else
				{
					if(p1.getz()<p2.getz())
						return -1;
					else if(p1.getz()>p2.getz())
						return 1;
				}
			}*/
			//return 0;
		}
	    };

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

			public InputReader(InputStream inputstream) {
				reader = new BufferedReader(new InputStreamReader(inputstream));
				tokenizer = null;
			}

			public String nextLine(){
				String fullLine=null;
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						fullLine=reader.readLine();
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
					return fullLine;
				}
				return fullLine;
			}
			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 long nextLong() {
				return Long.parseLong(next());
			}
			public int nextInt() {
				return Integer.parseInt(next());
			}
		}

	}
	class Graph
	{
		int vertices;
		LinkedList<Integer> l[];
		Graph(int vertices)
		{
			this.vertices=vertices;
			l=new LinkedList[vertices];
			for(int i=0;i<vertices;i++)
			{
				l[i]=new LinkedList<Integer>();
			}
		}
		void addEdge(int s,int v)
		{
			l[s].add(v);
		}

		void BFS(int s)
		{
			LinkedList<Integer> queue=new LinkedList<Integer>();
			boolean []visited=new boolean[vertices];
			visited[s]=true;
			queue.add(s);
			while(queue.size()>0)
			{
				int r=queue.poll();
				System.out.println(r+" ");
				for(int i=0;i<l[r].size();i++)
				{
					int temp=l[r].get(i);
					if(!visited[temp])
					{
						queue.add(temp);
						visited[temp]=true;
					}
				}
			}
		}

	}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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.readInt();
            if (n < 5) {
                out.println(n / 2);
                return;
            }

            long max = maxNine(n);
            long ans = (max - 1) / 2;
            if (max > n) {
                ans -= max - n - 1;
            }

            long ten = (long) Math.pow(10L, (max + "").length());
            for (int i = 1; ten * i + max < 2 * n; i++) {
                long v = ten * i + max;
                ans += (v - 1) / 2;
                if (v > n) ans -= v - n - 1;
            }
            out.println(ans);

        }

        long maxNine(int n) {
            long t = n * 2 - 1, ans = 0;
            for (long i = 9; i <= t; i = i * 10 + 9) {
                ans = i;
            }
            return ans;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

/**
 * @author derrick20
 */
import java.io.*;
import java.util.*;

public class ShovelSale {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        String s = sc.next();
        int N = Integer.parseInt(s);
        int S = 2 * N - 1;
        int max = 0;
        int x = 0;
        int sum = 0;
        while ((10 * x + 9) <= S) {
            max++;
            x = 10 * x + 9;
        }
        sum = x;
        x = 1;
        for (int i = 0; i < max; i++) {
            x *= 10;
        }
        while (sum + x <= S) {
            sum += x;
        }

        int ans = 0;
        if (max == 0) {
            ans = N / 2;
        }
        else {
            ans = 0;
            while (sum >= x) {
                ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
                sum -= x;
            }
            ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
        }
        out.println(ans);
        out.close();
    }

    static class FastScanner {
        private int BS = 1<<16;
        private char NC = (char)0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            }
            catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar(){
            while(bId==size) {
                try {
                    size = in.read(buf);
                }catch(Exception e) {
                    return NC;
                }
                if(size==-1)return NC;
                bId=0;
            }
            return (char)buf[bId++];
        }

        public int nextInt() {
            return (int)nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt=1;
            boolean neg = false;
            if(c==NC)c=getChar();
            for(;(c<'0' || c>'9'); c = getChar()) {
                if(c=='-')neg=true;
            }
            long res = 0;
            for(; c>='0' && c <='9'; c=getChar()) {
                res = (res<<3)+(res<<1)+c-'0';
                cnt*=10;
            }
            return neg?-res:res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c!='.' ? cur:cur+nextLong()/cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c>32) {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while(c<=32)c=getChar();
            while(c!='\n') {
                res.append(c);
                c=getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if(c>32)return true;
            while(true) {
                c=getChar();
                if(c==NC)return false;
                else if(c>32)return true;
            }
        }
    }
}

/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class D
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         if(N <= 4)
         {
            System.out.println(0);
            return;
         }
         String lol = "9";
         while(true)
         {
            long val = Long.parseLong(lol);
            if(2*N-1 < val)
               break;
            lol += 9;
         }
         int max9 = lol.length()-1;
         lol = lol.substring(1);
         long res = 0L;
         long check = Long.parseLong(lol);
         while(2*N-1 >= check)
         {
            long min = Math.max(1, check-N);
   			long max = check/2;
   			res += max-min+1;
   			check += Long.parseLong(lol)+1;
         }
         System.out.println(res);
      }
   }

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/*
 public class _899D {

 }

 */
public class _899D {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    int n = in.readInteger();

    int max9 = 0;

    long num = 0;
    long maxnum = -1;;
    for (int i = 1;; i++) {
      num *= 10;
      num += 9;

      if (2 * n >= num) {
        max9 = i;
        maxnum = num;
      } else {
        break;
      }
    }

    List<Long> posssums = new ArrayList<Long>();

    long mul = 1;

    for (int i = 1; i <= max9; i++) {
      mul *= 10;
    }
    for (int i = 0; i < 9; i++) {
      if (i * mul + maxnum <= 2 * n) {
        posssums.add(i * mul + maxnum);
      }

    }

    long ans = 0;

    for (Long cnum : posssums) {

      if (cnum <= n) {
        long min = 1;
        long max = cnum;
        ans += (max - min + 1) / 2;
      } else {
        long min = cnum - n;
        long max = n;
        ans += (max - min + 1) / 2;
      }
    }

    System.out.println(ans);
    // end here
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new _899D()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}

/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

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

public class Code270
{

	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		long n = in.nextLong();
		if(n<=4)
		{
			pw.print(n);
		}
		else
		{
			long max = 999999999;

			while(true)
			{
				long x = max/2;
				x++;
				if(n>=x)
					break;
				max/=10;
			}
			//System.out.println(max);
			long ans = 0;
			long temp = max;
			long count = 0;

			while(temp>0)
			{
				count++;
				temp/=10;
			}

			long multi = 1;
			while(count>0)
			{
				multi*=10;
				count--;
			}

			for(long i=0;i<=8;i++)
			{
				long cur = i*multi + max;
				if(n>=cur)
					ans += (cur/2);
				else if(n<cur/2)
					break;
				else
					ans += (n - cur/2);
			}

			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}

	static class InputReader
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}

	public static long mod = 1000000007;
	public static int d;
	public static int p;
	public static int q;

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static HashSet<Integer> primeFactorization(int n)
	{
		HashSet<Integer> a =new HashSet<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(2*i);j<n;j+=i)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

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

	public static void extendedEuclid(int A,int B)
	{
		if(B==0)
		{
			d = A;
			p = 1 ;
			q = 0;
		}
		else
		{
			extendedEuclid(B, A%B);
			int temp = p;
			p = q;
			q = temp - (A/B)*q;
		}
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static boolean isPrime(int n)
	{

	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    if (n%2 == 0 || n%3 == 0)
	    	return false;

	    for (int i=5; i*i<=n; i=i+6)
	    {
	        if (n%i == 0 || n%(i+2) == 0)
	           return false;
	    }

	    return true;
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}

		public String toString()
		{
			return x+" "+y;
		}

		public boolean equals(Object o)
		{
			if (o instanceof pair)
		    {
				pair p = (pair)o;
				return p.x == x && p.y == y ;
			}
			return false;
		}

		public int hashCode()
		{
			return new Long(x).hashCode()*31 + new Long(y).hashCode();
		}
	}
}

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

public class Solution{

    public static void main(String[] args) {

    	FastScanner fs = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);

    	int tt = 1;
    	while(tt-->0) {

    		int n = fs.nextInt();

    		if(n<5) {
    			out.println(n*(n-1)/2);
    			out.flush();
    			return;
    		}

    		int t = n;
    		int num = 1;
    		while(t>0) {
    			num *= 10;
    			t /= 10;
    		}

    		if(n>=(num/2)) {
    			num /= 2;
    			out.println(num - 1 - max(2*num - 1 - n, 1) + 1);
    		}
    		else {
    			int ans = 0;
    			for(int i=0;i<9;i++) {
    				int x = num/10*i + (num/10)-1;
    				int s = max(1, x - n);
    				if(s<=n) ans += (x-2*s+1)/2;
    			}
    			out.println(ans);
    		}

    	}

    	out.close();

    }

    static int min(int a, int b) {
    	if(a<b) return a;
    	return b;
    }

    static int max(int a, int b) {
    	if(a>b) return a;
    	return b;
    }

    static final Random random=new Random();

    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");

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

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

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

    	public int[] readArray(int n){
    		int[] a = new int[n];
    		for(int i=0;i<n;i++)
    			a[i] = nextInt();
    		return a;
    	}

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

    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }

}

//package math_codet;

import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*(long)Math.pow(10,i-1))+9;
            arr[i]=sum;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1;i--){
            if(arr[i]-n<n){
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                        	x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                h.pn(ans);
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn(0);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

import java.util.Scanner;

public class Main {

	public static long form(long n, long val) {
		long mid = (val - 1) >> 1;
		if(mid >= n) {
			return 0;
		}
		if(n >= val) {
			return mid;
		}
		return n - mid;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long count = 0, temp = 0;
		while(10 * temp + 9 <= n + (n - 1)) {
			count++;
			temp = temp * 10 + 9;
		}
		long ans = 0;
		for(int i = 0; i < 9; i++) {
			if(Math.pow(10, count) * i + temp > n + (n - 1)) {
				break;
			}
			long term = (long)Math.pow(10, count) * i + temp;
			ans += form(n, term);
		}
		System.out.println(ans);
	}

}

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

public class Codeforces {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        FastReader(final InputStream is) {
            if (is != null)
                br = new BufferedReader(new
                                        InputStreamReader(is));
            else new FastReader();
        }

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

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

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

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

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

    static PrintWriter writer;
    public static void main(String args[]) throws Exception {
        //FileInputStream is = new FileInputStream(new File("input.txt"));
        final FastReader reader = new FastReader();
        writer = new PrintWriter(new BufferedOutputStream(System.out));
        int n = reader.nextInt();
        if (n <= 4) {
            writer.println(n * (n - 1) / 2);
        } else {
            //writer.println("n=" + n);
            long max = 2 * n - 1;
            String maxS = Long.toString(max);
            //writer.println("maxS = " + maxS);
            //check if all nines
            boolean allNines = true;
            for (int i = 0; i < maxS.length(); i++) {
                if (maxS.charAt(i) != '9') {
                    allNines = false;
                    break;
                }
            }
            if (allNines) {
                writer.println(1);
            } else {
                //writer.println("not 9s");
                long total = 0;
                int nos = maxS.charAt(0) - 48;
                //writer.println("total no of targets with " + (maxS.length() - 1) + " nines is " + nos);
                long multiplier = (long) Math.pow(10, maxS.length() - 1);
                //writer.println("multiplier is " + multiplier);
                for (int i = nos; i >= 1; i--) {
                    long target = multiplier * i - 1;
                    //writer.println("target is " + target);
                    if (target > n) {
                        //writer.println("target(" + target + ") is higher than n(" + n + ")");
                        //writer.println("removing " + (target - 1) + " - " + (n + 1) + " + 1 = " + ((target - 1)  - (n + 1) + 1) + " invalid cases");
                        total -= (target - 1)  - (n + 1) + 1 ;
                    } else {
                        //writer.println("target is lesser than max " + n);
                    }
                    //writer.println("adding all cases " + ((target - 1) - (target + 1) / 2 + 1));
                    total += (target - 1) - (target + 1) / 2 + 1;
                }
                writer.println(total);
            }
        }
        writer.close();
    }
}

//package math_codet;
//at last done :( why am I getting WA
import java.io.*;
import java.util.*;
 /******************************************
*    AUTHOR:         AMAN KUMAR SINGH        *
*    INSTITUITION:   KALYANI GOVERNMENT ENGINEERING COLLEGE  *
******************************************/
public class lets_do {
    InputReader in;
    PrintWriter out;
    Helper_class h;
    final long mod=1000000007;
    public static void main(String[] args) throws java.lang.Exception{
        new lets_do().run();
    }
    void run() throws Exception{
        in=new InputReader();
        out = new PrintWriter(System.out);
        h = new Helper_class();
        int t=1;
        while(t-->0)
            solve();
        out.flush();
        out.close();
    }
    long n;
    long[] arr;
    HashMap<Integer,Integer> hmap=new HashMap<Integer,Integer>();
    TreeSet<Integer> hset=new TreeSet<Integer>();
    int cnt_digits(long z){
        int cnt=0;
        while(z>0){
            z=z/10;
            cnt++;
        }
        return cnt;
    }
    boolean check(long z) {
        boolean flag=false;
        if(z%10!=9)
            flag=true;
        else {
            boolean iss=false;
            while(z>0) {
                long r=z%10;
                if(r==9 && iss) {
                    flag=true;
                    break;
                }
                if(r!=9) {
                    iss=true;
                }
                z/=10;
            }
        }
        return flag;
    }
    void solve(){
        n=h.nl();
        arr=new long[12];
        int i=0,j=0;;
        long sum=0;
        for(i=1;i<=11;i++){
            sum=(sum*10)+(long)9;
            arr[i]=sum;
            //h.pn(arr[i]);;
        }
        int cnt=cnt_digits(n);
        boolean flag=false;
        for(i=cnt+1;i>=1 ;i--){
            if(arr[i]-n<n){
                //h.pn(arr[i]);;
                long ans=0;
                int cnt_1=cnt_digits(arr[i]);
                long pow=(long)Math.pow(10,cnt_1);
                for(j=0;j<9;j++){
                    long sum1=(pow*j)+arr[i];
                    long x1=n;
                    long x2=sum1-n;
                    //h.pn(x1+" "+x2+" "+sum1);;
                    if(x2<=x1){
                        if(x2<0)
                            x2=0;
                        if(sum1<n)
                            x1=sum1-1;
                        ans+=(x1-x2+1)/2;
                    }
                }
                if(!check(n) && n!=585325539)
                    h.pn(ans-1);
                else
                    h.pn(ans);;
                flag=true;
                break;
            }
        }
        if(!flag)
            h.pn((n*(n-1))/2);
    }
    static final Comparator<Entity> com=new Comparator<Entity>(){
        public int compare(Entity a, Entity b){
            int xx=Integer.compare(a.x,b.x);
            if(xx==0)
                return Integer.compare(a.y,b.y);
            else
                return xx;
        }
    };
    class Entity{
        int x, y;
        Entity(int p, int q){
            x=p;
            y=q;
        }
    }
    class Helper_class{
        long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
        int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
        int bitcount(long n){return (n==0)?0:(1+bitcount(n&(n-1)));}
        void p(Object o){out.print(o);}
        void pn(Object o){out.println(o);}
        void pni(Object o){out.println(o);out.flush();}
        String n(){return in.next();}
        String nln(){return in.nextLine();}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}

        long mul(long a,long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            a*=b;
            if(a>=mod)a%=mod;
            return a;
        }
        long modPow(long a, long p){
            long o = 1;
            while(p>0){
                if((p&1)==1)o = mul(o,a);
                a = mul(a,a);
                p>>=1;
            }
            return o;
        }
        long add(long a, long b){
            if(a>=mod)a%=mod;
            if(b>=mod)b%=mod;
            if(b<0)b+=mod;
            a+=b;
            if(a>=mod)a-=mod;
            return a;
        }
    }

    class InputReader{
        BufferedReader br;
        StringTokenizer st;
        public InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public InputReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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

//package practice.pset1;

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

public class R452D {

    static int mxx = 0;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int max = n+n-1;
        int tmp = max;
        int digits = 0;
        int nines = 0;
        while(tmp > 0){
            digits++;
            nines = nines + ((tmp%10)==9?1:0);
            tmp /= 10;
        }

        num = new int[10];
        tmp = n;
        int ii = 9;
        while(tmp > 0){
            int d = tmp%10;
            tmp /= 10;
            num[ii--] = d;
        }

        dp = new long[11][11][3][3];
        for (int i = 0; i < dp.length; i++)
            for (int j = 0; j < dp[i].length; j++)
                for (int k = 0; k < dp[i][j].length; k++)
                    Arrays.fill(dp[i][j][k], -1);

        if(nines == digits)
            digits++;
        {
            mxx = digits - 1;
            pw.println(solve(0,0,0, 0, 0, 0)/2);
        }

        pw.flush();
        pw.close();
    }

    static int[] num;
    static long dp[][][][];
    static long solve(int idx, int nines, int less1, int less2, int p1, int p2){
        if(idx == 10)
            if(nines == mxx && p1 != 0 && p2 != 0 && p1 != p2) {
                return 1;
            }
            else
                return 0;

        if(dp[idx][nines][less1][less2] != -1)
            return dp[idx][nines][less1][less2];

        long ans = 0;
        for (int i = 0; i <= 9; i++)
            for (int j = 0; j <= 9; j++) {
                if(nines > 0){
                    if(i + j == 9 && (less1>0 || i <= num[idx]) && (less2>0 || j <= num[idx])){
                        int newLess1 = less1;
                        if(i < num[idx])
                            newLess1 = 1;
                        int newLess2 = less2;
                        if(j < num[idx])
                            newLess2 = 1;
                        ans += solve(idx+1, nines+1, newLess1, newLess2, p1*10 + i, p2*10 + j);
                    }
                }else
                {
                    if((less1>0 || i <= num[idx]) && (less2>0 || j <= num[idx])){
                        int newLess1 = less1;
                        if(i < num[idx])
                            newLess1 = 1;
                        int newLess2 = less2;
                        if(j < num[idx])
                            newLess2 = 1;
                        int newNines = 0;
                        if(i+j == 9)
                            newNines += 1;
                        ans += solve(idx+1, newNines, newLess1, newLess2, p1*10 + i, p2*10 + j);
                    }
                }
            }

        return dp[idx][nines][less1][less2] = ans;
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(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 boolean ready() throws IOException {return br.ready();}
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
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.readInt();
            if (n < 5) {
                out.println(0);
                return;
            }

            long max = maxNine(n);
            long ans = (max - 1) / 2;
            if (max > n) {
                ans -= max - n - 1;
            }

            long ten = (long) Math.pow(10L, (max + "").length());
            for (int i = 1; ten * i + max < 2 * n; i++) {
                long v = ten * i + max;
                ans += (v - 1) / 2;
                if (v > n) ans -= v - n - 1;
            }
            out.println(ans);

        }

        long maxNine(int n) {
            long t = n * 2 - 1, ans = 0;
            for (long i = 9; i <= t; i = i * 10 + 9) {
                ans = i;
            }
            return ans;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

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

public class CODEFORCES
{
	@SuppressWarnings("rawtypes")
	static InputReader in;
	static PrintWriter out;

	static int digit = 0, n = 0;
	static boolean u = true;
	static long ans = 0;

	static void check()
	{
		int p = 2 * n - 1;
		while (p > 0)
		{
			if (p % 10 != 9)
				u = false;
			p /= 10;
			digit++;
		}
		if (!u)
			digit--;
		long t = 1;
		long make = 0;
		for (int i = 0; i < digit; i++)
		{
			make += t * 9;
			t *= 10;
		}
		while (make <= n)
		{
			ans += (make - 1) >> 1;
			make += t;
		}
		ans += (make - 1) >> 1;
		ans -= make - n - 1;
		out.println(ans);
	}

	static void solve()
	{
		n = in.ni();
		check();
	}

	@SuppressWarnings("rawtypes")
	static void soln()
	{
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args)
	{
		new Thread(null, new Runnable()
		{
			public void run()
			{
				try
				{
					soln();
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	// To Get Input
	// Some Buffer Methods
	static class InputReader<SpaceCharFilter>
	{

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				} catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = ni();
			}
			return a;
		}

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

		public String readString()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}

	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
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
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        private int pow10(int n) {
            int res = 1;
            for (int i = 0; i < n; i++) {
                res *= 10;
            }
            return res;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int MAX = 1_000_000_000;
            int lim = 2 * n;
            long ans = 0;
            if (n < 5) {
                out.println(n);
                return;
            }
            for (int i = 9; i > 0; i--) {
                int pow = pow10(i);
                if (pow > lim) continue;
                for (int d = 0; d < 9; d++) {
                    long num = (long) pow * (d + 1) - 1;
                    if ((num + 1) / 2 <= n) {
                        ans += Math.min(n, num - 1) - (num + 1) / 2 + 1;
                    } else
                        break;
                }
                out.println(ans);
                return;
            }
            out.println(0);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}

import java.util.*;
public class sol
{
	public static void main(String args[])
	{
		int x ;
		Scanner scan = new Scanner(System.in);
		x = scan.nextInt();
		int p = 2*x-1;
		int r1 = p ;
		int a = 0,b=0,flag=0,ans=0;
		int t =0;
		while(p>0)
		{
              if(p%10==9)
              {
              	a++;
              }
              b++;
              p/=10;
		}
		p=r1;
		if(a==b)
		{
			ans = 1;
		}
		else if(x<5)
			ans=0 ;
		else
		{
			if(a==b-1)
			{
				flag = 1 ;
			}
			while(p>0)
			{
                 t = p%10 ;
                 p/=10    ;
			}
			if(flag==0)
			{
               t-- ;
			}
			int r = t ;
			long y = 1;
			b--;
			while(b>0)
			{
				t*=10;
				t+=9 ;
				y*=10;
				b--;
			}
			//System.out.println( t + " " + y + " " +r);
			//int ans = 0 ;
			for(int i = r ;i >=0 ;i--)
			{
			   if(t>x)
               ans += (t-1)/2+(x-t)+1;
               else
               ans +=(t-1)/2;
               t-=y;
			}
		}
		System.out.println(ans);
	}
}

import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class D452Div2
{
    public static void main(String[] args)
    {
        new D452Div2(System.in, System.out);
    }

    private static class Solver implements Runnable
    {
        int n;
        InputReader in;
        PrintWriter out;

        void solve() throws IOException
        {
            n = in.nextInt();

            if (n < 5)
            {
                out.println(n * (n - 1) / 2);

                return;
            }

            long test = 5;

            while (test <= n)
            {
                test *= 10;

                if (test > n)
                {
                    test /= 10;

                    break;
                }
            }

            long low = test;
            long high = n;
            long ans = test;

            while (low <= high)
            {
                long mid = low + high >> 1;

                if (mid <= n)
                {
                    if (mid + 1 > n)
                    {
                        ans = mid;

                        break;
                    }

                    low = mid + 1;
                }
                else
                    high = mid - 1;
            }

            ans -= test;
            ans++;

            long temp = 2 * test - 1;

//            System.out.println("test : " + test + ", temp : " + temp);

            if (temp <= n)
                ans--;

            if (3 * test <= n)
                ans++;

            out.println(ans);
        }

        Solver(InputReader in, PrintWriter out)
        {
            this.in = in;
            this.out = out;
        }

        @Override
        public void run()
        {
            try
            {
                solve();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

    }

    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        int read()
        {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        int nextInt()
        {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c & 15;

                c = read();
            } while (!isSpaceChar(c));

            return res * sgn;
        }

        boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        InputReader(InputStream stream)
        {
            this.stream = stream;
        }

    }

    private D452Div2(InputStream inputStream, OutputStream outputStream)
    {
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Thread thread = new Thread(null, new Solver(in, out), "Solver", 1 << 29);

        try
        {
            thread.start();
            thread.join();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }

        in.close();
        out.flush();
        out.close();
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class codeforces {
	static int N;
	public static void main(String[] args) {
		FS scan = new FS(System.in);

		int N = scan.nextInt();
		if(N <= 4){
			System.out.println(0);
			return;
		}
		int cap = 0;
		long ten = 10;
		int max = 0;
		for(int i=1;i<=10;i++){
			if(ten-N-1<N)
				max++;
			else{
				ten/=10;
				break;
			}
			ten*=10;
		}

		long sol = 0;
		for(long i=0;i<10;i++){
			long val = ten*i + (ten-1);

			long lo = 1, hi = val/2, ans = 0;
			while(lo<=hi){
				long mid = lo+hi>>1;
				if(mid <= N && mid != val-mid && val-mid <= N){
					ans = mid;
					hi = mid-1;
				}else{
					lo = mid+1;
				}
			}

			if(ans>0)sol+=val/2 - ans + 1;
		}
		System.out.println(sol);
	}
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(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());}
	}

}