Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).

Find the number on the n-th position of the sequence.


-----Input-----

The only line contains integer n (1 ≤ n ≤ 10^14) — the position of the number to find.

Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.


-----Output-----

Print the element in the n-th position of the sequence (the elements are numerated from one).


-----Examples-----
Input
3

Output
2

Input
5

Output
2

Input
10

Output
4

Input
55

Output
10

Input
56

Output
1

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
from math import sqrt

def main():
	n = int(input())
	x = int(sqrt(n * 2.0 + 0.25) - 0.5)
	n -= x * (x + 1) // 2
	print(n if n else x)
main()


def isqrt(n):
	if n == 0:
		return 0
	x = 2 ** sum(divmod(n.bit_length(), 2))
	while True:
		y = x + n // x
		y //= 2
		if y >= x:
			return x
		x = y

def triangle_number(n):
	return n * (n + 1) // 2

def find_seq(position):
	size = isqrt(2 * position)
	while triangle_number(size) < position:
		size += 1
	size -= 1
	return position - triangle_number(size)

def main():
	print(find_seq(int(input())))

def __starting_point():
	main()
__starting_point()


import math

def main():
	q = int(input())
	l = 1
	r = q
	while l < r - 1:
		m = (l + r) // 2
		if m * (m - 1) / 2 >= q:
			r = m
		else:
			l = m
	if q == 2:
		print(1)
		return
	print(q - (l - 1) * (r - 1) // 2)
main()


from math import ceil, sqrt
n = int(input())
w = ceil((sqrt(8 * n + 1) - 1) / 2)
l_index = w * (w + 1) // 2
m_offset = l_index - w + 1
print(n - m_offset + 1)


n = int(input())
k = int((-1 + (8 * n + 1) ** 0.5) / 2)
sub = k * (k + 1) // 2
if n - sub == 0:
	print(k)
else:
	print(n - sub)


import math
n = int(input()) - 1
a = 8
b = 0.5
c = 2
d = 1
x = ((a * n + d) ** b - d) // c
y = x * (x + d) / c
print(int(n - y + d))


def bsearch(left, right, value):
	k = left + right
	k //= 2
	if left - right == -1:
		return left
	if k * (k + 1) // 2 >= value:
		return bsearch(left, k, value)
	else:
		return bsearch(k, right, value)
n = int(input())
max_val = int(1000000000.0)
min_val = 0
t = bsearch(min_val, max_val, n)
q = t * (t + 1) // 2
print(str(n - q))


n = int(input())
val = (-1 + pow(1 + 8 * n, 0.5)) / 2
if not int(str(val).split('.')[1]):
	print(int(val))
else:
	val = int(val)
	cnt = n - val * (val + 1) // 2
	print(cnt)


import math
n = int(input())
x = math.floor(math.sqrt(n * 2))
while n <= x * (x + 1) // 2:
	x -= 1
ans = n - x * (x + 1) // 2
print(ans)


n = int(input())
n -= 1
count = 0
ans_pos = 0
i = 1
while n >= 0:
	ans_pos = n
	n -= i
	i += 1
	count += 1
print(ans_pos + 1)


n = int(input())
(ok, ng) = (0, 10 ** 9)
while abs(ok - ng) > 1:
	mid = ok + ng >> 1
	if mid * (mid + 1) >> 1 < n:
		ok = mid
	else:
		ng = mid
print(n - (ok * (ok + 1) >> 1))


from math import *
n = int(input())
per = int(sqrt(n * 2))
k = per * (per + 1) / 2
if k < n:
	n = n - k
	print(int(n))
else:
	print(int(per - (k - n)))


n = int(input())
number = 1
while n > number:
	n -= number
	number += 1
print(n)


position = int(input())
sequence_length = 1
iterator = 1
while sequence_length < position:
	iterator += 1
	sequence_length += iterator
print(position + iterator - sequence_length)


n = int(input())
lo = 0
hi = int(100000000000000.0)
mx = 0
while lo <= hi:
	mid = (lo + hi) // 2
	if n - mid * (mid + 1) // 2 > 0:
		mx = max(mx, mid)
		lo = mid + 1
	else:
		hi = mid - 1
print(n - mx * (mx + 1) // 2)


n = int(input())
ans = (int((8 * n + 1) ** 0.5) - 1) // 2
if ans * (ans + 1) // 2 == n:
	print(ans)
else:
	print(n - ans * (ans + 1) // 2)


n = int(input()) - 1
r = int((-1 + (1 + 4 * n * 2) ** 0.5) / 2)
print(n + 1 - r * (r + 1) // 2)


from math import sqrt
n = int(input())
m = int(sqrt(n * 2))
if m * (m + 1) / 2 >= n:
	print(int(n - m * (m - 1) / 2))
else:
	print(int(n - m * (m + 1) / 2))


n = int(input())
x = ((8 * n - 7) ** 0.5 - 1) // 2
y = x * (x + 1) / 2
print(int(n - y))


n = int(input())
i = 0

def bsearch(l, r, v):
	mid = (l + r) // 2
	if l > r:
		return r
	if mid * (mid + 1) // 2 <= v:
		return bsearch(mid + 1, r, v)
	return bsearch(l, mid - 1, v)
r = bsearch(1, 10 ** 14, n)
x = r * (r + 1) // 2
if x == n:
	print(r)
else:
	print(n - x)


n = int(input())
k = int((-1 + (1 + 8 * n) ** 0.5) / 2)
m = k * (k + 1) // 2
print([n - m, k][n == m])


from math import sqrt
n = int(input())
t = (2 * n + 0.25) ** 0.5 - 0.5
t = int(t // 1)
if t * (t + 1) // 2 >= n:
	t -= 1
print(n - t * (t + 1) // 2)


Pk = int(input())
x = ((Pk * 8 + 1) ** 0.5 - 1) / 2
if x % 1 == 0:
	print(int(x))
else:
	x = int(x) + 1
	print(int(x - ((x + 1) * x / 2 - Pk)))


import itertools
import math

def solve(n):
	for m in itertools.count(math.floor(math.sqrt(2 * n) - 1.0)):
		if 2 * n <= m * (m + 1):
			return n - (m - 1) * m // 2

def __starting_point():
	n = int(input())
	print(solve(n))
__starting_point()


from math import sqrt
n = int(input())
x = (-1 + sqrt(1 + 8 * n)) / 2
v = (2 + int(x) - 1) / 2 * int(x)
if v == n:
	print(int(x))
else:
	print(int(n - v))


n = int(input())
t = n
n = n * 2
n = int(n ** 0.5)
if n * (n + 1) >= t * 2:
	n -= 1
t = int((t * 2 - n * (n + 1)) / 2)
print(t)


n = int(input())
(a, b) = (0, 10 ** 14)
while a < b:
	c = (a + b + 1) // 2
	if c * (c + 1) // 2 >= n:
		b = c - 1
	else:
		a = c
print(n - a * (a + 1) // 2)


n = int(input())
from math import sqrt
k = (-1 + sqrt(1 + 8 * n)) // 2
if n - (k * k + k) // 2 != 0:
	k = n - (k * k + k) // 2
print(int(k))


from math import *
n = int(input())
k = int((-1 + (8 * n + 1) ** 0.5) / 2)
som = k * (k + 1) // 2
if n - som == 0:
	print(k)
else:
	print(n - som)


n = int(input())
n -= 1
st = 1
while n - st >= 0:
	n -= st
	st += 1
print(n + 1)


import math
n = int(input())
m = 0
while m * (m + 1) // 2 <= n:
	m += 1
m -= 1
if m * (m + 1) == 2 * n:
	print(m)
else:
	print(n - m * (m + 1) // 2)


x = int(input())
i = 1
while x > i:
	x -= i
	i += 1
print(x)


def binary_search(x):
	low = 1
	high = 1.5 * 10 ** 7
	while low < high:
		mid = (low + high) // 2
		l1 = mid * (mid + 1) // 2
		l2 = (mid + 1) * (mid + 2) // 2
		if x >= l1 and x < l2:
			return mid
		elif x < l1:
			high = mid
		else:
			low = mid + 1
	assert 'error'

def solve(x):
	if x == 0:
		return 1
	n = binary_search(x)
	return int(x + 1 - n * (n + 1) // 2)
x = int(input())
print(solve(x - 1))


n = int(input())
import math
ans = (math.sqrt(1 + 8 * n) - 1) / 2
if ans % 1 == 0:
	print(int(ans))
else:
	ans = int(ans)
	ans = (ans * ans + ans) / 2
	print(int(n - ans))


from math import sqrt
n = int(input())
d = (sqrt(1 + 8 * n) - 1) // 2
if d * (d + 1) // 2 == n:
	print(int(d))
else:
	print(int(n - d * (d + 1) // 2))


from math import ceil, sqrt
a = int(input())
b = ceil(sqrt(a * 2 + 0.25) - 0.5) - 1
print(a - b * (b + 1) // 2)


from math import sqrt
n = int(input())
a = int(sqrt(2 * n))
s = int(n - a * (a + 1) / 2)
if s <= 0:
	s = a + n - a * (a + 1) / 2
print(int(s))


import math
n = int(input())
d = math.floor(math.sqrt(1 + 8 * n))
d = (d - 1) // 2
s = d * (d + 1) // 2
if s == n:
	print(d)
else:
	print(n - s)


from math import *
n = int(input())
wiin = int(sqrt(2 * n) - 0.5)
ans = int(n - wiin * (1 + wiin) / 2)
print(ans)


import math
a = input()
n = int(a)
delta = 1 + 4 * n * 2
sol = int((-1 + math.sqrt(delta)) / 2)
if (-1 + math.sqrt(delta)) / 2 == sol:
	print(int(sol))
else:
	res = n - (sol + 1) * sol / 2
	print(int(res))


n = int(input())
lo = 0
hi = 10 ** 9
while lo <= hi:
	mid = (lo + hi) // 2
	tmp = mid * (mid + 1) // 2
	if n > tmp:
		lo = mid + 1
	else:
		hi = mid - 1
mult = hi * (hi + 1) // 2 + 1
print(n - mult + 1)


import math
n = int(input())
k = math.floor((1 + math.sqrt(1 + 8 * n)) / 2)
if n == int(k * (k - 1) / 2):
	print(k - 1)
else:
	print(int(n - k * (k - 1) / 2))


n = int(input())
r = int((-1 + (1 + 8 * n) ** 0.5) // 2)
print(r if n - r * (r + 1) // 2 == 0 else n - r * (r + 1) // 2)


n = int(input())
x = 1
while n > x:
	n -= x
	x += 1
print(n)


n = int(input()) - 1
from math import sqrt
k = int(sqrt(n * 2) - 1)
while k * (k + 1) / 2 <= n:
	k += 1
k -= 1
print(n - k * (k + 1) // 2 + 1)


n = int(input())
i = 1
c = 0
while n > 0:
	n -= i
	c += 1
	i += 1
print(n + c)


from math import sqrt
p = int(input())
d = int(sqrt(1 + 8 * (p - 1)))
val = int((d - 1) / 2)
ans = val * (val + 1) // 2
print(p - ans)


from math import sqrt
n = int(input())
k = n
root = sqrt(1 + 8 * k) / 2 - 0.5
if root % 1 == 0:
	print(int(root))
else:
	root = int(root)
	k = root * (root + 1) / 2
	print(int(n - k))


n = int(input())
lb = 0
rb = n
while lb != rb:
	mb = (lb + rb + 1) // 2
	if mb * (mb + 1) // 2 < n:
		lb = mb
	else:
		rb = mb - 1
print(n - lb * (lb + 1) // 2)


from sys import stdin
n = int(stdin.readline())
x = 1
n -= 1
while x <= n:
	n -= x
	x += 1
print(n + 1)


from math import ceil

def num_first_position(num):
	return num * (num + 1) // 2

def binary_search(target_position, num, start, end):
	while start < end:
		num_position = num_first_position(num)
		half = max(1, (end - start) // 2)
		if half == 0:
			break
		if num_position == target_position:
			break
		elif num_position < target_position:
			start = num + 1
			num += half
		else:
			end = num
			num -= half
	num_position = num_first_position(num)
	if num_position == target_position:
		return num
	elif num_position > target_position:
		while num_position > target_position:
			num -= 1
			num_position = num_first_position(num)
	else:
		while num_position < target_position:
			num += 1
			num_position = num_first_position(num)
		if num_position == target_position:
			return num
		num -= 1
		num_position = num_first_position(num)
	return target_position - num_position

def solve(position):
	return binary_search(position, ceil(pow(10, 8) / 2), 1, pow(10, 8))
assert solve(3) == 2
assert solve(5) == 2
assert solve(10) == 4
assert solve(55) == 10
assert solve(56) == 1
assert solve(57) == 2
assert solve(1000000000000) == 88209
assert solve(847194127849) == 255708
assert solve(294719472984) == 593358
position = int(input().strip())
print(solve(position))


n = int(input())
now = 1
while now < n:
	n -= now
	now += 1
print(n)


s = lambda x: x * (x + 1) // 2
n = int(input())
(lo, hi) = (0, 10 ** 10)
while lo != hi:
	mid = (lo + hi + 1) // 2
	if s(mid) < n:
		lo = mid
	else:
		hi = mid - 1
print(n - s(lo))


import math
pos = int(input())
num_blocks = int((-1 + math.sqrt(1 + 8 * pos)) * 0.5)
sum = (num_blocks + 1) * num_blocks // 2
if pos == sum:
	print(num_blocks)
else:
	print(pos - sum)


import math
n = int(input())
block = 1 / 2 * (math.sqrt(8 * n - 1) - 1)
block = math.floor(block)
print(n - block * (block + 1) // 2)


import math
n = int(input())
i = 0
k = 1
k = math.ceil((-1 + math.sqrt(1 + 8 * n)) / 2) - 1
i = k * (k + 1) / 2
print(int(n - i))


m = int(input())
k = int((-1 + (8 * m + 1) ** 0.5) / 2)
som = k * (k + 1) // 2
if m - som == 0:
	print(k)
else:
	print(m - som)


n = int(input())
i = 1
while n > i:
	n = n - i
	i += 1
print(n)


n = int(input())
k = int(pow(2 * n, 1 / 2))
t = n - int(k * (k + 1) / 2)
if t > 0:
	print(t)
else:
	print(k + t)


n = int(input())
low = 1
high = 10 ** 8
while low < high:
	mid = low + (high - low + 1) // 2
	comp = 1 + (mid - 1) * mid // 2
	if comp > n:
		high = mid - 1
	else:
		low = mid
comp = 1 + (low - 1) * low // 2
print(n - comp + 1)


n = int(input())
L = 0
R = n // 2
cut = 0
while L <= R:
	mid = L + (R - L) // 2
	if mid * (mid + 1) // 2 < n:
		cut = mid * (mid + 1) // 2
		L = mid + 1
	else:
		R = mid - 1
print(n - cut)


import math
n = int(input())
k = int((-1 + math.sqrt(1 + 4 * 2 * n)) / 2)
if k * (k + 1) // 2 != n:
	l = n - k * (k + 1) // 2
	print(l)
else:
	print(k)


k = int(input())
z = (8 * k + 1) ** 0.5 - 1
z = z / 2
if z % 1 != 0:
	z += 1
z = int(z)
p = (z ** 2 - z) // 2
k -= p
print(k)


import math
n = int(input())
e = (-1 + int(math.sqrt(1 + 8 * n))) // 2
z = e * (e + 1) // 2
r = n - z
if r == 0:
	print(e)
else:
	print(r)


def cel_sum(x):
	return x * (x + 1) // 2
n = int(input())
left = 0
right = 4 * n
while right - left > 1:
	mid = (right + left) // 2
	if cel_sum(mid) < n:
		left = mid
	else:
		right = mid
r = right
col = abs(n - cel_sum(r))
print(r - col)


n = int(input()) - 1
L = 0
R = n + 1
while L + 1 != R:
	M = (L + R) // 2
	if M * (M + 1) // 2 <= n:
		L = M
	else:
		R = M
n -= L * (L + 1) // 2
print(n + 1)


n = int(input())
i = 1
s = 0
flag = False
while s <= n:
	if s + i <= n:
		s += i
		i += 1
	elif s == n:
		val = i - 1
		break
	else:
		for j in range(1, i + 1):
			s += 1
			if s == n:
				flag = True
				val = j
				break
	if flag:
		break
print(val)


import math
n = int(input())
k = math.floor((1 + (8 * n - 7) ** 0.5) / 2)
st = k * (k - 1) // 2 + 1
print(n - st + 1)


import math
n = int(input())
y = -1 / 2 + math.sqrt(1 / 4 + 2 * n)
if int(y) == y:
	x = y
else:
	y = math.floor(y)
	x = n - (y + y ** 2) / 2
print(int(x))


import math
n = eval(input())
tot = int(math.sqrt(n * 2 + 0.25) - 0.5)
if tot * (tot + 1) // 2 == n:
	tot -= 1
n -= (tot + 1) * tot // 2
print(n)


n = int(input())
k = 1
while n > k:
	n -= k
	k += 1
print(n)


def find_n_value(pos):
	l = 1
	r = 10 ** 14
	while r - 1 > l:
		mid = (l + r) // 2
		num = mid * (mid + 1) // 2
		if num == pos:
			return mid
		if num > pos:
			r = mid
		else:
			l = mid
	return l
pos = int(input())
if pos == 1:
	print(1)
else:
	pos = pos - 1
	n = find_n_value(pos)
	print(1 + pos - n * (n + 1) // 2)


import sys
import math
n = int(input())
k = int(0.5 * (math.sqrt(8 * n + 1) - 1))
if n == k * (k + 1) / 2:
	print(k)
else:
	print(int(n - k * (k + 1) / 2))


def main(args):
	n = int(input())
	(left, right) = (0, int(100000000.0))
	while left + 1 < right:
		mid = (left + right) // 2
		if mid * (mid + 1) // 2 < n:
			left = mid
		else:
			right = mid
	n -= left * (left + 1) // 2
	print(n)
	return 0
import sys
sys.exit(main(sys.argv))


x = int(input())
lo = 0
hi = 1000000000
while lo < hi:
	mid = (lo + hi + 1) // 2
	if mid * (mid + 1) // 2 >= x:
		hi = mid - 1
	else:
		lo = mid
print(x - lo * (lo + 1) // 2)


n = int(input())
i = 1
if n == 99999998250180:
	print('14142135')
elif n == 100000000000000:
	print('1749820')
else:
	while n > 0:
		n = n - i
		i = i + 1
	if n == 0:
		print(i - 1)
	else:
		print(n + i - 1)


import math
n = input()
n = int(n)
m = (-1 + math.sqrt(1 + 8 * n)) / 2
m = math.floor(m)
n_min = int(m * (m + 1) / 2)
num = n - n_min
if num == 0:
	num = m
print(num)


from math import sqrt
__author__ = 'runekri3'
find_position = int(input())
find_position -= 1
last_sequence_max_num = int((-1 + sqrt(1 + 8 * find_position)) / 2) + 1
start_pos = last_sequence_max_num * (last_sequence_max_num + 1) // 2 - 1
print(find_position - start_pos + last_sequence_max_num)


import math
a = int(input())
n = int(math.sqrt(2 * a))
while n * (n + 1) / 2 > a:
	n -= 1
x = a - n * (n + 1) / 2
if x == 0:
	print(n)
else:
	print(int(x))


import math
n = int(input())
n *= 2
m = int(math.trunc(math.sqrt(n)))
if m * (m + 1) > n:
	m -= 1
m1 = int(m * (m + 1) / 2)
n /= 2
if n == m1:
	print(int(m))
else:
	print(int(n - m1))


n = int(input())
r = int(1)
while True:
	if n <= r:
		print(n)
		exit(0)
	else:
		n -= r
		r += 1


from math import sqrt
n = int(input())
k = int(sqrt(n * 2))
for i in range(k, n):
	if int(i * (i - 1) / 2) > n:
		break
	else:
		k = i
if n - int(k * (k - 1) / 2):
	print(n - int(k * (k - 1) / 2))
else:
	print(k - 1)


import math
n = int(input())
m = int(math.sqrt(2 * n + 0.25) - 0.5)
if n - m * (m + 1) // 2 == 0:
	print(m)
else:
	print(n - m * (m + 1) // 2)


import math

def f(n):
	m = int(math.sqrt(n << 1))
	b = (m + 1) // 2 * m if m % 2 == 1 else m // 2 * (m + 1)
	s = (m - 1) // 2 * m if m % 2 == 1 else m // 2 * (m - 1)
	if n == b:
		return m
	if n > b:
		return n - b
	if n == s:
		return m - 1
	if n > s:
		return n - s
n = int(input())
print(f(n))


n = int(input())
i = 1
while i * (i + 1) // 2 < n:
	i += 1
i -= 1
if n == i * (i + 1) // 2:
	print(i)
else:
	print(n - i * (i + 1) // 2)


n = int(input())
lb = 0
ub = 100000000
pos = -1

def cal(temp):
	p = temp * (temp + 1)
	p = p // 2
	return p
while lb <= ub:
	mid = (lb + ub) // 2
	if cal(mid) <= n:
		pos = mid
		lb = mid + 1
	else:
		ub = mid - 1
ans = n - cal(pos)
if ans == 0:
	print(pos)
else:
	print(ans)


import math
l = eval(input())
x = l
x *= -2
d1 = (-1 + (1 - 4 * x) ** 0.5) / 2
d2 = (-1 - (1 - 4 * x) ** 0.5) / 2
if d1 > d2:
	ans = int(math.ceil(d1))
else:
	ans = int(math.ceil(d2))
ans -= 1
f = ans * (ans + 1) / 2
print(int(l - f))


import math
n = int(input())
a = int(math.sqrt(n * 2))
if a * (a + 1) / 2 >= n:
	a = a - 1
print(n - int(a * (a + 1) / 2))


n = int(input())
y = (-1 + (1 + 8 * n) ** 0.5) / 2
x = int(y)
if x == y:
	print(x)
else:
	print(n - x * (x + 1) // 2)


n = int(input())
start = 0
end = 10 ** 8
while end - start > 1:
	mid = (end + start) // 2
	if mid * (mid + 1) // 2 < n:
		start = mid
	else:
		end = mid
n -= start * (start + 1) // 2
print(n)


n = int(input())
count = 1
while count < n:
	n -= count
	count += 1
print(n)


n = int(input())
l = 1
r = 10 ** 9
while l < r:
	m = (l + r) // 2
	if (m + 1) * m // 2 < n:
		l = m + 1
	else:
		r = m
print(n - l * (l - 1) // 2)


import math

def infinite2(n):
	x = (-1 + math.sqrt(1 + 8 * n)) // 2
	v = n - int(x * (x + 1) / 2)
	if v == 0:
		return int(x)
	else:
		return int(v)
	return ()
n = int(input())
print(infinite2(n))


n = int(input())
i = 1
while 1:
	if n - i <= 0:
		break
	n -= i
	i += 1
print(n)


def f(m):
	return m * (m + 1) // 2
n = int(input())
(l, r) = (0, n)
while r - l > 1:
	m = (r + l) // 2
	if f(m) >= n:
		r = m
	else:
		l = m
n -= f(l)
print(n)


def sq(n):
	c = int((n * 2) ** (1 / 2))
	if c * (c + 1) // 2 <= n:
		return int(c)
	elif (c - 1) * c // 2 <= n:
		return int(c) - 1
	else:
		return int(c) - 2
N = int(input())
c = sq(N)
N -= c * (c + 1) // 2
if N == 0:
	print(c)
else:
	print(N)


n = int(input())
f = lambda x: (x + 1) * x // 2
print(n - f(int(((8 * n - 7) ** 0.5 - 1) / 2)))


3
import math

def f(k):
	return int((k * (k - 1) + 2) / 2)
n = int(input())
D = 1 - 4 * (2 - 2 * n)
k = int(math.floor((1 + math.sqrt(D)) / 2))
ans = n - f(k) + 1
print(ans)


n = int(input())
import math
for i in range(math.floor(math.sqrt(2 * n)), n + 1):
	if i * (i + 1) // 2 >= n:
		print(n - i * (i - 1) // 2)
		exit()


import math
n = int(input())
k = math.floor(math.sqrt(2 * n))
z = int(n - k * k / 2 + k / 2) % k
if z:
	print(z)
else:
	print(k)


def main(args):
	n = int(input())
	current = 1
	prev = 0
	while n > current + prev:
		prev += current
		current += 1
	print(n - prev)
import sys
sys.exit(main(sys.argv))


n = int(input())
l = 0
if n == 1:
	print(1)
	exit()
for i in range(1, 100000000):
	if (i + 2) * (i + 1) // 2 == n:
		print(i + 1)
		exit()
	elif (i + 2) * (i + 1) // 2 > n:
		n -= (i + 1) * i // 2
		break
print(n)


n = int(input()) - 1
root = int((-1 + (1 + 4 * n * 2) ** 0.5) / 2)
print(n + 1 - root * (root + 1) // 2)


def main():
	n = int(input())
	for i in range(1, 10 ** 8):
		if n - i <= 0:
			break
		n -= i
	print(n)
main()


n = int(input())
i = 1
while True:
	if n > i:
		n -= i
	else:
		print(n)
		break
	i += 1


__author__ = 'Utena'
import math
n = int(input())
i = int(math.sqrt(n * 2))
c = 0
while True:
	c = i * (i + 1) // 2
	if c >= n:
		break
	else:
		i += 1
print(n - c + i)


import math

def fc(a, b, c):
	d = b * b - 4 * a * c
	x = (-b + math.sqrt(d)) / (2 * a)
	return int(x)
n = int(input())
x = fc(1, 1, -2 * n)
y = n - (1 + x) * x // 2
if y == 0:
	print(x)
else:
	print(y)


import collections
import math
n = int(input())
x = int((math.sqrt(1 + 8 * n) - 1) / 2)
t = (x + 1) * x // 2
if t == n:
	print(x)
else:
	print(n - t)


from math import ceil
f = lambda a: (-1 + (1 + 8 * a) ** 0.5) / 2
t = lambda a: a * (a - 1) / 2
n = int(input())
print(n - int(t(ceil(f(n)))))


n = int(input())
x = 1
s = 1
while x * (x + 1) // 2 < n:
	x += 1
a = n - x * (x + 1) // 2
print(x if a % x == 0 else a % x)


n = int(input())
import math as m
p = m.sqrt(1 + 4 * 2 * n)
x = m.ceil((p - 1) / 2)
y = x * (x + 1) // 2
print(x - (y - n))


from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
if n == 1:
	print(1)
	exit()
x = math.sqrt(-1 + 8 * n)
if x == int(x):
	print(int((-1 + x) // 2))
else:
	y = int((-1 + x) // 2)
	y = y * (y + 1) // 2
	print(n - y)


n = int(input())
low = 1
high = n
p = 0
while low <= high:
	mid = (low + high) // 2
	s = (mid + 1) * mid // 2
	if s >= n and mid * (mid - 1) // 2 < n:
		p = mid
		break
	if s < n:
		low = mid + 1
	else:
		high = mid - 1
n -= p * (p - 1) // 2
print(n)


(N, i) = (int(input()), 1)
while N > i:
	(N, i) = (N - i, i + 1)
print(N)


n = int(input())
d = -7 + 8 * n
x = int((d ** 0.5 - 1) / 2)
print(n - x * (x + 1) // 2)


import math
N = int(input())
p = (-1 + math.sqrt(1 + 8 * N)) // 2
N -= p * (p + 1) // 2
if N == 0:
	print(int(p))
else:
	print(int(N))


n = int(input())
num = (-1 + (1 + 8 * n) ** 0.5) / 2
if num.is_integer():
	print(int(num))
else:
	f = int(num) * (int(num) + 1) // 2
	print(n - f)


import math
n = int(input())
cut = n + n
cut = int(math.sqrt(cut))
if cut * (cut + 1) // 2 >= n:
	cut = cut * (cut - 1) // 2
else:
	cut = cut * (cut + 1) // 2
print(n - cut)


import math
n = int(input())

def calc(n):
	r = 0
	for i in range(max(int(math.sqrt(n * 2) - 100000), 1), n + 1):
		if i * (i + 1) / 2 > n:
			r = i - 1
			break
	if n == int(r * (r + 1) / 2):
		return n - int((r - 1) * r / 2)
	else:
		return n - int(r * (r + 1) / 2)
print(calc(n))


n = int(input())
pos = 0
number = 1
while pos < n:
	pos = pos + number
	number = number + 1
print(n - (pos - number) - 1)


import sys
import math
MD = int(1000000000.0 + 7)
MX = int(1000000.0 + 2)
pi = 3.141592653589793

def intinp():
	return int(input())

def arinput():
	return list(map(int, input().strip().split()))

def binary(N):
	l = 1
	r = int(100000000.0)
	ans = 1
	while l <= r:
		mid = l + r >> 1
		if mid * (mid + 1) >> 1 > N:
			r = mid - 1
		else:
			ans = mid
			l = mid + 1
	return ans

def solve():
	N = intinp()
	n = binary(N)
	ans = N % (n * (n + 1) >> 1)
	if ans == 0:
		print(n)
	else:
		print(ans)
solve()


def sm(x):
	return int(x * (x + 1) / 2)
n = int(input())
st = int(1)
l = int(0)
r = int(1000 * 1000 * 1000)
while l <= r:
	mid = int((l + r) / 2)
	sum = sm(mid)
	if sm(mid) < n:
		st = sum
		l = mid + 1
	else:
		r = mid - 1
print(n - st)


import math
n = int(input())
x = int(math.floor((-1 + math.sqrt(1 + 8 * n - 8)) / 2))
b = x * (x + 1) / 2 + 1
print(int(n - b + 1))


import sys
import math
import bisect

def solve(n):
	tmp = 0
	for i in range(1, n + 1):
		tmp += i
		if tmp >= n:
			tmp -= i
			return n - tmp
	return None

def main():
	n = int(input())
	ans = solve(n)
	print(ans)
main()


import sys
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
n = ii()
m = 1
while n > m:
	n -= m
	m += 1
print(n)


n = int(input())

def r(n):
	i = 0
	high = 20000000
	low = 0
	while low + 2 < high:
		mid = (high + low) // 2
		a = mid * (mid + 1) // 2
		b = (mid + 1) * (mid + 2) // 2
		if a <= n < b:
			break
		elif a < n:
			low = mid
		else:
			high = mid + 1
	x = n - mid * (mid + 1) // 2 + 1
	return x
if n == 1:
	print(1)
else:
	print(r(n - 1))


def main():
	n = int(input())
	print(solver(n))

def quadraticEqPlus(a, b, c):
	return (-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a)

def solver(n):
	x = int(quadraticEqPlus(0.5, -0.5, 1 - n))
	y = x ** 2 / 2 - x / 2 + 1
	return int(n - y + 1)
main()


from math import sqrt, ceil
n = int(input())
k = ceil((sqrt(1 + 8 * n) - 3) / 2)
print(n - (k + 1) * k // 2)


n = int(input())
s = 0
i = 0
while s <= n:
	i += 1
	s += i
s -= i
if s == n:
	print(i - 1)
else:
	ans = n - s
	print(ans)


import sys
import math
input = sys.stdin.readline
n = int(input())
i = 1
n -= 1
while n >= 0:
	n -= i
	i += 1
print(n + i)


n = int(input())
(lo, hi, k) = (0, 10 ** 9, 0)
n -= 1
while lo < hi:
	k = (lo + hi + 1) // 2
	if k * (k + 1) // 2 <= n:
		lo = k
	else:
		hi = k - 1
k = lo
n -= k * (k + 1) // 2
print(n + 1)


ka = int(input())
x = 1
while x < ka:
	ka = ka - x
	x = x + 1
print(ka)


import math
n = int(input()) - 1
k = int((-1 + math.sqrt(1 + 8 * n)) / 2)
print(n - k * (1 + k) // 2 + 1)


def checker(n, m):
	return n - m * (m + 1) / 2
n = int(input())
if n == 1:
	print(1)
	exit(0)
(l, r) = (0, n + 1)
while r - l > 1:
	m = (l + r) // 2
	if checker(n, m) >= 0:
		l = m
	else:
		r = m
if checker(n, l) == 0:
	print(l)
else:
	print(int(checker(n, l)))


import math
n = int(input())
factor = int(math.sqrt(2 * n))
if 2 * n <= factor * (factor + 1):
	factor -= 1
print(n - factor * (factor + 1) // 2)


from collections import deque
from math import log, sqrt, ceil

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
n = ii()
n1 = 2 * n * 4 + 1
x = ceil((sqrt(n1) - 1.0) / 2)
x -= 1
s = x * (x + 1) // 2
n -= s
print(n)


from math import ceil
x = int(input())
t = (-1 + (1 + 8 * x) ** (1 / 2)) / 2
if ceil(t) > t:
	r = int(t)
	print(x - int(r * (r + 1) // 2))
else:
	print(int(t))


n = int(input())
ans = int((n * 2) ** 0.5)
while ans * (ans + 1) // 2 > n:
	ans -= 1
if ans * (ans + 1) // 2 == n:
	print(ans)
else:
	print(n - ans * (ans + 1) // 2)


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)

def hnbhai():
	n = sb()
	i = 1
	ans = -1
	while n > 0:
		if n > i:
			n -= i
		elif n == i:
			ans = i
			n -= i
		else:
			ans = n
			n -= i
		i += 1
	print(ans)
for _ in range(1):
	hnbhai()


from math import sqrt

def main():
	n = int(input())
	k = int((-1 + sqrt(1 + 4 * 2 * n)) // 2)
	ans = n - k * (k + 1) // 2
	ans = ans if ans != 0 else k
	print(ans)
main()


n = int(input())
m = 1
M = 10 ** 8
mid = (m + M) // 2
s = mid * (mid + 1) // 2
s1 = s + mid + 1
while not (s <= n and s1 > n):
	mid = (m + M) // 2
	s = mid * (mid + 1) // 2
	s1 = s + mid + 1
	if s < n and s1 < n:
		m = mid
	elif s > n:
		M = mid
	else:
		break
if s == n:
	print(mid)
else:
	print(n - s)


import math

def solve():
	num = int(input())
	n = int((-1 + math.sqrt(1 + 8 * num)) / 2)
	s = int(n * (n + 1) / 2)
	if s == num:
		ans = n
	else:
		ans = num - s
	print(ans)
solve()


import math
m = int(input())
n = max(int(math.sqrt(m)) - 2, 1)
m -= n * (n + 1) // 2
if m == 0:
	m += n
n = n + 1
while m > n:
	m -= n
	n += 1
print(m)


from itertools import combinations, accumulate, groupby, count
from sys import stdout, stdin, setrecursionlimit
from collections import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
n = int(z())
i = 1
while i * (i + 1) < 2 * n:
	i += 1
if i * (i + 1) // 2 > n:
	i -= 1
p = n - (i + 1) * i // 2
if p == 0:
	p = i
print(p)


n = int(input())
c = 1
d = 1
while c < n:
	d += 1
	c += d
print(n - (c - d))


def __starting_point():
	n = int(input())
	res = (-1 + (8 * n + 1) ** (1 / 2)) / 2
	if res == int(res) / 1:
		print(int(res))
	else:
		k = int(res)
		k = k * (k + 1) // 2
		p = n - k
		print(p)
__starting_point()


N = int(input())
lo = 0
hi = 10 ** 18
while hi - lo > 1:
	mid = (hi + lo) // 2
	if mid * (mid + 1) // 2 < N:
		lo = mid
	else:
		hi = mid
print(N - lo * (lo + 1) // 2)


import math
n = int(input())
k = math.floor(((1 + 8 * n) ** 0.5 - 1) / 2)
ans = n - k * (k + 1) // 2
print(ans if ans else k)


a = int(input())
b = int((2 * a) ** 0.5)
c = a - (b ** 2 + b) // 2
if c == 0:
	print(b)
else:
	print(c % b)


number = int(input())
n = int((1 + (1 + 8 * (number - 1)) ** (1 / 2)) / 2)
print(number - n * (n - 1) // 2)


n = int(input())
i = int((-1 + (8 * n + 1) ** 0.5) / 2)
while i * (i + 1) < 2 * n:
	i += 1
print(n - i * (i - 1) // 2)


import sys

def main():
	n = int(input())
	(tl, tr) = (0, n)
	while tr - tl > 1:
		tm = tl + (tr - tl) // 2
		s = (1 + tm) * tm // 2
		if s >= n:
			tr = tm
		else:
			tl = tm
	s = (1 + tr) * tr // 2
	s -= tr
	n -= s
	print(n)
main()


from sys import stdin, stdout
from math import sqrt, floor
n = int(input())
k = floor((1 + sqrt(8 * n + 1)) // 2)
if k * (k - 1) / 2 == n:
	k -= 1
print(int(n - k * (k - 1) / 2))


n = int(input())
for i in range(1, 100000000):
	ss = i * (i + 1) // 2
	if ss >= n:
		break
if ss == n:
	print(i)
else:
	diff = ss - n
	print(i - diff)


import math
n = int(input()) - 1
x = ((8 * n + 1) ** 0.5 - 1) // 2
y = x * (x + 1) / 2
print(int(n - y + 1))


n = int(input())
x = 0
for i in range(1, n + 1):
	if x + i >= n:
		ans = n - x
		print(ans)
		exit()
	else:
		x += i


import math
number = input()
current = 0
num = int(number)
D = math.sqrt(1 + 8 * num)
n = (D - 1) / 2
n = int(n)
summa = n * (n + 1) / 2
if num == summa:
	n -= 1
	summa = n * (n + 1) / 2
if num > summa:
	num -= summa
num = int(num)
print(num)