PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000180. Dãy các nhóm số (Number Sequence)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy các nhóm số (Number Sequence)

Number Sequence

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Define digit strings S1,S2,S3,…S_1,S_2,S_3,\ldots. The group SkS_k is formed by writing the integers 1,2,…,k1,2,\ldots,k consecutively, with no separators.

For example, S1=1S_1=\texttt{1}, S2=12S_2=\texttt{12}, S3=123S_3=\texttt{123}, and S10=12345678910S_{10}=\texttt{12345678910}.

Concatenate the groups in order to obtain the infinite digit sequence S1S2S3⋯S_1S_2S_3\cdots. No characters are inserted between groups.

Given a positive integer ii, determine the digit at one-based position ii of this infinite sequence. Print exactly one digit, rather than the whole integer containing that digit.

Input

  • The only line contains the integer ii, the one-based position of the requested digit.

Output

Print one digit character from 0 to 9: the digit at position ii.

Subtasks

  • Subtask 1 (20 points): 1≤i≤10001\le i\le 1000.
  • Subtask 2 (30 points): 1≤i≤10000001\le i\le 1000000.
  • Subtask 3 (50 points): 1≤i≤21474836471\le i\le 2147483647.

Examples

Example 1

Input

8

Output

2

Explanation

The first groups are S1=1S_1=\texttt{1}, S2=12S_2=\texttt{12}, S3=123S_3=\texttt{123}, and S4=1234S_4=\texttt{1234}. The first three groups contain 1+2+3=61+2+3=6 digits. Position 88 is the (8−6)(8-6)-th digit inside S4S_4. The second digit of 1234 is 2.

Example 2

Input

3

Output

2

Explanation

S1S_1 contributes digit 1. The next group S2=12S_2=\texttt{12} occupies positions 22 and 33. Thus the third overall digit is the second digit of 12, namely 2.