description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
from sys import stdin input = stdin.readline T = int(input()) for _ in range(T): a, b = map(int, input().split()) res = 0 for i in range(1, 35000): rb = (a - i) // i rb = min(rb, b) - i if rb > 0: res += rb print(res)
ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
t = int(input()) for lll in range(0, t): x, y = map(int, input().split()) print(sum(max(0, min(y, x // i - 1) - i) for i in range(1, int(x**0.5) + 1)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
for p in [*open(0)][1:]: a, b = map(int, p.split()) s = 0 j = 0 while j < b: j += 1 if a <= j * j + j or b <= j: break s += min(a // j - 1, b) - j print(s)
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
def db(*arg): print(*arg) T = int(input()) ans_ls = [0] * T for t in range(T): A, B = map(int, input().split()) ans = 0 for k in range(1, int(A**0.5) + 10): big_b = A // k - 1 big_b = min(big_b, B) add = max(0, big_b - k) ans += add ans_ls[t] = ans for ans in ans_ls...
FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER...
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
import sys input = sys.stdin.readline t = int(input()) while t: t -= 1 x, y = map(int, input().split()) k = 1 ans = 0 while k * (k + 2) <= x: mx = x // k ans += max(0, min(y + 1, mx) - (k + 2) + 1) k += 1 print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_O...
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
import sys def main(): t = int(input()) allAns = [] def findNext(b, x, y): add = y change = calcChange(x, b) while add > 0: while b + add <= y and calcChange(x, b + add) == change: b += add add //= 2 return b + 1 def calcChange(...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VA...
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
t = int(input()) for _ in range(t): x, y = (int(x) for x in input().split()) ans = 0 for i in range(1, int(x**0.5) + 1): k = min((x - i) // i - i, y - i) if k <= 0: break ans += k print(ans)
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR EX...
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
T = int(input()) for _ in range(T): x, y = [int(z) for z in input().split()] c = 1 result = 0 done = False while True: extra = max(min((x - c) // c, y) - c, 0) result += extra if extra == 0: done = True break c += 1 print(result)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ...
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
p = lambda: list(map(int, input().split())) for _ in "." * p()[0]: a, b = p() s = j = 0 while j < b: j += 1 if a <= j * j + j or b <= j: break s += min(a // j - 1, b) - j print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR BIN_OP STRING FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A pair of positive integers $(a,b)$ is called special if $\lfloor \frac{a}{b} \rfloor = a mod b$. Here, $\lfloor \frac{a}{b} \rfloor$ is the result of the integer division between $a$ and $b$, while $a mod b$ is its remainder. You are given two integers $x$ and $y$. Find the number of special pairs $(a,b)$ such that $...
t = int(input()) for _ in range(t): def main(): x, y = map(int, input().split()) res = 0 cur = 1 while 1: end = min(x // cur - 1, y) if end < cur + 1: return res res += end - cur cur += 1 print(main())
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER RETURN VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL V...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) while t > 0: t -= 1 n, b = [int(i) for i in input().split()] if int(n % b) == 0: print(n - int(n / b) + 1) else: print(n - int(n / b))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def check(n, m): ct = 0 if n >= m: ct = int(n / m) ct += check(int(n / m) + int(n % m), m) return ct def bsearch(n, m): lo = 1 hi = n while lo < hi: mid = int((lo + hi) / 2) val = mid + check(mid, m) if val >= n: hi = mid else: ...
FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VA...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) while t: n, b = list(map(int, input().split())) ans = n - n // b if b == 1: print(1) elif n % b: print(ans) else: print(ans + 1) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
for _ in range(int(input())): n, b = input().split() n, b = int(n), int(b) a = int(n / b) c = n - a if n % b == 0: c += 1 print(c)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) i = 0 while t > i: n, b = map(int, input().split()) ans = n - n // b if b == 1: print(1) elif not n % b: print(ans + 1) else: print(ans) i += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) for j in range(t): a, b = list(map(int, input().split())) L = 1 R = a while R - L > 1: mid = (L + R) // 2 cookies = mid crumbles = 0 hours = mid while cookies > b - 1: crumbles = cookies % b hours += cookies // b ...
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 NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN ...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) for _ in range(t): n, b = map(int, input().split()) low = 0 high = n while low < high: mid = (low + high) // 2 cook = mid left = mid while True: book = left // b if book == 0: break left = book + left % ...
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 NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) for i in range(t): n, b = list(map(int, input().split())) a = n - n // b if n % b == 0: a = a + 1 print(a)
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 BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def f(): t = int(input()) while t > 0: t -= 1 n, b = map(int, input().split()) if b >= n: print(n) elif n % b == 0: ans = (n // b - 1) * (b - 1) + b print(ans) else: ans = ((n - 1) // b - 1) * (b - 1) + b + (n - 1) % b ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def resck(a, c): cr = a net = a while cr >= c: new = cr // c net += new cr -= new * (c - 1) return net for _ in range(int(input())): n, b = map(int, input().split()) lo = 0 hi = n while hi - lo > 1: md = (lo + hi) // 2 if resck(md, b) < n: ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR 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 NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def count(mid, b): ans = mid crumb = mid while crumb >= b: ans += crumb // b crumb = crumb // b + crumb % b return ans for _ in range(int(input())): n, b = map(int, input().split()) low = 1 high = 10**11 while low <= high: mid = (low + high) // 2 if coun...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR 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 NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP ...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
test = int(input()) while test != 0: test = test - 1 n, b = map(int, input().split()) pp = n // b ans = n - pp if n % b == 0: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
for _ in range(int(input())): n, k = map(int, input().split()) p = n sum = 0 while n // (k + 1) != 0: sum += n // (k + 1) n -= k * (n // (k + 1)) print(p - sum)
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 VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def cookies(N, B): ans = N crumbs = N while crumbs >= B: ans += crumbs // B crumbs = crumbs // B + crumbs % B return ans def b_search(N, B): low = 1 high = N ans = N while low < high: mid = low + (high - low) // 2 qty = cookies(mid, B) if qty >= ...
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN V...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) for _ in range(t): n, b = map(int, input().split()) low = 1 high = n if b == 1: print(1) continue while low < high and abs(high - low) > 4: mid = (low + high) // 2 a = mid // b aa = mid % b d = mid while a: d += a ...
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 NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VA...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def finder(k): eaten = 0 crumbs = 0 while k > 0: eaten += k crumbs += k k = crumbs // b crumbs %= b return eaten def search(N): lo = 1 hi = N while lo < hi: mid = (lo + hi) // 2 total = finder(mid) if total < n: lo = mid +...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VA...
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) for i in range(t): n, b = map(int, input().split()) x = n // b if n % b == 0: a = n - x + 1 else: a = n - x print(a)
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 BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
t = int(input()) for i in range(t): n, b = map(int, input().split(" ")) if n == b: print(n) elif n % b == 0: print(n - n // b + 1) else: print(n - n // b)
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 STRING IF VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
Chef is baking delicious cookies today! Since Chef is super hungry, he wants to eat at least $N$ cookies. Since Chef is a messy eater, he drops a lot of crumbs. Crumbs of $B$ cookies can be put together to make a new cookie! Given $N$ and $B$, help Chef find out the minimum number of cookies he must initially bake, $A...
def fun(n, b): if n <= b: return n n = n - 1 a = n // b d = b - 1 r = n % b return 1 + a * d + r t = int(input()) l = [] for i in range(t): n, b = tuple(map(int, input().split())) l.append(fun(n, b)) for i in l: print(i)
FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC...
Bob is about to take a hot bath. There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ...
def gcd(a, b): if a % b == 0: return b else: return gcd(b, a % b) [t1, t2, x1, x2, t0] = input().split(" ") t1 = int(t1) t2 = int(t2) x1 = int(x1) x2 = int(x2) t0 = int(t0) a = t2 - t0 b = t0 - t1 if a == 0 and b == 0: print(x1, x2) exit(0) if a == 0: y1 = 0 y2 = x2 print(y...
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN LIST VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR A...
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and ...
def works(X, N, M, K): res = 0 n = 1 div = X / M while n < div: res += M n += 1 while n < N + 1: res += (X - 1) // n n += 1 return res def solve(): N, M, K = [int(s) for s in input().split()] left = 1 right = K + 1 while right - left > 1: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP...
Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and ...
from sys import stdin n, m, k = [int(x) for x in stdin.readline().split()] be, en = 1, k + 1 while be < en: mid = be + en + 1 >> 1 be1, cur = (mid + m - 1) // m, 0 for i in range(1, be1): cur += m for i in range(be1, n + 1): cur += (mid - 1) // i if cur <= k - 1: be = mid ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ...
Concatenation of two integers is obtained as follows: First, convert both integers to strings. Then concatenate both strings into one and convert this concatenated string back to integer. For example, concatenation of 6 and 7 is CONC(6, 7) = 67, concatenation of 123 and 45 is CONC(123, 45) = 12345. You are given an a...
def main(): for _ in range(int(input())): n, L, R = map(int, input().split()) a = sorted(map(int, input().split())) c = 0 ls = [] rs = [] l, r = 0, n - 1 for i in range(n - 1, -1, -1): while l < n and not L <= int(str(a[l]) + str(a[i])): ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUM...
Concatenation of two integers is obtained as follows: First, convert both integers to strings. Then concatenate both strings into one and convert this concatenated string back to integer. For example, concatenation of 6 and 7 is CONC(6, 7) = 67, concatenation of 123 and 45 is CONC(123, 45) = 12345. You are given an a...
from sys import stdin, stdout input = stdin.readline for _ in range(int(input())): n, L, R = map(int, input().split()) a = list(map(int, input().split())) a.sort() s = 0 ls = [0] * n rs = [0] * n l, r = 0, n - 1 for i in range(n - 1, -1, -1): while l < n and L > int(str(a[l]) + ...
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: pow2 = set() for i in range(30): pow2.add("".join(sorted(str(1 << i)))) def reorderedPowerOf2(self, N: int) -> bool: return "".join(sorted(str(N))) in self.pow2
CLASS_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR FUNC_DEF VAR RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: def is_power_of_two(c): return bin(int("".join(c))).count("1") == 1 permutations = itertools.permutations(str(N)) for cand in permutations: if cand[0] != "0" and is_power_of_two(cand): ret...
CLASS_DEF FUNC_DEF VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER STRING FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: def backtrack(idx, num): if idx == L: if num in two_set: return True return False for v in counter: if idx == 0 and v == "0": continu...
CLASS_DEF FUNC_DEF VAR FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR VAR IF VAR NUMBER VAR STRING IF VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR AS...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: n_hash = {} n_str = str(N) for c in n_str: n_hash[c] = n_hash.get(c, 0) + 1 for i in range(0, 31): num = pow(2, i) if len(str(num)) > len(str(N)): return False ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
from itertools import permutations class Solution: def reorderedPowerOf2(self, x: int) -> bool: n = 1 pows = set() for i in range(31): pows.add(n) n <<= 1 for p in permutations(str(x)): if p[0] == "0": continue if int...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING IF FUNC_CALL VAR FUNC_CALL STRING VAR VAR RETURN NUMBER RETURN NUMBER VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: maxn = 10**9 twopower = 1 twosets = set() while twopower <= maxn: twosets.add(twopower) twopower *= 2 permutations = self.get_all_permutation(N) for p in permutations: if...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER STRING FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIG...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
from itertools import permutations class Solution: def reorderedPowerOf2(self, N: int) -> bool: Nstr = str(N) pset = set("".join(p) for p in permutations(Nstr)) bmk = 1 while len(str(bmk)) < len(Nstr): bmk *= 2 while len(str(bmk)) == len(Nstr): if s...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NU...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
import itertools class Solution: def reorderedPowerOf2(self, N: int) -> bool: if N == 1: return True digits = self._getDigits(N) ones = {2, 4, 6, 8} & set(digits) if not ones: return False for o in ones: digits.remove(o) if s...
IMPORT CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR VAR IF VAR RETURN NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER VAR FUNC_DEF ASSIGN VAR LIST WHILE VA...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: sn = sorted(str(N)) for i in range(32): pot = 1 << i spot = sorted(str(pot)) if sn == spot: return True return False
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: if N == 1: return True elif N == 2: return True max_v = int("".join(sorted(list(str(N)), reverse=True))) canidates = 2 while True: print(canidates) if len(str(canidat...
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: main = list(map(Counter, [str(2**n) for n in range(0, 30)])) return any(Counter(str(N)) == mape for mape in main) 1892
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR NUMBER VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, n: int) -> bool: n_len = len(str(n)) n = Counter(str(n)) p = 1 while len(str(p)) <= n_len: if len(str(p)) == n_len and Counter(str(p)) == n: return True p *= 2 return False
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def reorderedPowerOf2(self, N: int) -> bool: pow_sigs = set() twon = 1 while twon <= 10**9: sig = [0] * 10 s = str(twon) for c in s: sig[int(c)] += 1 pow_sigs.add(tuple(sig)) twon *= 2 n_sig ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FO...
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
from itertools import permutations class Solution: def reorderedPowerOf2(self, N: int) -> bool: res = False for n in permutations(str(N)): if n[0] == "0": continue n = int("".join(n)) res = max(res, not n & n - 1) return res
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR VAR
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2.   Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false E...
class Solution: def helper(self, level, chars): if level == len(chars): temp1 = "".join(chars) if temp1[0] == "0": return 0 if temp1 in self.been: return self.been[temp1] temp = bin(int(temp1)).count("1") if temp ==...
CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER STRING RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR V...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has a sequence $A$ consisting of $N$ positive integers. He is playing a game with this sequence. The goal of the game is to maximize the greatest common divisor of all elements of the sequence. Chef may perform the following operatio...
sv = [True] * 101 bpr = [2] for ap in range(3, 101, 2): if sv[ap]: bpr.append(ap) for ml in range(ap * ap, 101, ap): sv[ml] = False for _ in range(int(input())): n = int(input()) z = input().split() a = list(map(int, z[:n])) g = a[0] for ai in a: ai %= g ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUN...
Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has a sequence $A$ consisting of $N$ positive integers. He is playing a game with this sequence. The goal of the game is to maximize the greatest common divisor of all elements of the sequence. Chef may perform the following operatio...
def findmin(m, arr): st = -1 en = n - 1 while en - st > 1: md = (st + en) // 2 if arr[md] < m: st = md else: en = md return en sv = [True] * 101 bpr = [2] for ap in range(3, 101, 2): if sv[ap]: bpr.append(ap) for ml in range(ap * ap, ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def isPalindrome(self, s): i = 0 j = len(s) - 1 while i < j: if s[i] != s[j]: return False i += 1 j -= 1 return 1 def palindromepair(self, n, arr): mp = {} for i in range(n): s = arr...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VA...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): d = [] for i in arr: if i[::-1] in d: return 1 d.append(i) st1 = set(arr) st2 = set() for i in st1: st2.add(i[::-1]) for s in st1: n = len(s) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN NUM...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): def is_palindrome(s): return s == s[::-1] words = {} for i in range(N): words[arr[i]] = i for i in range(N): for j in range(len(arr[i]) + 1): prefix, suffix = arr[i][:j], arr[i][j...
CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUMBER IF FUNC_CA...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
import time class Solution: def __init__(self): self.star_time = time.time() def palindromepair(self, N, arr): for i in range(len(arr)): for e in range(N): if N > 600 and time.time() - self.star_time > 8: return 0 j = N - 1 - e ...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): words = {word: i for i, word in enumerate(arr)} for i, word in enumerate(arr): if word[::-1] in words and words[word[::-1]] != i: return 1 if word[::-1][0:-1] in words and words[word[::-1][0:-1]] != i: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER NUMBER NUMBER VAR RETURN NUMBER IF VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER NUMBER NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class TrieNode: def __init__(self): self.children = [None] * 26 self.eos = 0 def insert(root, key): curr = root for char in key: index = ord(char) - 97 if not curr.children[index]: newNode = TrieNode() curr.children[index] = newNode curr = c...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VA...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class TrieNode: def __init__(self): self.links = [None] * 26 self.id = -1 self.pos = [] self.isEnd = False class Trie: def __init__(self): self.root = TrieNode() def isPalindrome(self, s, i, n): while i < n: if s[i] != s[n]: re...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Node: def __init__(self): self.links = [None for _ in range(26)] self.flag = False def is_present(self, ch): return self.links[ord(ch) - ord("a")] is not None def insert(self, ch): self.links[ord(ch) - ord("a")] = Node() def next(self, ch): return self.l...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NONE FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_DEF RETURN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBE...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): rev_hashMap = {w[::-1]: i for i, w in enumerate(arr)} for ind, w in enumerate(arr): for i in range(len(w)): l, r = w[: i + 1], w[i + 1 :] if l == l[::-1] and r in rev_hashMap and rev_hashMap[r] != ind: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): index_dict = {word: i for i, word in enumerate(arr)} for i, word in enumerate(arr): for j in range(len(word) + 1): left_side = word[:j] right_side = word[j:] if left_side == left_side[::-1]...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUMBER IF VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUM...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
def is_palindrome(string): return string == string[::-1] class Trie: def __init__(self): self.root = {} def insert(self, word, index): curr_node = self.root n = len(word) for i in range(n - 1, -1, -1): char = word[i] if char not in curr_node: ...
FUNC_DEF RETURN VAR VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR DICT IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR VAR VAR IF STRING VAR ...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, words): ans = set() index = {word: i for i, word in enumerate(words)} for i, word in enumerate(words): for j in range(len(word) + 1): left = word[:j] right = word[j:] if left == left[::-1...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR IF VAR VAR NUMBE...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class StringTrie: class Node: def __init__(self): self.parent = None self.childmap = {} self.terminal = None self.tcount = 0 def terminal_iter(self): if self.terminal: yield self.terminal for c, child in sorte...
CLASS_DEF CLASS_DEF FUNC_DEF ASSIGN VAR NONE ASSIGN VAR DICT ASSIGN VAR NONE ASSIGN VAR NUMBER FUNC_DEF IF VAR EXPR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR EXPR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NONE IF VAR NONE ASSIGN VAR FU...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): reverse = dict() for index, word in enumerate(arr): reverse[word[::-1]] = index for index, word in enumerate(arr): for i in range(len(word)): prefix, suffix = word[:i], word[i:] if ( ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN NUMBER RETURN NU...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): if N <= 1: return 0 d = {} for i in range(N): d[arr[i][::-1]] = i for i in range(N): x = arr[i] for j in range(len(x) + 1): pre = x[:j] suf = x[j:] ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR RETURN NUMBER IF VAR...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class TrieNode: def __init__(self): self.children = [None] * 26 self.isEndOfWord = False class Trie: def __init__(self): self.root = TrieNode() def insert(self, root, word): def util(root, index, word): if len(word) == index: root.isEndOfWord...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF VAR VAR NONE ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL ...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, n, arr): if n == 1: return 0 d = {} for i in range(n): d[arr[i]] = i for i in range(n): x = arr[i][::-1] if x in d and d[x] != i: return 1 for i in range(n): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR N...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): d = {} for i, j in enumerate(arr): d[j[::-1]] = i for i, j in enumerate(arr): for k in range(len(j)): left = j[: k + 1] right = j[k + 1 :] if left == left[::-1] and righ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR RET...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def __init__(self): self.dp = [] self.mp = {} def createPalindromeDp(self, str): n = len(str) dp = [([False] * n) for i in range(n)] for l in range(1, n + 1): for i in range(0, n - l + 1): j = i + l - 1 if l ==...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR V...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): ans = [] hs = {wrd[::-1]: i for i, wrd in enumerate(arr)} for idx, word in enumerate(arr): for i in range(len(word)): left, right = word[0 : i + 1], word[i + 1 :] if ( not len(l...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VA...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): def isPalindrome(stg, i, j): while i <= j: if stg[i] != stg[j]: return False i += 1 j -= 1 return True dic = {} for i in range(N): dic[...
CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): ans = set() index = {word: i for i, word in enumerate(arr)} for i, word in enumerate(arr): for j in range(len(word) + 1): left = word[:j] right = word[j:] if left == left[::-1]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR IF FUNC_CALL VAR...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def ispal(self, word, i, j): j -= 1 while i < j: if word[i] != word[j]: return False i += 1 j -= 1 return True def palindromepair(self, N, arr): mp = dict() for i in range(N): mp[arr[i][::-1...
CLASS_DEF FUNC_DEF VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR V...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): hashmap = {} for i, val in enumerate(arr): hashmap[val] = i for i, word in enumerate(arr): for j in range(len(word)): prefix = word[:j] suffix = word[j:] if ( ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUM...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class TrieNode: def __init__(self): self.children = {} self.end = False self.ind = -1 class Trie: def __init__(self): self.root = TrieNode() def insert(self, key, ind): curr = self.root for i in key: if i not in curr.children: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR IF VAR VAR NUMBER VAR RETURN NUMBER ...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
def palindrome(S, l, r): while l < r: if S[l] != S[r]: return 0 l += 1 r -= 1 return 1 class TrieNode: def __init__(self): self.chars = [None] * 26 self.idx = -1 self.indices = [] class Trie: def __init__(self): self.root = TrieNo...
FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF F...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): reverse = {arr[i][::-1]: i for i in range(len(arr))} for i in range(0, N): for j in range(len(arr[i])): left, right = arr[i][0 : j + 1], arr[i][j + 1 :] if left == left[::-1] and right in reverse and rever...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER IF VAR VAR NUMBER VAR VAR VAR VA...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def palindromepair(self, N, arr): d = {} for i in range(N): if arr[i] in d: if arr[i] == arr[i][::-1]: return 1 d[arr[i]] = i def isPalindrome(string): n = len(string) if n == 1 or n == 0: ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NU...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class TrieNode: def __init__(self): self.links = [None] * 26 self.endOfWord = False self.ind = set() class Trie: def __init__(self): self.root = TrieNode() def isPalindrome(self, key): n = len(key) for i in range(n // 2): if key[i] != key[n - ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NONE NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIG...
Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome. Example 1: Input: N = 6 arr[] = {"geekf", "geeks", "or","keeg", "abc", "bc"} Output: 1 Explanation:...
class Solution: def ispalin(self, word): p1, p2 = 0, len(word) - 1 while p1 < p2: if word[p1] != word[p2]: return False p1 += 1 p2 -= 1 return True def palindromepair(self, n, words): tmp = [] ans = [] d = {} ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
l = int(input()) a = [(int(x) - 1) for x in input().split()] maxh = max(a) h = [(0) for x in range(maxh + 1)] result = 0 prev = maxh + 1 if len(set(a)) > 20000: for curr in a: if curr > prev: h[prev:curr] = [(0) for _ in range(curr - prev)] result += h[curr] h[curr] += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
N = int(input().strip()) heights = [int(h) for h in input().strip().split()] count = 0 starts = [] for i in range(len(heights)): while len(starts) > 0 and heights[i] > starts[-1][0]: starts.pop() if len(starts) > 0 and heights[i] == starts[-1][0]: count += starts[-1][1] starts[-1][1] += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
a = [(0, 0)] * int(input()) c, l = 0, 1 for i in map(int, input().split()): if a[0][0] < i: a[0] = i, 1 l = 1 else: mid, step = 0, 1 << l.bit_length() while step: step >>= 1 if mid + step < l and a[mid + step][0] >= i: mid += step l...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR WHILE VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
class Stack(object): def __init__(self): self.data = [] def push(self, data): self.data.append(data) def pop(self): if not len(self.data): return None return self.data.pop() def peek(self): if not len(self.data): return None ret...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR RETURN NONE RETURN FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR RETURN NONE RETURN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR WHI...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
N = int(input()) heights = [int(x) for x in input().split()] hstack = [] ret = 0 for hcurr in heights: dup = 0 while hstack and hstack[-1][0] <= hcurr: hprev, duprev = hstack.pop() if hprev == hcurr: dup += 1 + duprev hstack.append((hcurr, dup)) ret += dup * 2 print(ret)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
import sys class stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(self): return self.items.pop() def peek(self): return self.items[len(self.items) - 1] def s...
IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF RETURN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING RETURN VAR CLASS_DEF FUNC_DEF ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
n = int(input()) stack = [] heights = list(map(int, input().strip().split(" "))) count = 0 for h in heights: while stack and stack[-1][0] < h: stack.pop() if stack and stack[-1][0] == h: count += stack[-1][1] stack[-1][1] += 1 else: stack.append([h, 1]) print(count * 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
class Building(object): def __init__(self, height, routes): self.height = height self.routes = routes n = int(input()) skyscrapers = [int(x) for x in input().split()] buildings = [] total_routes = 0 for height in skyscrapers: while buildings and buildings[-1].height < height: building...
CLASS_DEF VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
_ = int(input()) st = [] tot = 0 for x in (int(s) for s in input().split()): while st and st[-1][0] < x: st.pop() if st and st[-1][0] == x: tot += st[-1][1] * 2 st[-1][1] += 1 else: st.append([x, 1]) print(tot)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VA...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
st = [[float("inf"), 0]] input() res = 0 for h in map(int, input().split()): while st[-1][0] < h: st.pop() if st[-1][0] == h: res += st[-1][1] st[-1][1] += 1 else: st.append([h, 1]) print(res * 2)
ASSIGN VAR LIST LIST FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR ...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
def main(): numSkyscrapers = int(input()) hs = input().split() heights = list(map(lambda x: int(x), hs)) currentHeight = heights[0] prevVals = verts = [None] * numSkyscrapers prevValIndex = 0 counts = [None] * numSkyscrapers tsum = 0 for y in range(0, len(heights)): h = heigh...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASS...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
N = int(input()) H = list(map(int, input().split(" "))) stack = [] count = 0 for n in range(0, N): incr = False while len(stack) > 0: h = stack[-1] if H[n] > h[0]: stack.pop() else: if H[n] == h[0]: count += h[1] incr = True ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR NUMBER VAR VA...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
num_ss = int(input()) heights = list(reversed(list(map(int, input().split())))) stack = [] num_paths = 0 for x in range(0, num_ss): height = heights.pop() if stack and stack[len(stack) - 1] < height: old = stack.pop() c = 1 while stack and stack[len(stack) - 1] < height: new ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHIL...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
n = int(input()) arr = [int(x) for x in input().split()] stack = [] ans = 0 i = 0 while i < n: if stack: if arr[i] > stack[-1]: cur = stack[-1] cnt = 0 while stack: if stack[-1] == cur: stack.pop() cnt += 1 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BI...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
n = int(input()) hs = map(int, input().split()) curr = [] count = 0 for i in range(n): h = hs.__next__() while len(curr) > 0 and h > curr[-1][0]: curr.pop() if len(curr) == 0: curr.append([h, 1]) elif h == curr[-1][0]: count += curr[-1][1] curr[-1][1] += 1 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER IF VAR V...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
def bin_search(arr, low, high, item): while low <= high: mid = low + (high - low) // 2 if arr[mid][0] == item: return mid elif arr[mid][0] < item: high = mid - 1 else: low = mid + 1 return low def calc(heights): available = [] last_av...
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR RETURN VAR IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VA...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
def routesForward(skyscrapers, size): count = 0 for i in range(0, size): for j in range(i + 1, size): if skyscrapers[j] > skyscrapers[i]: break elif skyscrapers[j] == skyscrapers[i]: count += 1 return count def routesWithStack(skyscrapers, si...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR WHILE FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VA...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
N = int(input()) heights = list(map(int, input().split(" "))) total = 0 size = 0 v = [0] * N m = [0] * N for i in range(N): h = heights[i] while size > 0 and v[size - 1] < h: size -= 1 if size < 1 or v[size - 1] > h: v[size] = h m[size] = 0 size += 1 total += m[size - 1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF V...
Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers h...
n = int(input()) hs = map(int, input().split()) hhs = sorted(enumerate(hs), key=lambda t: (t[1], t[0])) prev = list(range(-1, n - 1)) next = list(range(1, n + 1)) firsti, firsth = lasti, lasth = hhs[0] block_len = 1 s = 0 for i, h in hhs[1:]: if h == lasth and i == next[lasti]: block_len += 1 lasti ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER A...