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

Difficulty: interview

Starter code:

Solutions:
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 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)



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))


3

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)



__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)

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)

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())
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))


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)

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)


import collections
import math

#n ,m = map(int, input().split())
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)

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()



'''
@author: agavrikov
'''
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)
    #print('mid = ', mid)
    sum = sm(mid)
    #print('sum = ', sum)
    if sm(mid) < n:
        st = sum
        l = mid + 1
    else:
        r = mid - 1              
print(n - st)


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 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))

#!/usr/bin/env pypy
# -*- coding: utf-8 -*-

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()

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)

def __starting_point():
    main()
__starting_point()

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 ):

    #print("solve",x)
    if x == 0:
        return 1

    n = binary_search( x )
    #print("n =",n)

    return int(x+1-n*(n+1)//2)

def __starting_point():

    x = int( input() )
    print( solve(x-1) )
__starting_point()

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))


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



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())
number = 1
while n > number:
    n -= number
    number += 1
print(n)

#!/usr/bin/env python3


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()

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))


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)))