description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) a = list(map(int, input().split())) result = [abs(a[x] + a[y] - k) for x in range(n) for y in range(x + 1, n)] minimum = min(result) print(minimum, result.count(minimum))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) while t > 0: n, k = map(int, input().split()) l = list(map(int, input().split())) x = 3 * 10**9 a = [] for i in range(n): for j in range(i + 1, n): a.append(abs(l[j] + l[i] - k)) m = min(a) print(m, a.count(m)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUN...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
def inp(): n, k = input().split() n = int(n) k = int(k) if n >= 2 and n <= 1000: l = list(map(int, input().split())) l = l[:n] le = len(l) s = [] p = [] i = 0 while i < le: j = le - 1 while j > i: s.append(l[...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
tests = int(input()) for i in range(tests): n, k = map(int, input().split()) arr = list(map(int, input().split())) checked_numbers = set() gap = abs(k - (arr[0] + arr[1])) freq = {} for j in range(n): if arr[j] in freq: freq[arr[j]] += 1 else: freq[arr[j]]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for T in range(t): n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] val = abs(a[0] + a[1] - k) c = 0 for i in range(n): for j in range(i + 1, n): if val == abs(a[i] + a[j] - k): c += 1 elif val > abs(a[i] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) for e in range(0, t): n, k = input().strip().split() n = int(n) k = int(k) a = list(map(int, input().strip().split())) low = float("inf") count = 0 for i in range(0, n - 1): for j in range(i + 1, n): if abs(a[i] + a[j] - k) < low: low = ab...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_C...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): a, k = map(int, input().split()) result = [] lst = list(map(int, input().split())) for i in range(len(lst) - 1): for j in range(i + 1, len(lst)): a = abs(lst[i] + lst[j] - k) result.append(a) print(min(result), result.count(min(result)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CA...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): n, k = map(int, input().split()) list1 = list(map(int, input().split())) list1.sort() min1 = 1000000000000001 maxsum = 0 for i in range(len(list1)): for j in range(i + 1, len(list1)): temp = abs(list1[i] + list1[j] - k) if temp < min1...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL V...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
from sys import stdin, stdout def sin(): return stdin.readline().rstrip() def listInput(): return list(map(int, sin().split())) def printBS(li): if not li: return for i in range(len(li) - 1): stdout.write("%d " % li[i]) stdout.write("%d\n" % li[-1]) t = int(sin()) for _ in ra...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): n, k = map(int, input().split()) l = list(map(int, input().split())) d = {} min = 2**31 - 1 for i in range(n): for j in range(i + 1, n): diff = abs(l[i] + l[j] - k) if min > diff: min = abs(l[i] + l[j] - k) if ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUN...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
t = int(input()) while t > 0: n, k = map(int, input().split()) l = list(map(int, input().split())) x = 3 * 10**9 c = 0 for i in range(n): for j in range(i + 1, n): y = abs(l[j] + l[i] - k) if y < x: x = y for i in range(n): for j in range(i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN...
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
for _ in range(int(input())): n, k = list(map(int, input().split())) l = list(map(int, input().split())) l.sort() c = 0 mn = abs(l[0] + l[1] - k) for i in range(n - 1): for j in range(i + 1, n): temp = abs(l[i] + l[j] - k) if temp == mn: c += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP V...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
n, m = input().split() n = int(n) m = int(m) c = 0 f = not (m == 0 and n == 0) a = 1 px = 0 py = 0 while f: co = 0 while co < a: px += 1 co += 1 if n == px and m == py: f = False if not f: break c += 1 co = 0 while co < a: py += 1 co +=...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = list(map(int, input().split())) c = 0 if y == 0 and (x == 0 or x == 1): c = 0 elif abs(x) == abs(y) and x > 0 and y > 0: c = 4 * x - 3 elif abs(x) == abs(y) and x < 0 and y > 0: c = 4 * y - 2 elif abs(x) == abs(y) and x < 0 and y < 0: c = -4 * x - 1 elif abs(x) == abs(y) and x > 0 and y < 0: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR B...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
import time x, y = map(int, input().split()) movements = [(1, 0), (0, 1), (-1, 0), (0, -1)] sizeOfSteps = 1 x_0, y_0 = 0, 0 x_1, y_1 = 1, 0 step = 0 change = 1 while not ( (x_0 <= x <= x_1 or x_0 >= x >= x_1) and (y_0 <= y <= y_1 or y_0 >= y >= y_1) ): step += 1 move_i = movements[step % 4] if change %...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) if x == 1 and y == 0: print(0) exit() a = 4 * (x - 1) + 1 if x > 0 else -4 * x - 1 if x < 0 else 0 b = 4 * y - 2 if y > 0 else -4 * y if y < 0 else 0 if abs(x) == abs(y) and y >= x or y < 0 and abs(x) > abs(y): print(min(a, b)) else: print(max(a, b))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP NUM...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
m, n = map(int, input().split()) x = 1 y = 0 count = 0 if 0 <= m <= 1 and n == 0: print(0) else: while True: a1, a2 = x, y b1, b2 = a1, abs(a2) + 1 if a1 == m and a2 < n <= b2: count += 1 break else: count += 1 c1, c2 = -b1, b2 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = list(map(int, input().split())) dx, dy = [1, 0, -1, 0], [0, 1, 0, -1] def onl(x1, y1, x2, y2): if x1 == x2: return x == x1 and y in range(min(y1, y2), max(y1, y2) + 1) elif y1 == y2: return y == y1 and x in range(min(x1, x2), max(x1, x2) + 1) def sp(cx, cy, t): l = t // 2 + 1 ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def detquad(x, y): if x > 0 and y > 0: return 1 elif x < 0 and y > 0: return 2 elif x < 0 and y < 0: return 3 elif x > 0 and y < 0: return 4 def findprevpoints(x, y): if x == 0: return y, y elif y == 0: if x > 0: return x, -(x - 1) ...
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBE...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = input().split() x, y = int(x), int(y) if x == y == 0: print(0) if y >= -x and y > x: print(4 * y - 2) if x + y < 0 and y >= x: print(4 * abs(x) - 1) if y < x and x + y <= 1: print(4 * abs(y)) if x + y > 1 and y <= x: print(4 * x - 3)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def on(segment, point): start, end = segment if point == start: return False if point == end: return True x1, y1 = start x2, y2 = point x3, y3 = end if x1 == x2 and x2 == x3 and (y1 < y2 < y3 or y3 < y2 < y1): return True if y1 == y2 and y2 == y3 and (x1 < x2 < x3...
FUNC_DEF ASSIGN VAR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
inputs = list(map(int, input().split())) x = inputs[0] y = inputs[1] if y == 0 and 0 <= x <= 1: print(0) else: a = max(abs(x), abs(y)) m = 1 + 4 * (a - 1) if x == a and y == -(a - 1): print(m - 1) if x == a and -(a - 1) < y <= a: print(m) elif y == a and -a <= x < a: prin...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = [int(i) for i in input().split()] if x >= 0: if y > x: zone = 3 elif y <= x and y > -x + 1: zone = 2 else: zone = 1 elif y >= -x: zone = 3 elif y < -x and y >= x: zone = 4 else: zone = 1 if zone == 1: ans = -y * 4 elif zone == 2: ans = 1 + (x - 1) * 4 elif ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def main(): x, y = map(int, input().split()) r, t = max(abs(x), abs(y)), 0 if x == r == 1 - y: t = 4 elif x == r > -y: t = 3 elif y == r > x: t = 2 elif -x == r > y: t = 1 print( { (0, 0): 0, (1, 0): 0, (1, 1): 1, ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER DICT N...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = input().split() x = int(x) y = int(y) p, q, z, i, j = 0, 0, 0, 1, 1 def GT(n): t = 0 for i in range(1, n + 1): if i % 2 != 0: t += i else: t += -i return t while 1: x1, y1 = max(GT(i), GT(i - 1)), min(GT(i), GT(i - 1)) x2, y2 = max(GT(j), GT(j - 1))...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR RETURN VAR WHILE NUMBER ASSIGN VAR VAR FUNC...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = tuple(map(int, input().split())) if x == 0 and y == 0: print(0) elif x >= 0 and y >= -x + 1 and y < x: if y == -x + 1: print(4 * (x - 1)) else: print(4 * (x - 1) + 1) elif y > 0 and (x == 0 or x <= abs(y) and x > -abs(y)): if y == x: print(4 * (abs(y) - 1) + 1) else: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER IF VAR NUMBER...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) sx = sy = 0 c = 0 i = j = 1 while 1: p = sx q = sy if i % 2 == 0: sy = sy + (-1) ** (j - 1) * j j += 1 else: sx = sx + (-1) ** (j - 1) * j if ( (min(p, sx) <= x and x <= max(p, sx)) and (min(q, sy) <= y and y <= max(q, sy)) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) u, v = abs(x), abs(y) a = max(u, v) s = 4 * (a - 1) if u >= v and x > 0 and y > 1 - a: s += 1 elif v >= u and y > 0: s += 2 elif u >= v and x < 0: s += 3 elif v >= u and y < 0: s += 4 print(s if a > 0 else 0)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) isCorner = x == y or -x == y and y > 0 or y == -x + 1 and x is not 0 reachX = 0 if x == 0 else 1 + (x - 1) * 4 if x > 0 else 3 + (abs(x) - 1) * 4 reachY = 0 if y == 0 else 2 + (y - 1) * 4 if y > 0 else abs(y) * 4 if isCorner: print(min(reachX, reachY)) else: print(max(reachX, re...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER BIN_OP...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
p = [(0, 0)] a, b = 0, 0 c = 1 while c < 202: for i in range(c - 1): a += 1 p.append((a, b)) p.append((a + 1, b, "*")) a += 1 for j in range(c - 1): b += 1 p.append((a, b)) p.append((a, b + 1, "*")) b += 1 for k in range(c): a -= 1 p.append((a,...
ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_C...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = [int(i) for i in input().split()] x1, y1 = 0, 0 i = 1 direct = 2 counter = 0 br = 0 res = 0 while x1 != x or y1 != y: if direct == 1: direct = 4 for j in range(i): y1 += 1 if x1 == x and y1 == y: br = 1 break elif direct == 2: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBE...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
a, b = map(int, input().split()) count = 0 q, e = 0, 0 i = 1 flag = 0 while q != a or e != b: for j in range(i): q += 1 if q == a and e == b: flag = 1 break if flag: break count += 1 for j in range(i): e += 1 if q == a and e == b: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = [int(y) for y in input().split()] ans = 0 if (x == 0 or x == 1) and y == 0: print(0) else: ans += 4 * max(abs(x), abs(y)) if x >= 0 and y <= 0: if abs(y) == x - 1: ans -= 4 if abs(y) < x - 1: ans -= 3 elif x >= 0 and y >= 0: if y <= x: a...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMB...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def nextStep(x, y): if x == 0 and y == 0: return 1, 0 if x == 1 and y == 0: return 1, 1 if x > 0 and y > 0: return -x, y if x < 0 and y > 0: return x, -y if x < 0 and y < 0: return -x + 1, y if x > 0 and y < 0: return x, -y + 1 def lie(cor1, cor2...
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR VAR IF VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMB...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
point = list(map(int, input().strip().split())) i = 0 k = 0 segment = [[0, 0], [1, 0]] seg_copy = [segment[0], point, segment[1]] seg_copy.sort(key=lambda j: (j[1 - i], j[i])) turns = 0 while seg_copy[1] != point: turns += 1 segment[0] = list(segment[1]) segment[1][1] = segment[1][0] if k == 0 or k == 2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER ASSIGN VAR N...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
dest = list(map(int, input().split())) side_len = 0 pos = [0, 0] turns = 0 while True: side_len += 1 if dest[1] == pos[1] and pos[0] <= dest[0] <= pos[0] + side_len: break turns += 1 pos[0] += side_len if dest[0] == pos[0] and pos[1] <= dest[1] <= pos[1] + side_len: break turns +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
entry = input().split(" ") x, y = list(map(int, entry)) if abs(y) > abs(x) and y >= 0 or y > 0 and x == -y: x, y = 0, y position = 1 elif abs(x) > abs(y) and x <= 0 or x < 0 and x == y: x, y = x, 0 position = 2 elif abs(y) > abs(x) and y <= 0 or x > 0 and (x == -y or y == -x + 1): x, y = 0, y po...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER I...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x = 0 y = 0 nx, ny = map(int, input().split()) if (nx == 0 or nx == 1) and ny == 0: print(0) else: x = 1 turn = 0 flag = 0 while True: turn = turn + 1 while y != x: y = y + 1 if x == nx and y == ny: flag = 1 break if fla...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) def fn(x, y): if y == 0 and x == 0: return 0 elif x < 0 and x + y == 0: return 4 * abs(y) - 2 elif x == y: if x > 0: return 4 * x - 3 else: return 4 * abs(x) - 1 elif x + y == 1 and x == abs(y) + 1: return...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def point_on_spiral(x_int, y_int) -> int: if x_int == 0 and y_int == 0 or x_int == 1 and y_int == 0: return 0 count = 0 x_prev, y_prev = 0, 0 while True: spiral, count_mod_4 = divmod(count + 4, 4) if count_mod_4 == 0: x_curr, y_curr = spiral, -(spiral - 1) eli...
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) z = max(abs(x), abs(y)) c = (z - 1) * 4 if x == z and y > -z + 1 and y <= z: c += 1 elif x < z and x >= -z and y == z: c += 2 elif x == -z and y < z and y >= -z: c += 3 elif y == -z and x > -z and x <= z + 1: c += 4 print(max(0, c))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP V...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def main(): a, b = list(map(int, input().split())) if a == 0 and b == 0: return 0 x = 0 y = 0 step = 1 rep = 0 direction = 0 ans = 0 while x != a or y != b: if direction == 0: for i in range(step): x += 1 if x == a and y == ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR R...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) i = 0 j = 0 n = 1 cnt = 0 while True: if n % 2 == 1: if cnt % 2 == 0: if i <= x and x <= i + n and j == y: break else: i += n cnt += 1 elif i == x and j <= y and y <= j + n: break ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMB...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) cur_x, cur_y = 0, 0 i = 1 pos = 0 sign = [(1, 0), (0, 1), (-1, 0), (0, -1)] ans = 0 j = 0 while cur_x != x or cur_y != y: if j == i: j = 0 if pos % 2 == 1: i += 1 pos = (pos + 1) % 4 ans += 1 cur_x = cur_x + sign[pos][0] cur_y = cu...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) x1 = abs(x) y1 = abs(y) mx = max(x1, y1) if x == 1 and y == 0: print(0) elif x == 0 and y == 0: print(0) elif x == 2 and y == -1: print(4) elif x1 == y1: if x > 0: if y > 0: print(4 * x1 - 3) elif y < 0: print(4 * x1) elif x < ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR IF VAR N...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = list(map(int, input().rstrip().split())) if x == 0 and y == 0 or x == 1 and y == 0: print(0) elif x > 0 and y in range(-1 * x + 2, x + 1): ans = 1 + 4 * (abs(x) - 1) print(ans) elif y > 0 and x in range(-1 * y, y): ans = 1 + 4 * (y - 1) print(ans + 1) elif x < 0 and y in range(x - 1, abs(x)):...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CAL...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
s = input().split() x = int(s[0]) y = int(s[1]) dirx = [1, 0, -1, 0] diry = [0, 1, 0, -1] if x == 0 and y == 0: print(0) else: cx = 0 cy = 0 dir = 0 steps = 1 count = 0 done = False while not done: for i in range(steps): cx += dirx[dir] cy += diry[dir] ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER AS...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
U = 1 D = -1 x, y = map(int, input().split()) k = A = B = 0 while 1: a, b = U, B k += 1 if (A <= x <= a or a <= x <= A) and (B <= y <= b or b <= y <= B): break A = a b = U k += 1 if (A <= x <= a or a <= x <= A) and (B <= y <= b or b <= y <= B): break B = b a = D k...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR ...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
l = input().split(" ") x, y = int(l[0]), int(l[1]) if y <= 0 and x >= 1 + y and x <= 1 - y: print(-y * 4) elif x > 0 and y >= 2 - x and y <= x: print(x * 4 - 3) elif y > 0 and x >= -y and x <= y - 1: print(y * 4 - 2) elif x < 0 and y >= x and y <= -1 - x: print(-x * 4 - 1) else: print(0)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR V...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
def spiral(): X, Y = list(map(int, input().split())) x = y = 0 dx = 0 dy = -1 turn = 0 if X == 0 and Y == 0: turn = 1 else: while 1: if x == X and y == Y: break if x == y or x < 0 and x == -y or x > 0 and x == 1 - y: dx,...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) start = [0, 0] turns = 0 flag = 0 while [x, y] != [start[0], start[1]] and flag == 0: turns += 1 if turns % 4 == 1: for i in range(2 * (turns // 4 + 1) - 1): start[0] += 1 if [x, y] == [start[0], start[1]]: flag = 1 elif turns ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE LIST VAR VAR LIST VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER I...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) if x == y == 0 or x == 1 and y == 0: print(0) exit() dx = [0, -1, 0, 1] dy = [1, 0, -1, 0] i = 1 ty = 0 tx = 1 c = 0 while 1: i += 0.5 j = 0 c += 1 while j < int(i): tx += dx[(c - 1) % 4] ty += dy[(c - 1) % 4] j += 1 if x == tx and...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR N...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = list(map(int, input().split())) if y >= x and y < -x: print(-4 * x - 1) elif y > x and y >= -x: print(4 * y - 2) elif y <= x and y > 1 - x: print(4 * x - 3) elif y < x and y <= 1 - x: print(-4 * y) else: print(0)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP NUM...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) a, b, cnt = 0, 0, 0 if x == y == 0: print(0) exit() while 1: while a + b != 1: a += 1 if a == x and b == y: print(cnt) exit() cnt += 1 while a - b != 0: b += 1 if a == x and b == y: print(cnt) ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR WHILE NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMB...
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thu...
x, y = map(int, input().split()) sector = 0 flag = 0 if x == 0 and y == 0: flag = 1 elif x == 1 and y == 0: flag = 2 elif x > 0 and y >= 0 and x >= y: sector = 1 elif x > 0 and y < 0 and x > 1 - y: sector = 1 elif x >= 0 and y > 0 and x < y: sector = 2 elif x < 0 and y > 0 and -x <= y: sector = ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def ishappy(n, d): if n == 1: return True elif n in d: return False d[n] = 0 a = str(n) m = 0 for i in a: i = int(i) m = m + i * i...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def util(self, n): s = 0 while n != 0: s += n % 10 * (n % 10) n = n // 10 return s def nextHappy(self, N): i = N + 1 while True: li = [] s = i while 1: s = self.util(s) ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR IF VAR VAR EXPR FUNC_CALL VAR ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
def isHappy(n): k = n d = {} while True: try: if p[k]: return True except: pass s = 0 try: return d[n] except: d[n] = False while n: s += (n % 10) ** 2 n = n // 10 ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR DICT WHILE NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUM...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): while True: N += 1 result = self.isHappy(N) if result: return N def isHappy(self, n): slow = self.squared(n) fast = self.squared(self.squared(n)) while slow != fast and fast != 1: ...
CLASS_DEF FUNC_DEF WHILE NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR NUMBER FUNC_DEF VAR ASSIGN VAR NUMBER WHI...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def recur(self, num): if num == 1 or num == 7 or num == 10: return True if num < 10: return False sm = 0 while num > 0: n = num % 10 sm += n * n num //= 10 return self.recur(sm) def nextHappy(se...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR RETURN VAR VAR NUMBER
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def check(self, n): if n // 10 == 0: n = n % 10 * (n % 10) while n // 10 != 0: N = n nh = 0 while N > 0: nh += N % 10 * (N % 10) N //= 10 n = nh if n == 1: return 1 ...
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def square_sum(self, num): sqaure_sum1 = 0 while num != 0: sqaure_sum1 += (num % 10) ** 2 num //= 10 return sqaure_sum1 def check_indv_num(self, num): slow_ptr = num fast_ptr = num while True: slow_ptr = self.s...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def isHappy(self, N): if N == 1 or N == 7: return 1 sum = N x = N while sum > 9: sum = 0 while x > 0: d = x % 10 sum += d * d x //= 10 if sum == 1: return ...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBE...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def happy(n): s = 0 while n > 0: s += (n % 10) ** 2 n //= 10 if s == 1: return True if s == 4: return False return happy(s) i = N + 1...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER RETURN VAR
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
def sum_of_digits(n): s = 0 while n > 0: s = s + (n % 10) ** 2 n = n // 10 return s def is_happy_num(n): slow = n fast = sum_of_digits(n) while fast != 1 and slow != fast: slow = sum_of_digits(slow) fast = sum_of_digits(sum_of_digits(fast)) if fast == 1: ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER RETU...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def check(self, n): if n in self.prev: return False self.prev.add(n) numbers = [] while n: numbers.append(n % 10) n = n // 10 ans = 0 for i in numbers: ans += i * i if ans == 1: retur...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN V...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def isHappy(n): l = [2, 3, 4, 5, 6, 8, 9] while n != 1: if n in l: return False s = 0 for i in str(n): s += int(i) ** 2 n = s ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR RETURN VAR VA...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
def numSquareSum(n): squareSum = 0 while n: squareSum += n % 10 * (n % 10) n = int(n / 10) return squareSum def isHappynumber(n): st = set() while 1: n = numSquareSum(n) if n == 1: return True if n in st: return False st.add(n...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def ifhappy(self, num): s = 0 for i in str(num): s += int(i) ** 2 if s == 1 or s == 7: return 1 elif len(str(s)) == 1: return 0 return self.ifhappy(s) def nextHappy(self, N): i = 1 while True: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN BIN_...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def rec(n, dic): if n == 1: return True curr = 0 while n != 0: temp = (n % 10) ** 2 curr += temp n //= 10 if curr in dic: return False ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): li = [] for n in range(N, N + 100): p = n count_i = 0 while n != 1: sum_i = 0 for i in str(n): sum_i += int(i) ** 2 n = sum_i count_i += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR RETURN VAR NUMBE...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def isHappy(self, n): k = n while True: k = str(k) digitSqSum = 0 for i in k: digitSqSum += int(i) * int(i) if digitSqSum == 1 or digitSqSum == 7: return True if digitSqSum < 10: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_DEF VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER RETUR...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): for i in range(N + 1, 10000): if self.check(i): return i return -1 def check(self, N): if N == 7 or N == 1 or N == 10: return True elif N < 10: return False sum = 0 while...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FU...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def getSum(self, N): if N == 1 or N == 7 or N == 10: return True if N < 10: return False add = 0 while N > 0: temp = N % 10 add += temp * temp N = int(N / 10) return self.getSum(add) def nextHap...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): dp = {} v = set() def f(i): if i in dp: return dp[i] if i == 1: dp[1] = True return True if i in v: dp[i] = False return False ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETUR...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): n = N + 1 def ishappy(n1, sq): while n1 != 0: rem = n1 % 10 sq += rem * rem n1 = n1 // 10 if n1 == 0: n1 = sq sq = 0 if n1...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER WHILE VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): num = N + 1 while True: isHappy = self.checkHappy(num) if isHappy: return num num += 1 return None def checkHappy(self, n): seen = set() while True: n = self.getNextN...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN VAR VAR NUMBER RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUM...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def check(self, n, l=[]): if n in l: return n == 1 q = sum([(int(x) ** 2) for x in str(n)]) return self.check(q, [*l, n]) def nextHappy(self, N): while True: N += 1 if self.check(N): return N
CLASS_DEF FUNC_DEF LIST IF VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR LIST VAR VAR FUNC_DEF WHILE NUMBER VAR NUMBER IF FUNC_CALL VAR VAR RETURN VAR
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: count = True temp = 0 status = False def nextHappy(self, N): if Solution.count: Solution.temp = N Solution.count = False n = str(N) t = 0 if N == 7 and Solution.status == True: Solution.count = True Solution...
CLASS_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VA...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def numSquareSum(n): squareSum = 0 while n: squareSum += n % 10 * (n % 10) n = int(n / 10) return squareSum def isHappynumber(n): slow = n fast = n while...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR NUMBER WHILE NUMB...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def SumSquare(self, n): summ = 0 while n != 0: dg = n % 10 summ += dg * dg n //= 10 return summ def isHappy(self, n): st = set() st.add(n) while True: if n == 1: return 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER FUNC_DE...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): N += 1 def ishappy(n): s = n while s > 9: s = 0 while n > 0: r = n % 10 s += r**2 n //= 10 if s > 9: n = s...
CLASS_DEF FUNC_DEF VAR NUMBER FUNC_DEF ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR RETURN VAR VAR NUMBER
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
def happy(N): l = 0 while N: r = N % 10 l += r**2 N = N // 10 if l > 9 and N == 0: N = l l = 0 if l == 1: return True return False class Solution: def nextHappy(self, N): N = N + 1 while happy(N) == False: ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NU...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def isHappy(self, n): if n == 1 or n == 7: return True sos = n x = n while sos > 9: sos = 0 while x > 0: d = x % 10 sos += d * d x //= 10 x = sos if sos == 1 or so...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): i = N + 1 while True: j = i l = [] while True: if j in l: break if j == 1: return i sum = 0 l.append(j) ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE NUMBER IF VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def dig(n): while n > 9: s = 0 while n: t = n % 10 s += t * t n //= 10 n = s return n n = N + 1 while True: ...
CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR VAR NUMBER
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, n): p, b = 0, 0 for i in range(n + 1, n + 50): if i == 1 or i <= 7: return 7 else: b = self.check(i) if b == 1: return i def check(self, m): while m >= 10: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR FUNC_DEF WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, n): q = {(1): 1} s = set() def dfs(i): if i in q: return q[i] if i in s: return -1 s.add(i) q[i] = dfs(sum(j * j for j in map(int, [*str(i)]))) return q[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR RETURN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def happy(self, n): s = set() while True: s.add(n) if n == 1: return True val = 0 while n >= 1: val += (n % 10) ** 2 n = n // 10 n = val if n in s: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER FUNC_DEF IF FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RET...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def squaresum(self, n): s = 0 while n != 0: s += n % 10 * (n % 10) n //= 10 return s def nextHappy(self, N): n = N + 1 while True: slow = n fast = n while True: slow = self.squar...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER RETURN...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def happy(n): def new(num): c = 0 while num > 0: a = num % 10 c += a**2 num = num // 10 return c slow = new(n) fast = ne...
CLASS_DEF FUNC_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def digits_N(self, N): num = N digits = [] while num: digits.append(num % 10) num = num // 10 return digits def check_happiness(self, N): num = N non_happy = [] while num > 9: digits = self.digits_N(num...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def fun(i): res = i while res != 1: i = res res = 0 if a[i] == 0: a[i] = 1 while i > 0: res += pow(i % 10, 2) ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER RETUR...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): i = N + 1 while True: if isHappy(i, set()): return i i += 1 def isHappy(N, s): s.add(N) a = N val = N while True: sum_ = 0 while val != 0: k = val % 10 val //= 1...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR RETURN VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER IF VA...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def happy(n): s = 0 while n: r = n % 10 s += r * r n = n // 10 return s def ishappy(n): s = set() while True: n = happy(n) ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR ...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def isHappy(self, N): if N == 1 or N == 7: return True if N < 10: return False result = 0 while N > 0: result += N % 10 * (N % 10) N = N // 10 return self.isHappy(result) def nextHappy(self, N): N +...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR RETURN VAR VAR NUMBER
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): def ishappy(n): s = 0 while n: r = n % 10 s += r**2 n = n // 10 return s for i in range(N + 1, N + 100): t = i while i > 9: i = ishap...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN VAR
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): N = N + 1 while True: if self.ishappy(N): return N N += 1 def ishappy(self, N): sum = 0 while N > 0: digit = N % 10 sum += digit * digit N = N // 10 if su...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR RETURN VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def checkHappyYear(self, N, loopCheck): if N == 1: return True s = 0 while N != 0: s += (N % 10) ** 2 N //= 10 if s in loopCheck: return False loopCheck.add(s) return self.checkHappyYear(s, loopCheck) ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST VAR IF FUNC_CALL VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR NUM...
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we ...
class Solution: def nextHappy(self, N): for j in range(N + 1, N**10): if j == 1 or j == 7: return j q = j while j > 9: i = 0 x = str(j) z = 0 while i < len(x): z = z + int...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NU...