Problem:


Score : 200 points

Problem Statement

There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0.
During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right.
That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i.
The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible.
Find the earliest possible time to reach coordinate X.

Constraints

X is an integer.

1≤X≤10^9

Input

The input is given from Standard Input in the following format:

X

Output

Print the earliest possible time for the kangaroo to reach coordinate X.

Sample Input 1

6

Sample Output 1

3

The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.

Sample Input 2

2

Sample Output 2

2

He can reach his nest at time 2 by staying at his position during the first second, and jumping to the right at the next second.

Sample Input 3

11

Sample Output 3

5



Sample input:
6


Sample output:
3

Submission status: Wrong Answer

Solution code:
N=input()
left=1
right=10**9

while left <= right:
	center = (left + right)/2
	x=(1+center)*center/2
	#print left,center,right,x,N
	if center==N:
		print center
		break
	elif x==N:
		print center
		break
	elif x<N-1 and center<(N-x):
		print N-x
		break
	elif N<x:
		right=center-1
	else:
		left=center+1

Submission status: Wrong Answer

Solution code:
N=input()
left=1
right=10**9

while left <= right:
	center = (left + right)/2
	x=(1+center)*center/2
	#print left,center,right,x,N
	if x==N:
		print center
		break
	elif x==N-1:
		print center+1
		break
	elif x<N-1:
		left=center+1
	else:
		right=center-1

Submission status: Wrong Answer

Solution code:
N=int(input())
for i in range(N):
    if N <= i*(i+1)//2:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
X = int(input())

L = 0
for i in range(1, X) :
    L += i
    if L >= X :
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import sys

# sys.stdin = open('c1.in')

x = int(input())


def f(x):
    a = 0
    b = 4 * 10 ** 4
    while b - a > 1:
        n = (a + b) // 2
        s = n * (n + 1) // 2
        if s >= x:
            b = n
        else:
            a = n
    return b


print(f(x))

Submission status: Wrong Answer

Solution code:
import sys

# sys.stdin = open('c1.in')

x = int(input())


def f(x):
    a = 0
    b = 4 * 10 ** 4
    while b - a > 1:
        n = (a + b) // 2
        s = n * (n + 1) / 2
        if s >= x:
            b = n
        else:
            a = n
    return b


print(f(x))

Submission status: Wrong Answer

Solution code:
def obj(t):
    return t**2 + t

import math
X = int(input())

s = 0
e = 2e9
m = math.floor((s + e) / 2.0)

while(True):
    if (obj(m) < (2 * X)):
        s = m
    else:
        e = m
    if ((e - s) <= 1):
        print(m)
        break
    m = math.floor((s + e) / 2.0)

Submission status: Wrong Answer

Solution code:
def obj(t):
    return t**2 + t

import math
X = int(input())

s = 1
e = 2e9
m = math.floor((s + e) / 2.0)

while(True):
    if (obj(m) < (2 * X)):
        s = m
    else:
        e = m
    if ((e - s) <= 1):
        print(m)
        break
    m = math.floor((s + e) / 2.0)

Submission status: Wrong Answer

Solution code:
def obj(t):
    return t**2 + t

import math
X = int(input())

s = 1
e = 1e9
m = math.floor((s + e) / 2.0)

while(True):
    if (obj(m) < (2 * X)):
        s = m
    else:
        e = m
    if ((e - s) <= 1):
        print(m)
        break
    m = math.floor((s + e) / 2.0)

Submission status: Wrong Answer

Solution code:
import math

def gtime(X, a, t):
  l = math.floor((len(a)-1)/2)
  if(len(a) == 1):
    return a[0]
  if(a[l] <= X and t <= X - a[l] and a[l+1] + t + 1 > X):
    return a[l]

  elif(a[l] > X):
    return gtime(X, a[:l], t + 1)

  else:
    return gtime(X, a[l+1:], t + 1)





X = abs(int(input()))
a = [(i)*(i+1)/2 for i in range(X)]
ans = gtime(X, a, 1)
print(X - ans)

Submission status: Wrong Answer

Solution code:
# C - Go Home
# 問題URL:http://abc056.contest.atcoder.jp/tasks/arc070_a

import math

X = int(input())
n = int((-1 + math.sqrt(1+8*X)) / 2)
sigma = 0.5 * n*(n+1)
sigma2 = 0.5 * (n+1)*(n+2)

time1 = n + abs(X - sigma)
time2 = n+1 + abs(X - sigma2)
print(int(min(time1,time2)))

Submission status: Wrong Answer

Solution code:
import math

X = int(input())
n = int((-1 + math.sqrt(1+8*X)) / 2)
sigma = 0.5 * n*(n+1)
sigma2 = 0.5 * (n+1)*(n+2)

time1 = n + abs(X - sigma)
time2 = n + abs(X - sigma2)
print(int(min(time1,time2)))

Submission status: Wrong Answer

Solution code:
import math

X = int(input())
n = int((-1 + math.sqrt(1+8*X)) / 2)
sigma = 0.5 * n*(n+1)
sigma2 = 0.5 * (n+1)*(n+2)

time1 = n + X - sigma
time2 = n + sigma2 - X
print(int(min(time1,time2)))

Submission status: Wrong Answer

Solution code:
import math

X = int(input())
n = int((-1 + math.sqrt(1+8*X)) / 2)
sigma = 0.5 * n*(n+1)
sigma2 = 0.5 * (n+1)*(n+2)

time1 = n + X - sigma
time2 = n + sigma - X
print(int(min(time1,time2)))

Submission status: Wrong Answer

Solution code:
import math

X = int(input())
n = int((-1 + math.sqrt(1+8*X)) / 2)
sigma = 0.5 * n*(1+n) 
print(int(n + abs(X - sigma)))

Submission status: Wrong Answer

Solution code:
# C - Go Home
# 問題URL:http://abc056.contest.atcoder.jp/tasks/arc070_a

import math

X = int(input())
n = int((-1 + math.sqrt(1+8*X)) / 2)
sigma = 0.5 * n*(1+n) 
print(int(n + X - sigma))

Submission status: Wrong Answer

Solution code:
X = int(raw_input())
X = 11

def makeValue(x, n):
    if(n == 0):
        return False
    if(x == n):
        return True
    if(x == -n):
        return True
    if(makeValue(x - n, n - 1)):
        return True
    if(makeValue(x + n, n - 1)):
        return True

    return False

for i in range(1, X + 1):
    if(makeValue(X, i)):
        print i
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

for i in range(1, N):
    if N <= (i * (i + 1) / 2):
        print (str(i))
        break

Submission status: Wrong Answer

Solution code:
import math
X = int(input())
n = int(math.sqrt(2*X) -2)

def sum(a):
    return a*(a+1)/2

result = 1

for i in range(n,X):
    if sum(i)>= X:
        result = i
        break

print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

a = int(raw_input())

result = 0

def conv(x, n):
    if x < 0: return None
    if n < 2 or 16 < n: return None

    if x == 0: return 0

    nchar = '0123456789ABCDEF'
    digit = 0

    result = ''

    while x > 0:
        result = nchar[x % n] + result
        x = x / n

    return result

def get_data(num):
    l = []
    result = []
    for n in range(1,num+1):
        l.append([-n, 0, n])
    for i in range(0, 3**num):
        hen = str(conv(i, 3))
        while len(hen) < num:
            hen = '0' + hen
        r = 0
        for j in range(0,num):
            s = hen[j]
            r += int(l[j][int(hen[j])])
        result.append(r)
    return list(set(result))

#rrrr = 0
#i = 1
#while 1:
    #if a in get_data(i):
        #rrrr = i
        #break
    #i += 1
lll = [
    [0, 1, -1],
    [0, 1, 2, 3, -1, -3, -2],
    [0, 1, 2, 3, 4, 5, 6, -2, -6, -5, -4, -3, -1],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, -10, -9, -8, -7, -6, -5, -4, -3, -2],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -1, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, -1, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, -11, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -1, -10, -9, -8, -7, -6, -5, -4, -3, -2],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, -1, -45, -44, -43, -42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2]]

result = 0
for i in range(0,9):
    if a in lll[i]:
        result = i+1
        break


# 出力
print result

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

a = int(raw_input())

result = 0

def conv(x, n):
    if x < 0: return None
    if n < 2 or 16 < n: return None

    if x == 0: return 0

    nchar = '0123456789ABCDEF'
    digit = 0

    result = ''

    while x > 0:
        result = nchar[x % n] + result
        x = x / n

    return result

def get_data(num):
    l = []
    result = []
    for n in range(1,num+1):
        l.append([-n, 0, n])
    for i in range(0, 3**num):
        hen = str(conv(i, 3))
        while len(hen) < num:
            hen = '0' + hen
        r = 0
        for j in range(0,num):
            s = hen[j]
            r += int(l[j][int(hen[j])])
        result.append(r)
    return list(set(result))

rrrr = 0
tmp = a
aaa = 1
while 1:
    tmp = tmp/aaa
    if tmp<=0:
        break
    aaa += 1
        
i = aaa
while 1:
    if a in get_data(i):
        rrrr = i
        break
    i += 1



# 出力
print rrrr

Submission status: Wrong Answer

Solution code:
def canMakeX(l, X):
    return sum(l) >= X

X = int(input())
for t in range(1, X + 1):
    l = list(range(1, t))
    if canMakeX(l, X):
        print(t-1)
        break

Submission status: Wrong Answer

Solution code:
#coding:utf-8
x=int(raw_input())  # 1 # 一つの数字のみ
# w, a, b =map(int,raw_input().split())  # 2 3  # 二つの数字
sums=0
for i in range(14145):
    sums += i
    # if x == place:
    # print sum
    # print i
    if sums < x:
        pass
    elif sums >= x:
        print i
        break

Submission status: Wrong Answer

Solution code:
#coding:utf-8
x=int(raw_input())  # 1 # 一つの数字のみ
# w, a, b =map(int,raw_input().split())  # 2 3  # 二つの数字
sums=0
for i in range(14144):
    sums += i
    # if x == place:
    # print sum
    # print i
    if sums >= x:
        print i
        break


# print pl?ace

Submission status: Wrong Answer

Solution code:
x = int(input())
sum = 0
i = 0
while sum !=x:
    i += 1
    if x - sum - i == 0:
        sum += i
    elif x - sum - i <= i:
        sum = sum
    else:
        sum += i
        
print(i)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
min_dt = 1001001001
min_i = 0
for i in range(1, x+1):
    dt = abs(x - (i+1)*i//2)
    if dt<min_dt:
        min_dt = dt
        min_i = i
    if min_dt == 0:
        print(i)
        break
else:
    print(min_i+min_dt)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

t = 1
while True:
    if (1 + t) * t / 2 > x:
        print(t)
    else:
        t += 1

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

time = 0
total = 0
while True:
    time += 1
    total += time
    if total > x:
        print(x)

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()

A = []
tmp = 0
for i in range(1, X+1):
    tmp += i
    A.append(tmp)

for i in range(len(A)):
    if X <= A[i]:
        print(i+1)
        break

Submission status: Time Limit Exceeded

Solution code:
import collections
ta = int(raw_input())
vis = set([0])
q = collections.deque([(0,0)])
while(q):
	x,t = q.popleft()
	if x == ta:
		print t
		break
	for nt in [x-t-1,x,x+t+1]:
		q.append((nt, t + 1))

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
dp = {}
dp[0] = 0

for i in range(1,X+1):
    dp_ = dp.copy()
    for key in dp.keys():
        if not key+i in dp.keys(): dp_[key+i] = i
        else: dp_[key+i] = min(dp_[key+i], i)

        #if not key-i in dp.keys(): dp_[key-i] = i
        #else: dp_[key-i] = min(dp_[key-i],i)
    dp = dp_
ans = dp[X]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
X = int(input())
dp = {}
dp[0] = 0

for i in range(1,X+1):
    dp_ = dp.copy()
    for key in dp.keys():
        if not key+i in dp.keys(): dp_[key+i] = i
        else: dp_[key+i] = min(dp_[key+i], i)

        if not key-i in dp.keys(): dp_[key-i] = i
        else: dp_[key-i] = min(dp_[key-i],i)
    dp = dp_
ans = dp[X]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
X = int(input())
time = X
for i in range(X+1):
    if i > time: continue
    n = - 1 + math.sqrt(1+8*(X-i))
    if n < 2*i and n%2 == 0:
        time = min(time, i)
print(time)

Submission status: Time Limit Exceeded

Solution code:
import math
X = int(input())
time = X
for i in range(X+1):
    j = X - i
    if j > time: continue
    n = - 1 + math.sqrt(1+8*(X-j))
    if n < 2*j and math.floor(n) == n:
        time = min(time, j)
print(time)

Submission status: Time Limit Exceeded

Solution code:
import math
X = int(input())
time = X
for i in range(X+1):
    if i > time: continue
    n = - 1 + math.sqrt(1+8*(X-i))
    if n < 2*i and math.floor(n) == n:
        time = min(time, i)
print(time)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
time = X
for i in range(X+1):
    if i > time: continue
    for j in range(i+1):
        dist = i + sum(range(j))
        if dist == X:  
            time = i
print(time)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

mylist=[]
for i in range (X):
    mylist.append(i+1)

ans=0
for j in mylist:
    if sum(mylist[0:j])>=X:
        print(len(mylist[0:j]))
        exit()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

X = int(input())

queue = deque()
queue.appendleft((0, 0))

while queue:
    now = queue.pop()
    pos = now[0]
    time = now[1]

    if pos == X:
        print(time)
        exit()

    queue.appendleft((pos + time+1, time+1))
    queue.appendleft((pos, time+1))
    queue.appendleft((pos - (time+1), time+1))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
tot=0
dp = [0 for i in range(n+4)]
for i in range(1, n+1):
	tot=tot+i
	if tot>=n:
		print(i)
		break

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
queue = [(0,0)]
while queue:
  time, location = queue.pop(0)
  if location == X:
    print(time)
    break
  time+=1
  queue.append((time,location+time))
  queue.append((time,location))
  queue.append((time,location-time))

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
# X > 0 なのでマイナス方向にジャンプする選択肢は選ばない
cnt = 0
while X != 0:
    if X != cnt + 1:
        X -= cnt
    cnt += 1
print(cnt - 1)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()
ary = []
for i in range(1,N+1):
    ary.append(i)

cumsum = list(itertools.accumulate(ary))

for i in range(len(cumsum)):
    if cumsum[i] >= N:
        ans = i
        break
print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# BFS
from collections import deque

x = int(input())
q = deque()
q.append((0, 0))
visited = []

while q:
    u = q.popleft()
    if u[0] == x:
        print(u[1])
        break
    visited.append(u)
    if ((u[0]-1, u[1]+1)) not in visited:
        q.append((u[0]-(u[1]+1), u[1]+1))
    if ((u[0], u[1]+1)) not in visited:
        q.append((u[0], u[1]+1))
    if ((u[0]+1, u[1]+1)) not in visited:
        q.append((u[0]+(u[1]+1), u[1]+1))

Submission status: Time Limit Exceeded

Solution code:
d = int(input())
t = 0 
while True:
  if t*(t+1)//2 >=d:
    print(t)
    exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = [e for e in range(n+1)]
if (int((2*n)**(1/2))+1)*(int((2*n)**(1/2)))/2 < n:
    print(int((2*n)**(1/2))+1)
else:
    print(int((2*n)**(1/2)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = [e for e in range(n+1)]
if sum(ls[:int((2*n)**(1/2))+1]) < n:
    print(int((2*n)**(1/2))+1)
else:
    print(int((2*n)**(1/2)))

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

ans = 0
for i in range(1, x + 1):
    L = [i for i in range(1, i + 1)]
    if sum(L) >= x:
        ans = i
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ABC 056 C
X =int(input())
L = [int(i) for i in range(X+1)]
from itertools import accumulate
for ind,val in enumerate(list(accumulate(L))):
    if val >=X:
        print(ind)
        exit()

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
count=0
x=[[0]]
for k in range(0,1000000):
    if X in x[k]:
        print(k)
        break
    x.append(list(set(x[k])))
    for j in range(len(x[k])):
        x[k+1].append(x[k][j]+k+1)
        x[k+1].append(x[k][j]-k-1)
    x[k+1]=list(set(x[k+1]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

X = int(input())

q = deque()
q.append((0, 1))

while len(q) > 0:
    pos = q.popleft()
    if pos[0] + pos[1] == X or pos[0] - pos[1] == X:
        print(pos[1])
        break
    q.append((pos[0] + pos[1], pos[1] + 1))
    q.append((pos[0] - pos[1], pos[1] + 1))
    q.append((pos[0]         , pos[1] + 1))

Submission status: Time Limit Exceeded

Solution code:
x=int(input())
time=0
long=0
for i in range(1,2*x):
    if long<x:
        long+=i
        time+=1
print(time)

Submission status: Time Limit Exceeded

Solution code:
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    def main():
        X=int(input())
        d=deque([1,0,-1])
        now=2
        while True:
            for i in range(3**(now-1)):
                dd=d.popleft()
                if dd==X:
                    return now
                else:
                    d.append(dd+now)
                    d.append(dd)
                    d.append(dd-now)
            now+=1
    print(main()-1)






resolve()

Submission status: Time Limit Exceeded

Solution code:
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    X=int(input())
    d=deque([[0,0]])

    while True:
        dd=d.popleft()
        if dd[0]==X:
            print(dd[1])
            break
        else:
            d.append([dd[1]+1+dd[0],dd[1]+1])
            d.append([dd[0],dd[1]+1])
            d.append([-(dd[1]+1)+dd[0],dd[1]+1])






resolve()

Submission status: Time Limit Exceeded

Solution code:
def main():
    x = int(input())

    i = 1
    p = 0
    while True:
        if i == (x - p):
            print(i)
            break
        if i + 1 == (x - p):
            print(i + 1)
            break
        else:
            p += i
            i += 1


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
X=int(input())
ava={0}
ava2={0}

for i in range(1,10**9):
  ava=copy.deepcopy(ava2)
  #print(i,ava,ava2)
  if X not in ava:
    for item in ava: 
      ava2.add(item+i)
      ava2.add(item-i)
  else:
    print(i-1)
    break

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

ans = 0
loc = 0
while loc < X:
    ans += 1
    for i in range(ans):
        loc += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
A = [i for i in range(1, x//2+1)]
if sum(A) < x: print(x//2 + 1)
else: print(x//2)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())

Q = deque()
Q.append(0)
i = 1
f = False
while Q:
  Q2 = Q
  Q = []
  for t in Q2:
    if t+i == N or t-i == N:
      print (i)
      f = True
      break
    Q.append(t-i)
    Q.append(t)
    Q.append(t+i)
  if f: break
  i += 1

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
len = 0
flag = False
for i in range(1,X+1):
    if flag:
        break
    for j in range(i):
        len += 1
        if len >= X:
            flag = True
            ans = i
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
#幅
from collections import deque
def dfs_2(start,goal):
  q = deque([])   # スタック
  q.append([start])
  flg = 0
  while flg==0:
    p = q.popleft()         # スタック取りだし（先頭）
    jp = len(p)
#    if p[-1]-jp == goal or p[-1]+jp == goal:
    if p[-1]+jp == goal:
      return jp
    else:
      p0 = [p[-1]]
      pp = [p[-1]+jp]
#      pm = [p[-1]-jp]
      q.append(p+pp)# スタック追加
#      q.append(p+pm)
      q.append(p+p0)

print(dfs_2(0,X))

Submission status: Time Limit Exceeded

Solution code:
def main():
    x=int(input())
    ans=abs(x)
    L=[0]
    for i in range(1,10**9):
        P=L[:]
        for l in L:
            P.append(l+i)
            P.append(l-i)
        if x in P:
            print(i)
            break
        L=P[:]
main()

Submission status: Time Limit Exceeded

Solution code:
# ABC056c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

x = int(input())


def calc(time, pos):
    if pos == x:
        return time
    if pos > x:
        return -1
    for i in range(time+1, x+1):
        result = calc(i, pos+i)
        if result != -1:
            return result
    return -1


print(calc(0, 0))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import bisect
if sys.platform in ['ios', 'win32', 'darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(x) for x in input().split()]

X = INT()

tmp = np.cumsum(range(X+1))

#print(tmp)
print(bisect.bisect_left(tmp, X))

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
#幅
from collections import deque
def dfs_2(start,goal):
  q = deque([])   # スタック
  q.append([start])
  flg = 0
  while flg==0:
    p = q.popleft()         # スタック取りだし（先頭）
    jp = len(p)
    if p[-1]-jp == goal or p[-1]+jp == goal:
      return jp
    else:
      p0 = [p[-1]]
      pp = [p[-1]+jp]
      pm = [p[-1]-jp]
      q.append(p+pp)# スタック追加
      q.append(p+pm)
      q.append(p+p0)

print(dfs_2(0,X))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
x=int(input())

c=1
while True:
    c+=1
    z=sum(range(c))
    if(z>=x):
        print(c-1)
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import bisect
x=int(input())
l=[(i*(i+1))//2 for i in range(100000000)]
print(bisect.bisect_left(l,x))

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, N+1))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    from itertools import accumulate
    S = [i for i in accumulate(range(1, N+1))]

    def is_ok(mid):
        if N <= S[mid]:
            return True
        else:
            return False

    def binary_search_meguru():
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid):
                right = mid
            else:
                left = mid
        return right

    ans = binary_search_meguru() + 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
x = int(input())
xx = x//2
a = []
s = 0
for i in range(xx):
	s += i+1
	a.append(s)
	#print (s)

r = bisect.bisect_left(a, x)
print (r+1)

Submission status: Time Limit Exceeded

Solution code:
import bisect
x = int(input())
xx = x//2
a = []
s = 0
for i in range(x):
	s += i+1
	a.append(s)
	#print (s)

r = bisect.bisect_left(a, x)
print (r+1)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
X=int(input())

if X==1:
    print(1)
    exit()
elif X==2:
    print(2)
    exit()

l=[1]
i=2
while True:
    temp=[]
    for item in l:
        temp.append(item+i)
    if X in temp:
        print(i)
        exit()
    else:
        l+=temp
        i+=1

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
x = int(input())
que = deque()
count = 0

que.append((count, 0, 0, 0))

while len(que) > 0:
    depth, v1, v2, v3 = que.popleft()
    if any([val == x for val in (v1, v2, v3)]):
        break
    depth += 1
    for v in (v1, v2, v3):
        que.append((depth, v - depth, v, v + depth))

print(depth)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

def jump(s, t):
    ns = set()
    for n in s:
        ns.add(n - t)
        ns.add(n)
        ns.add(n + t)
    return ns

def main():
    t = 0
    curr = set([0])
    while X not in curr:
        t += 1
        curr = jump(curr, t)
    print(t)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
X = int(input().strip())
states = {0}
for i in range(1,X+1):
  next_set = {s+i for s in states}
  if X in next_set:
    print(i)
    break
  states |= next_set

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
x = [i for i in range(0, X+1)]
count = 0
ans = 0

for i in x:
    ans += 1
    count += i
    if X <= count+i+1:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
dp = set([0])

ans = 0
while X not in dp:
    ans += 1
    for i in list(dp):
        if i + ans not in dp:
            dp.add(i + ans)
        if i - ans not in dp:
            dp.add(i - ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

X = int(input())

dic = {}
dic[0] = 1

time = 0

while True:

    time += 1

    dicc = dic.copy()
    for i in dicc:

        dic[i + time] = 1
        dic[i - time] = 1

    if X in dic:
        break

print (time)

Submission status: Time Limit Exceeded

Solution code:
x=int(input())
import queue

q = queue.Queue()

q.put(0)
q.put("")
count=1
while 1:
    now=q.get()
    if now=="":
        count+=1
        q.put("")
        continue
    if now+count==x or now-count==x:
        print(count)
        break
    q.put(now+count)
    q.put(now)
    q.put(now-count)

Submission status: Time Limit Exceeded

Solution code:
def main():
	X = int(input())
	cur = 0
	p = 0
	for _ in range(X):
		if cur == p:
			cur += 1
			p = 1
		else:
			p += 1
	print(cur)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
for i in range(10**5):
    s = sum(range(i))
    if s < X <= s + i:
        break
print(i)

Submission status: Time Limit Exceeded

Solution code:
import queue
x = int(input())

q = queue.Queue()
q.put((0,0))
d = dict()
d[0] = 0
while not q.empty():
    s,t = q.get()
    if s==x:
        break
    if not d.__contains__(s-(t+1)):
        q.put((s-(t+1),t+1))
        d[s-(t+1)]=t+1
    if not d.__contains__(s+t+1):
        q.put((s+t+1,t+1))
        d[s+t+1]=t+1
    q.put((s,t+1))
print(d[x])

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
d = {0: None}
i = 0
while(True):
    flag = False
    i += 1
    d_keys = list(d.keys())
    for di in d_keys:
        xx = [di - i, di + i]
        if x in xx:
            flag = True
            break
        else:
            d[xx[0]] = None
            d[xx[1]] = None
    if flag:
        break
print(i)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
from collections import deque
q = deque([[0, 0]])
while q:
    xi, i = q.popleft()
    if xi == x:
        print(i-1)
        exit()
    q.append([xi, i+1])
    q.append([xi+i, i+1])
    q.append([xi-i, i+1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/24
Solved on 2019/3/
@author: shinjisu
"""


# ABC 056 C - Go Home
def getInt(): return int(input())
def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob_TLE():
    d = Debug()
    d.off()
    X = getInt()
    d.dmp((X), 'X')
    pos = [0]
    for i in range(1, 10*9+1):
        nextPos = []
        for a in pos:
            nextPos.append(a-i)
            nextPos.append(a)
            nextPos.append(a+i)
        pos = nextPos
        d.dmp((pos), 'pos')
        if X in pos:
            break
    return i


def prob():
    d = Debug()
    d.off()
    X = getInt()
    d.dmp((X), 'X')
    pos = set([0])
    for i in range(1, 10**9+1):
        nextPos = set()
        for a in pos:
            nextPos.add(a-i)
            nextPos.add(a)
            nextPos.add(a+i)
        pos = nextPos
        #d.dmp((pos), 'pos')
        if X in pos:
            break
    return i


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)