All problems

Problem 359

Nth Digit of the Integer Sequence

Medium · 20 pts · Math, Binary Search

Problem

Write all positive integers one after another without spaces: 123456789101112131415... Print the N-th digit of this infinite string (counting from 1). The one-digit numbers fill the first 9 digits, the two-digit numbers the next 90 · 2 = 180 digits, the three-digit numbers the next 900 · 3 digits, and so on, so you can find which number contains the N-th digit without building the string.

Input

A single integer N.

Output

Print the N-th digit.

Constraints

1 <= N <= 2147483647

Example input

11

Example output

0

Explanation

The string starts 1 2 3 4 5 6 7 8 9 1 0 1 1 ... The 11th digit is the 0 of the number 10.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Bulb Switcher Next: Solve Two Congruences