Snuke is visiting a shop in Tokyo called 109 to buy some logs.
He wants n logs: one of length 1, one of length 2, ..., and one of length n.
The shop has n+1 logs in stock: one of length 1, one of length 2, \dots, and one of length n+1. Each of these logs is sold for 1 yen (the currency of Japan).
He can cut these logs as many times as he wants after buying them. That is, he can get k logs of length L_1, \dots, L_k from a log of length L, where L = L_1 + \dots + L_k. He can also throw away unwanted logs.
Snuke wants to spend as little money as possible to get the logs he wants.
Find the minimum amount of money needed to get n logs of length 1 to n.

-----Constraints-----
 - 1 \leq n \leq 10^{18}

-----Input-----
Input is given from Standard Input in the following format:
n

-----Output-----
Print the minimum amount of money needed to get n logs of length 1 to n.

-----Sample Input-----
4

-----Sample Output-----
3

One way to get the logs he wants with 3 yen is:
 - Buy logs of length 2, 4, and 5.
 - Cut the log of length 5 into two logs of length 1 each and a log of length 3.
 - Throw away one of the logs of length 1.

Difficulty: MEDIUM_HARD

Solutions:
import sys
import math
n = int(input())
i = math.floor(math.sqrt(n * 2)) - 1
while True:
	total = (2 + i) * (i + 1) // 2
	if total <= n + 1:
		i += 1
	else:
		break
print(n - i + 1)


def binarySearch(ok, ng, test):
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if test(mid):
			ok = mid
		else:
			ng = mid
	return ok

def test(x):
	return x * (x + 1) // 2 <= n + 1
n = int(input())
k = binarySearch(1, 10 ** 18 + 10, test)
ans = n - k + 1
print(ans)


import sys
readline = sys.stdin.readline
N = int(readline())
ok = 0
ng = 10 ** 18 + 1

def isOk(x):
	if (1 + x) * x // 2 <= N + 1:
		return True
	return False
while abs(ng - ok) > 1:
	mid = abs(ng + ok) // 2
	if isOk(mid):
		ok = mid
	else:
		ng = mid
print(N + 1 - ok)


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

def __starting_point():
	resolve()
__starting_point()


import sys

def is_match(k):
	if (1 + k) * k // 2 <= n + 1:
		return True
	else:
		return False
n = int(input())
left = -1
right = n + 1
while right - left > 1:
	mid = (left + right) // 2
	if is_match(mid):
		left = mid
	else:
		right = mid
print(n - left + 1)


class BisectBase:

	def __init__(self, n, asc):
		self._n = n
		self._lc = self.ge_item if asc else self.le_item
		self._rc = self.gt_item if asc else self.lt_item

	def lt_item(self, idx, item):
		raise NotImplementedError('lt_item should be implemented')

	def gt_item(self, idx, item):
		raise NotImplementedError('gt_item should be implemented')

	def le_item(self, idx, item):
		raise NotImplementedError('le_item should be implemented')

	def ge_item(self, idx, item):
		raise NotImplementedError('ge_item should be implemented')

	def bisect_left(self, item):
		return self._bisect_left(item, 0, self._n)

	def _bisect_left(self, item, left, right):
		if right - left == 1:
			return left + 1
		mid = left + (right - left) // 2
		if self._lc(mid, item):
			return self._bisect_left(item, left, mid)
		else:
			return self._bisect_left(item, mid, right)

	def bisect_right(self, item):
		return self._bisect_right(item, 0, self._n)

	def _bisect_right(self, item, left, right):
		if right - left == 1:
			return left + 1
		mid = left + (right - left) // 2
		if self._rc(mid, item):
			return self._bisect_right(item, left, mid)
		else:
			return self._bisect_right(item, mid, right)

class Bisect(BisectBase):

	def gt_item(self, idx, item):
		return idx * (idx + 1) > item
n = int(input())
b = Bisect(n + 1, True)
m = b.bisect_right(2 * (n + 1)) - 1
print(n + 1 - m)


n = int(input())

def func(ii):
	return (ii + 1) * ii // 2 - (n + 1)
l = 1
r = n
m = (r + l) // 2
while r - l > 1:
	m = (r + l) // 2
	if func(m) == 0:
		break
	if func(m) > 0:
		r = m
	if func(m) < 0:
		l = m
if func(r) == 0:
	c = r
elif func(m) <= 0:
	c = m
else:
	c = l
print(n - c + 1)


n = int(input())
(ok, ng) = (1, n + 1)

def is_ok(x):
	if x * (x + 1) // 2 <= n + 1:
		return True
	else:
		return False
while abs(ok - ng) > 1:
	mid = abs(ok + ng) // 2
	if is_ok(mid):
		ok = mid
	else:
		ng = mid
print(n + 1 - ok)


n = int(input())
import math
k = int((math.sqrt(8 * n + 9) - 1) / 2)
if n >= 10000:
	for i in range(k - 100, k + 100):
		if i ** 2 + i > 2 * (n + 1):
			k = i - 1
			break
print(n + 1 - k)


n = int(input())
if n == 1 or n == 2:
	print(1)
	return

def cut(n):
	l = 0
	r = n
	while r - l > 1:
		mid = (l + r) // 2
		if mid * (mid + 1) // 2 <= n + 1:
			l = mid
		else:
			r = mid
	return l
print(n - cut(n) + 1)


import sys
input = sys.stdin.readline
N = int(input().strip())
k_max = None
ok = 0
ng = 2 * (N + 1)
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	if mid * (mid + 1) <= 2 * (N + 1):
		ok = mid
	else:
		ng = mid
k_max = ok
print(N - k_max + 1)


n = int(input())

def is_ok(arg):
	return 2 * (n + 1) < arg * (arg + 1)

def meguru_bisect(ng, ok):
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if is_ok(mid):
			ok = mid
		else:
			ng = mid
	return ok - 1
print(n + 1 - meguru_bisect(1, n + 1))


n = int(input())
if n <= 2:
	print(1)
elif n == 3:
	print(2)
else:
	s = 0
	a = int((2 * (n + 1)) ** 0.5)
	l = lambda x: x * (x + 1) // 2
	for i in range(a, n):
		if l(i) > n + 1:
			print(n - i + 2)
			break


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


n = int(input())
left = 0
right = n + 1
while left < right - 1:
	mid = left + right >> 1
	if mid * (mid + 1) // 2 <= n + 1:
		left = mid
	else:
		right = mid
print(n + 1 - left)


def solve():
	N = int(input())
	ok = 1
	ng = N + 1
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if mid * (mid + 1) // 2 <= N + 1:
			ok = mid
		else:
			ng = mid
	print(N - ok + 1)

def __starting_point():
	solve()
__starting_point()


import math
n = int(input())
ans = n
k = math.ceil(((n * 8 + 9) ** (1 / 2) - 1) / 2) - 1
while k * (k + 1) <= 2 * (n + 1):
	k += 1
ans -= k - 2
print(ans)


import sys, io
_INPUT = '2\n'

def main():
	n = int(input())
	ng = n + 1
	ok = 1
	while ng - ok > 1:
		mid = (ok + ng) // 2
		if mid * (mid + 1) // 2 <= n + 1:
			ok = mid
		else:
			ng = mid
	ans = n - ok + 1
	print(ans)

def __starting_point():
	main()
__starting_point()


n = int(input())
ok = 10 ** 20
ng = 0
while ok - ng > 1:
	m = (ok + ng) // 2
	if m * (m + 1) <= 2 * (n + 1):
		ng = m
	else:
		ok = m
print(n + 1 - ng)


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


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


import math
N = int(input())
OK = 0
NG = 10 ** 10
while NG - OK > 1:
	check = (OK + NG) // 2
	if check * (check + 1) <= 2 * N + 2:
		OK = check
	else:
		NG = check
print(N - OK + 1)


N = int(input())

def f(k):
	return (k + 1) * k // 2

def bi_re():
	l = 0
	r = N + 1
	while l <= r:
		m = (l + r) // 2
		if f(m) > N + 1:
			r = m - 1
		elif f(m) < N + 1:
			l = m + 1
		else:
			return m
	return r
k = bi_re()
print(N - k + 1)


import sys
sys.setrecursionlimit(10 ** 6)

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LC():
	return list(input())

def IC():
	return [int(c) for c in input()]

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]
N = II()
if N == 1:
	print(1)
else:
	Big = N + 1
	NG = 0
	OK = Big

	def is_ok(arg):
		return (arg + 2) * (arg + 3) // 2 >= Big

	def meguru_bisect(ng, ok):
		while abs(ok - ng) > 1:
			mid = (ok + ng) // 2
			if is_ok(mid):
				ok = mid
			else:
				ng = mid
		return ok
	l = meguru_bisect(NG, OK)
	while l * (l + 1) // 2 <= Big:
		l += 1
	l -= 1
	print(Big - l)


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


import collections

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

def readInt():
	return int(input())

def readString():
	return input()

def tcase():
	t = readInt()
	for _ in range(t):
		solve()

def solve():
	n = readInt()
	(lo, hi) = (1, n)
	while lo < hi:
		mid = lo + hi + 1 >> 1
		if mid * (mid + 1) // 2 <= n + 1:
			lo = mid
		else:
			hi = mid - 1
	print(n - lo + 1)
solve()


n = int(input())
left = 0
right = n + 1
while right - left > 1:
	mid = left + (right - left) // 2
	flag = True
	if (1 + mid) * mid // 2 <= n + 1:
		flag = True
	else:
		flag = False
	if flag:
		left = mid
	else:
		right = mid
print(n - left + 1)


n = int(input())

def f(k):
	return k * (k + 1) // 2
l = -1
r = n + 1
while r - l > 1:
	mid = l + (r - l) // 2
	if f(mid) <= n + 1:
		l = mid
	else:
		r = mid
ans = n - l + 1
print(ans)


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


n = int(input())
x = 1
y = n * 2
while y - x > 1:
	mid = (y + x) // 2
	s = (1 + mid) * mid // 2
	if s > n + 1:
		y = mid
	else:
		x = mid
k = x
ans = 1 + (n - k)
print(ans)


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


from sys import stdin, setrecursionlimit
import bisect, collections, copy, heapq, itertools, math, string
setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 1000000007

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

def main():
	n = int(input())
	ok = n + 1
	ng = 0
	while ok - ng > 1:
		mid = (ok + ng) // 2
		if n + 1 >= (n + 1 - mid) * (n + 1 - mid + 1) // 2:
			ok = mid
		else:
			ng = mid
	print(ok)
	return

def __starting_point():
	main()
__starting_point()


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


import math
n = int(input())
x = math.floor((-1 + math.sqrt(8 * n + 9)) / 2)
for i in range(x + 3, x - 2, -1):
	if (n + 2) * (n + 1) - i * (i + 1) >= n * (n + 1):
		y = i
		break
print(n + 1 - y)


from math import sqrt, ceil
n = int(input())
m = ceil((-1 + sqrt(8 * n + 9)) / 2)
s = m * (m + 1) - 2 * (n + 1)
while s > 0:
	m -= 1
	s = m * (m + 1) - 2 * (n + 1)
print(n - m + 1)


n = int(input())
right = 10 ** 18 + 1
left = -1
while right - left > 1:
	mid = (right + left) // 2
	if mid * (mid + 1) // 2 > n + 1:
		right = mid
	else:
		left = mid
print(n - left + 1)


from bisect import bisect, bisect_left

class BisectSearch:

	@staticmethod
	def search_float(f, l=0, r=10 ** 9, epsilon=1e-09, return_left=False):
		assert f(l) and (not f(r))
		while r - l > epsilon:
			m = (r + l) / 2
			if f(m):
				l = m
			else:
				r = m
		if return_left:
			return l
		return r

	@staticmethod
	def search_int(f, l=0, r=10 ** 9, return_left=False):
		assert f(l) and (not f(r))
		while r - l > 1:
			m = (r + l) // 2
			if f(m):
				l = m
			else:
				r = m
		if return_left:
			return l
		return r

	@staticmethod
	def search_list(key, A, return_left=False):
		search = bisect_left if return_left else bisect
		return search(A, key)

def arithmetic_series(n, d=1, a=1):
	return n * (2 * a + (n - 1) * d) // 2
n = int(input())
bs = BisectSearch

def f(x):
	return arithmetic_series(x) <= n + 1
print(n + 1 - bs.search_int(f, l=1, r=n + 1, return_left=True))


n = int(input())
LOW = 0
HIGH = n
r = 0
now = (LOW + HIGH) // 2
if n < 3:
	print(1)
	return
while 1:
	now = (LOW + HIGH) // 2
	cur = now * (now + 1) // 2
	nex = (now + 1) * (now + 2) // 2
	if cur <= n + 1 and n + 1 < nex:
		r = now
		break
	elif cur < n + 1:
		LOW = now
	else:
		HIGH = now
print(n - r + 1)


n = int(input())

def sqrt(n):
	if n == 0:
		return 0
	x = 1 << (n.bit_length() + 1) // 2
	y = (x + n // x) // 2
	while y < x:
		x = y
		y = (x + n // x) // 2
	return x

def f(n):
	return
print(n + 1 - (-1 + sqrt(1 + 8 * (n + 1))) // 2)


N = int(input())
ok = 0
ng = 10 ** 18 + 1
while abs(ok - ng) > 1:
	mid = (ok + ng) // 2
	if N + 1 >= mid * (mid + 1) // 2:
		ok = mid
	else:
		ng = mid
print(N - ok + 1)


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


def is_ok(k):
	return k * (1 + k) // 2 <= n + 1

def meguru_bisect(ng, ok):
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		if is_ok(mid):
			ok = mid
		else:
			ng = mid
	return ok
n = int(input())
ans = meguru_bisect(n + 1, 0)
print(n + 1 - ans)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	if n == 1:
		print(1)
		return
	left = 1
	right = n + 1
	result = 0
	while True:
		k = (right + left) // 2
		if k == right or k == left:
			break
		temp = k * (k + 1) // 2
		if temp <= n + 1:
			left = k
			result = k
		else:
			right = k
	print(n - result + 1)

def __starting_point():
	main()
__starting_point()


n = int(input())
l = 0
r = 10 ** 18
while r - l > 1:
	mid = (r + l) // 2
	sum = mid * (mid + 1)
	if sum <= 2 * (n + 1):
		l = mid
	else:
		r = mid
print(n - l + 1)


def sigma(k):
	return k * (k + 1) // 2
n = int(input())
ub = 10 ** 18
lb = 1
while ub - lb > 1:
	mid = (ub + lb) // 2
	if sigma(mid) <= n + 1:
		lb = mid
	else:
		ub = mid
print(n - lb + 1)


ma = lambda : map(int, input().split())
lma = lambda : list(map(int, input().split()))
tma = lambda : tuple(map(int, input().split()))
ni = lambda : int(input())
yn = lambda fl: print('Yes') if fl else print('No')
ips = lambda : input().split()
import collections
import math
import itertools
import heapq as hq
import sys
ceil = math.ceil
gcd = math.gcd
RL = sys.stdin.readline
INF = 10 ** 15

def ceilab(a, b):
	return (a + b - 1) // b
n = ni()
l = 0
r = n + 1
while r - l > 1:
	x = (r + l) // 2
	if x * (x + 1) // 2 > n + 1:
		r = x
	else:
		l = x
print(n + 1 - l)


from decimal import Decimal
n = int(input())
i = int((-1 + Decimal(1 + 8 * (n + 1)).sqrt()) / 2)
print(n - i + 1)


import sys

def input():
	return sys.stdin.readline().strip()

def mapint():
	return map(int, input().split())
sys.setrecursionlimit(10 ** 9)
N = int(input())
(l, r) = (0, 10 ** 18)
while l + 1 < r:
	half = (l + r) // 2
	if half * (half + 1) // 2 <= N + 1:
		l = half
	else:
		r = half
print(N + 1 - l)


n = int(input())
if n <= 2:
	print(1)
else:
	(l, r) = (0, n)
	d = (l + r) // 2
	while r - l > 1:
		if d * (d + 1) <= 2 * (n + 1):
			l = d
		else:
			r = d
		d = (l + r) // 2
	print(n - d + 1)


n = int(input())
right = 0
left = 10 ** 18
while abs(right - left) > 1:
	k = (right + left) // 2
	if k * (k + 1) <= (n + 1) * 2:
		right = k
	else:
		left = k
print(n - right + 1)


from abc import ABCMeta, abstractmethod

class BisectBase(metaclass=ABCMeta):

	def __init__(self, n, asc):
		self._n = n
		self._lc = self._ge if asc else self._le
		self._rc = self._gt if asc else self._lt

	@abstractmethod
	def get(self, idx):
		pass

	def _lt(self, idx, item):
		return self.get(idx) < item

	def _gt(self, idx, item):
		return self.get(idx) > item

	def _le(self, idx, item):
		return self.get(idx) <= item

	def _ge(self, idx, item):
		return self.get(idx) >= item

	def bisect_left(self, item):
		return self._bisect_left(item, 0, self._n)

	def _bisect_left(self, item, left, right):
		if right - left == 1:
			return left if self._lc(left, item) else left + 1
		mid = left + (right - left) // 2
		if self._lc(mid, item):
			return self._bisect_left(item, left, mid)
		else:
			return self._bisect_left(item, mid, right)

	def bisect_right(self, item):
		return self._bisect_right(item, 0, self._n)

	def _bisect_right(self, item, left, right):
		if right - left == 1:
			return left if self._rc(left, item) else left + 1
		mid = left + (right - left) // 2
		if self._rc(mid, item):
			return self._bisect_right(item, left, mid)
		else:
			return self._bisect_right(item, mid, right)

class Bisect(BisectBase):

	def get(self, idx):
		return idx * (idx + 1)
n = int(input())
b = Bisect(n + 2, True)
m = b.bisect_right(2 * (n + 1)) - 1
print(n + 1 - m)


from math import sqrt

def solve(n):
	z = 2 * (n + 1)
	y = int(sqrt(z))
	if y * (y + 1) > z:
		y -= 1
	return n - y + 1
n = int(input())
print(solve(n))


n = int(input())

def is_ok(x):
	if (n - x + 1) * (n - x + 2) // 2 <= n + 1:
		return True
	else:
		return False
ng = 0
ok = n
while ng + 1 < ok:
	c = (ok + ng) // 2
	if is_ok(c):
		ok = c
	else:
		ng = c
print(ok)


n = int(input())
found = False

def search(small, large, border):
	is_ok_l = border > int(large * (large + 1) / 2)
	is_ok_s = border > int(small * (small + 1) / 2)
	return (is_ok_s, is_ok_l)
width = 2 ** 16
s = 0
l = 10 ** 5
while not found:
	(is_s, is_l) = search(s, l, n + 1)
	if is_l and is_s:
		width = int(width * 2)
		l += width
		s += width
	elif not is_l and is_s:
		width = int(width / 2)
		l = s + width
	else:
		width = int(width / 2)
		l -= width
		s -= width
	if width < 20:
		break
k = int(s)
to = 0
while not found:
	accum = k * (k + 1) // 2
	if accum > n + 1:
		to = k - 1
		break
	elif accum == n + 1:
		to = k
		break
	k += 1
print(n - to + 1)


from decimal import Decimal, ROUND_CEILING, getcontext
n = Decimal(input())
print(((Decimal(2) * n + Decimal(3) - (Decimal(8) * n + Decimal(9)).sqrt()) / Decimal(2)).to_integral_value(ROUND_CEILING))


n = int(input().strip())
r = 10 ** 19
l = 0
m = 0
while l + 1 < r:
	m = l + r >> 1
	if m * (1 + m) >> 1 <= n + 1:
		l = m
	else:
		r = m
print(n - l + 1)


n = int(input())

def can(x):
	return x * (x + 1) // 2 <= n + 1
l = 0
r = n + 1
while r - l > 1:
	m = (l + r) // 2
	if can(m):
		l = m
	else:
		r = m
print(n + 1 - l)


n = int(input())

def possible(x):
	if (1 + x) * x <= 2 * (n + 1):
		return True
	else:
		return False
left = 0
right = 10 ** 10
while right - left > 1:
	middle = (right + left) // 2
	if possible(middle):
		left = middle
	else:
		right = middle
print(n + 1 - left)


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


n = int(input()) + 1
a = int(((8 * n + 1) ** 0.5 - 1) // 2)
ans = 0
for i in range(max(0, a - 100), a + 100):
	if i * (i + 1) <= 2 * n and 2 * n < (i + 1) * (i + 2):
		ans = n - i
		break
print(ans)


from decimal import *
n = Decimal(input())
print(n - int(((n * 8 + 9).sqrt() - 3) / 2))


def __starting_point():
	n = int(input())
	left = 0
	right = 10 ** 18 + 2
	while left < right - 1:
		x = (left + right) // 2
		if x * (x + 1) // 2 <= n + 1:
			left = x
		else:
			right = x
	print(n + 1 - left)
__starting_point()


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


from decimal import Decimal
n = int(input())
left = 0
right = n + 1
mid = (left + right) // 2
for _ in range(100000):
	mid = (left + right) // 2
	if mid * (mid + 1) // 2 > n + 1:
		right = mid
	else:
		left = mid
i = mid
print(n - i + 1)


import math
n = int(input())

def get(n):
	temp = (math.sqrt(8 * (n + 1) + 1) - 1) / 2
	return math.floor(temp)

def check(n):
	target = get(n)
	if (target + 1) * (target + 2) // 2 <= n + 1:
		return target + 1
	elif target * (target + 1) // 2 <= n + 1:
		return target
	elif (target - 1) * target // 2 <= n + 1:
		return target - 1
print(n + 1 - check(n))


n = int(input())
l = 1
r = n + 1
for i in range(1, 100):
	mid = (l + r) // 2
	if n + 1 >= (n - mid + 2) * (n - mid + 1) // 2:
		r = mid
	else:
		l = mid
print(r)


n = int(input())
ans = 0
target = int((2 * (n + 1)) ** 0.5)
for num in range(max(target - 1000, 1), target + 1000):
	if num * (num + 1) > 2 * (n + 1):
		break
	else:
		ans = num
print(n - ans + 1)


n = int(input())
ans = n + 1
square = int((n * 2 + 2) ** 0.5)
if n * 2 + 2 - square ** 2 - square >= 0:
	pass
else:
	square -= 1
print(ans - square)


N = int(input())
l = 0
r = 10 ** 100
while r - l > 1:
	m = (r + l) // 2
	if m * (m + 1) <= 2 * (N + 1):
		l = m
	else:
		r = m
print(N - l + 1)


n = int(input())
ans = n
cnt = 0
while cnt <= n:
	cnt += 100000
	if cnt * (cnt + 1) // 2 > n + 1:
		cnt -= 100000
		break
while cnt <= n:
	cnt += 1
	if cnt * (cnt + 1) // 2 > n + 1:
		cnt -= 1
		break
print(ans - cnt + 1)


def solve(n):
	return n * (n + 1) // 2
N = int(input())
left = 0
right = N + 1
while abs(right - left) > 1:
	mid = abs(right + left) // 2
	if solve(mid) <= N + 1:
		left = mid
	else:
		right = mid
print(N - left + 1)


n = int(input())
x = int(((1 + 4 * 2 * (n + 1)) ** 0.5 - 1) / 2)
if (x + 1) * (x + 2) <= (n + 1) * 2:
	x += 1
if x * (x + 1) > (n + 1) * 2:
	x -= 1
ans = n + 1 - x
print(ans)


n = int(input())
if n <= 2:
	print(1)
	return
ng = 0
ok = n
while ng + 1 != ok:
	mid = (ng + ok) // 2
	if mid * (mid + 1) // 2 <= n + 1:
		ng = mid
	else:
		ok = mid
print(n - ng + 1)


import sys, math, random, re, heapq
from itertools import combinations as c, permutations as perm, product as p
from collections import deque
from copy import deepcopy
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 998244353
F = 1e-09

def si():
	return input()

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

def fi():
	return float(input())

def lstr():
	return input().split()

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

def lintdec():
	return list(map(lambda x: int(x) - 1, input().split()))

def lnstr(n):
	return [input() for _ in range(n)]

def lnint(n):
	return [ii() for _ in range(n)]

def lint_list(n):
	return [lint() for _ in range(n)]

def lcm(a, b):
	return a * b // math.gcd(a, b)
n = int(input())
l = 1
r = n + 1
while r - l > 1:
	mid = (l + r) // 2
	s = mid * (mid + 1) // 2
	if s <= n + 1:
		l = mid
	elif s > n + 1:
		r = mid
print(n - l + 1)


n = int(input())
x = 1
y = n + 1
while y > x:
	mid = (x + y + 1) // 2
	if (mid + 1) * mid // 2 <= n + 1:
		x = mid
	else:
		y = mid - 1
print(n + 1 - y)


n = int(input())

def check(k):
	return k * (k + 1) // 2 <= n + 1
left = 0
right = 10 ** 18 + 1
while left + 1 < right:
	mid = (left + right) // 2
	if check(mid):
		left = mid
	else:
		right = mid
print(n - left + 1)


def search(n):
	s = 1
	e = n
	while s <= e:
		mid = (s + e) // 2
		if mid * (mid + 1) // 2 <= n:
			ans = mid
			s = mid + 1
		else:
			e = mid - 1
	return ans
n = int(input())
print(1 + n - search(n + 1))


n = int(input())
(l, r) = (0, 1000000000000000000)
while r - l > 1:
	m = (l + r) // 2
	tmps = m * (m + 1) // 2
	if tmps <= n + 1:
		l = m
	else:
		r = m
print(n - l + 1)


from collections import defaultdict
from sys import stdin
input = stdin.readline

def solve():
	n = int(input())
	left = 1
	right = n + 1

	def ok(x):
		return x * (x - 1) <= 2 * (n + 1)
	while left < right:
		mid = left + right + 1 >> 1
		if ok(mid):
			left = mid
		else:
			right = mid - 1
	print(n - left + 2)

def __starting_point():
	solve()
__starting_point()


n = int(input())

def maruta(m):
	if n + 1 >= m * (m + 1) // 2:
		return True
	else:
		False
left = 1
right = n + 1
while left + 1 < right:
	t = (left + right) // 2
	if maruta(t):
		left = t
	else:
		right = t
print(n + 1 - left)


import math
import collections
n = int(input())
K = 0
l = 0
r = n + 1
m = 0
while r - l > 1:
	m = (l + r) // 2
	if m * (m + 1) // 2 > n + 1:
		r = m
	else:
		l = m
print(n - l + 1)


def sigma1(n):
	return n * (n + 1) // 2
n = int(input())

def do():
	l = 0
	h = n
	while l <= h:
		mid = (l + h) // 2
		if sigma1(mid) <= n + 1:
			l = mid + 1
		else:
			h = mid - 1
	return h if sigma1(h) <= n + 1 else l
x = do()
print(1 + (n - do()))


def solve():
	N = int(input())
	left = 1
	right = N + 1
	while right - left > 1:
		mid = (left + right) // 2
		if mid * (mid + 1) // 2 > N + 1:
			right = mid
		else:
			left = mid
	print(N - left + 1)

def __starting_point():
	solve()
__starting_point()


import math
from decimal import *
n = int(input())
m = int((-1 + Decimal(1 + 4 * (2 * n + 2)) ** Decimal(0.5)) / 2)
print(n - m + 1)


n = int(input())

def main():
	lb = 0
	ub = 10 ** 10
	while ub - lb > 1:
		mid = int((lb + ub) / 2)
		if n >= (mid + 2) * (mid - 1) // 2:
			lb = mid
		else:
			ub = mid
	print(n - (lb - 1))
main()