description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = [int(x) for x in input().split()] def fact(n): if n == 0: return 1 br = 1 for i in range(1, n + 1): br *= i return br res = 0 left = 0 right = n countbigger = 0 countsmaller = 0 while left < right: middle = (left + right) // 2 if middle == pos: left = midd...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
M = 10**9 + 7 def inv(n): return power(n, M - 2) def power(x, y): ans = 1 while y > 0: if y % 2 == 1: ans = ans * x % M y = y // 2 x = x * x % M return ans % M def com(n, r): if r == 0: return 1 else: return f[n] * inv(f[n - r]) % M % M ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RE...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
vals = input().split() n = int(vals[0]) x = int(vals[1]) pos = int(vals[2]) big = 0 small = 0 ans = 1 l, r = 0, n while l < r: mid = (l + r) // 2 if mid == pos: l = mid + 1 elif mid > pos: r = mid big += 1 else: l = mid + 1 small += 1 if small >= x or big > n - x:...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = map(int, input().split()) ans = 1 m = 10**9 + 7 a = x - 1 b = n - x l = 0 h = n c = 0 while l < h: mid = (l + h) // 2 c += 1 if pos >= mid: if pos == mid: l = mid + 1 else: ans *= a ans %= m l = mid + 1 a -= 1 else: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR AS...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def bin_search(a, x): left = 0 right = len(a) j = 0 l = 0 while left < right: j += 1 middle = (left + right) // 2 if a[middle] <= x: l += 1 left = middle + 1 else: right = middle if left > 0 and a[left - 1] == x: return ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR F...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p mod = 10**9 + 7 t = 1 for _ in range(t): n, x, pos = map(int, input().split()) left = 0 right = n a = 0 b = 0 while left < right: ...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIG...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def main(): n, x, pos = map(int, input().split()) zero, one = 0, 0 l, r = 0, n while l < r: middle = (l + r) // 2 if middle <= pos: zero += 1 l = middle + 1 else: one += 1 r = middle res = 1 mod = 10**9 + 7 for i in rang...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = [int(k) for k in input().split()] ans = 1 greater = n - x smaller = x - 1 left = 0 right = n mid = n while left < right: mid = (left + right) // 2 if mid < pos: ans *= smaller ans = ans % 1000000007 smaller -= 1 left = mid + 1 elif mid > pos: ans *= greate...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def algo(arr, y): ans = [] left = 0 right = len(arr) while left < right: middle = (left + right) // 2 ans.append(arr[middle]) if arr[middle] <= y: left = middle + 1 else: right = middle if left > 0 and arr[left - 1] == y: return True, a...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER VAR RETURN NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
from sys import stdin, stdout mod = 10**9 + 7 def binarySearch(arr, x, pos): l = 0 r = len(arr) left = 0 right = 0 while l < r: mid = (l + r) // 2 if mid < pos: left += 1 if mid > pos: right += 1 if arr[mid] <= x: l = mid + 1 ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = map(int, input().split()) large = 0 small = 0 mod = 10**9 + 7 l, h = 0, n while l < h: m = (l + h) // 2 if m <= pos: if m != pos: small += 1 l = m + 1 else: h = m large += 1 great, less = n - x, x - 1 ans = 1 for i in range(large): ans = ans * grea...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VA...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
M = 10**9 + 7 N = 10**3 + 1 fact = [(0) for i in range(N)] fact[0] = 1 for i in range(1, N): fact[i] = i % M * fact[i - 1] % M % M invfact = [(0) for i in range(N)] invfact[N - 1] = pow(fact[N - 1], M - 2, M) for i in range(N - 2, -1, -1): invfact[i] = invfact[i + 1] % M * (i + 1) % M % M def ncr(n, r): i...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VA...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def fact(n): ans = 1 for i in range(1, n + 1): ans *= i return ans mod = 10**9 + 7 def search(A, x): lo = 0 hi = len(A) fixed = set() while lo < hi: mid = (lo + hi) // 2 fixed.add(mid) if A[mid] <= x: lo = mid + 1 else: hi =...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN V...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
lm = 1010 f = {(0): 1} mod = 10**9 + 7 for i in range(1, lm): f[i] = i * f[i - 1] % mod def BnS(pos, n): l, r = 0, n sm, bg = 0, 0 while l < r: m = (l + r) // 2 if m <= pos: sm += 1 l = m + 1 else: bg += 1 r = m return sm, bg ...
ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR N...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, p = map(int, input().split()) mod = 1000000007 small = x - 1 large = n - x arr = [(-1) for x in range(n)] l, r = 0, n while l < r: mid = (l + r) // 2 if mid <= p: if mid == p: arr[mid] = 1 else: arr[mid] = small small -= 1 small = max([0, sma...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def comb(n, x): a, b = 1, 1 for i in range(1, x + 1): a *= n + 1 - i b *= i return a // b % mod def fact(n): val = 1 for i in range(1, n + 1): val = val * i % mod return val % mod mod = 1000000007 n, x, pos = map(int, input().split()) less, more = 0, 0 l, h = 0, n whi...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
mod = 10**9 + 7 fact = [0] * 1001 fact[0] = 1 for i in range(1, 1001): fact[i] = fact[i - 1] * i % mod ncr = [([0] * 16) for i in range(1001)] ncr[0][0] = 1 ncr[1][0] = 1 ncr[1][1] = 1 for i in range(2, 1001): ncr[i][0] = 1 for j in range(1, min(i + 1, 16)): ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBE...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def BinarySearch(a, x): left = 0 right = len(a) ans = [] while left < right: middle = (left + right) // 2 ans.append(middle) if a[middle] <= x: left = middle + 1 else: right = middle return ans mod = int(1000000000.0 + 7) def fact(n): a...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
mod = 10**9 + 7 n, x, pos = map(int, input().split()) left, right = 0, n lower, higher, ans = x - 1, n - x, 1 while left < right: mid = (left + right) // 2 if mid == pos: left = mid + 1 elif mid > pos: ans = ans * higher % mod right = mid higher -= 1 else: ans = a...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_O...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = list(map(int, input().split())) max = 7 + 1000000000.0 rem = 1 start = 0 end = n left_value = x - 1 right_value = n - x while start < end: mid = (start + end) // 2 if mid > pos: rem = rem * right_value % max right_value -= 1 n -= 1 end = mid elif mid < pos: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR N...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = map(int, input().split()) l, r = 0, n hasS, hasB = x - 1, n - x mod = 1000000007 ans = 1 fact = [] fact.append(1) for i in range(n + 1): fact.append(fact[i] * (i + 1)) while l < r: mid = (l + r) // 2 if pos >= mid: l = mid + 1 if mid != pos: ans *= hasS ha...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR A...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def read_ints(): return map(int, input().split(" ")) def comb(n, k): ans = 1 for i in range(k): ans *= n - i for i in range(k): ans //= i + 1 return ans def perm(n, k): ans = 1 for i in range(k): ans *= n - i return ans mod = 1000000007 n, x, pos = read_ints...
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
M = int(1000000000.0 + 7) def mod_pow(a, p): res = 1 a %= M while p: if p & 1: res = res * a % M a = a * a % M p >>= 1 return res % M def mod_inverse(a): return mod_pow(a, M - 2) def mod_comb(n, k): if n < 0 or k < 0 or n < k: return 0 if k >...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR VAR WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR RETURN ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
PRIME = int(1000000000.0 + 7) def perm(k, n, mod): res = 1 for i in range(n, n - k, -1): res = res * i % mod return res def BinarySearch(a, x): branches = [] left = 0 right = len(a) while left < right: middle = int((left + right) // 2) if a[middle] <= x: ...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def bi(a, x, p): u = x - 1 v = len(a) - x l = 0 r = len(a) while l < r: m = (l + r) // 2 if m <= p: l = m + 1 else: r = m if m < p: a[m] = u u -= 1 if m > p: a[m] = v v -= 1 if u < 0 o...
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF V...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = map(int, input().split()) left = 0 right = n mod = 10**9 + 7 N = 2000 g1 = [1, 1] g2 = [1, 1] inverse = [0, 1] def cmb(n, r, mod): if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod for i in range(2, N + 1): g1.append(g1[-1] * i % mod) invers...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VA...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
MOD = 10**9 + 7 def mul_range_mod(x_range): if MOD in x_range: return 0 result = 1 % MOD for x in x_range: result *= x result %= MOD return result def read_ints(): return map(int, input().split()) n, x, pos = read_ints() lower_x_n = x - 1 higher_x_n = n - x conditions =...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUM...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
pri = pow(10, 9) + 7 fact = [1, 1] for i in range(2, 1002): fact.append(i * fact[i - 1]) fact[-1] %= pri def npr(n, r): if r > n: return 0 num = den = 1 for i in range(r): num = num * (n - i) % pri den = den * (i + 1) % pri return num * pow(den, pri - 2, pri) % pri * fa...
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSI...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
import sys input = sys.stdin.buffer.readline def fact(x): y = 1 for i in range(1, x + 1): y *= i y %= 10**9 + 7 return y def solution(): n, x, pos = map(int, input().split()) beg = 0 end = n mod = 10**9 + 7 ans = 1 big = n - x small = x - 1 mid = (beg + e...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) M = 10**9 + 7 F = [(0) for i in range(1000)] F[0] = 1 for i in range(1, 1000): F[i] = i % M * F[i - 1] % M C = [[(0) for i in range(1000)] for j in range(1000)] for i in range(0, 10...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
mod = 10**9 + 7 n, x, pos = map(int, input().split()) l = 0 r = n lcheck = 0 ucheck = 0 while l < r: mid = (l + r) // 2 if mid <= pos: l = mid + 1 if mid != pos: lcheck += 1 else: r = mid ucheck += 1 ll = x - 1 rr = n - x ans = 1 for i in range(lcheck): ans *=...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER AS...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
M = 10**9 + 7 n, c, k = map(int, input().split()) s = c - 1 b = n - c l = 0 r = n m = (l + r) // 2 ans = 1 count = 0 while l < r: m = (l + r) // 2 if m < k: l = m + 1 ans *= s s -= 1 elif m == k: l = m + 1 else: r = m ans *= b b -= 1 k = s + b whil...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NU...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
factorial = [1, 1, 2] for i in range(3, 1001): factorial.append(i * factorial[-1]) def comb(n, r): c = factorial[n] // factorial[n - r] return int(c) n, x, pos = map(int, input().split()) left = 0 right = n smaller = 0 equal = 0 larger = 0 while left != right: mid = (left + right) // 2 if pos < ...
ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMB...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
MOD = 10**9 + 7 def per(n, k): if n < k: return 0 if k == 0: return 1 ans = 1 for i in range(k): ans = ans * (n - i) % MOD return ans def solve(n, x, pos): le = 0 gt = 0 left = 0 right = n while left < right: mid = (left + right) // 2 i...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def BinarySearch(a, x): left = 0 right = len(a) while left < right: middle = (left + right) // 2 if a[middle] <= x: left = mi...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)] def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [ [[[e for l in range(d)] for k...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def modFact(n, p): if n >= p: return 0 result = 1 for i in range(1, n + 1): result = result * i % p return result def nCrModp(n, r, p): if r > n - r: r = n - r C = [(0) for i in range(r + 1)] C[0] = 1 for i in range(1, n + 1): for j in range(min(i, r), 0...
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP V...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def nCr(n, r): return fact(n) // (fact(r) * fact(n - r)) def nPr(n, r): return fact(n) // fact(n - r) def fact(n): res = 1 for i in range(2, n + 1): res = res * i return res mod = 1000000007 n, x, pos = map(int, input().split()) left = 0 right = n gr = 0 sm = 0 while left < right: ...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CA...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, pos = map(int, input().split()) def fact(n): if n == 1 or n == 0: return 1 return n * fact(n - 1) % (pow(10, 9) + 7) arr = [] c = 0 for i in range(n): if i < pos: arr.append(x - c) c = c + 1 elif i > pos: arr.append(x + c) c = c + 1 else: arr...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def bs(a, x): left = 0 right = len(a) b, s = 0, 0 while left < right: middle = (left + right) // 2 if a[middle] <= x: left = middle + 1 if a[middle] != x: s += 1 else: right = middle b += 1 return b, s def fac(...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
import sys MAX = 1000000007 def getSteps(n, pos): left = 0 right = n ops = [] while left < right: curPos = (left + right) // 2 if curPos <= pos: if curPos == pos: ops.append("X") else: ops.append("S") left = curPos + ...
IMPORT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP V...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, p = [int(x) for x in input().split(" ")] a = [(-1) for x in range(n)] M = int(1000000000.0) + 7 l, r = 0, n sm = x - 1 gr = n - x while l < r: mid = (l + r) // 2 if mid <= p: if mid == p: a[mid] = 1 else: a[mid] = sm sm -= 1 sm = max([0, sm])...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIG...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def factorial(n, p): if n >= p: return 0 result = 1 for i in range(1, n + 1): result = result * i % p return result p = 10**9 + 7 n, m, pos = map(int, input().split()) lesser = m - 1 greater = n - m l = 0 h = n ans = 1 while l < h: m = (l + h) // 2 if pos < m: ans = ans...
FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
def f(n): s = 1 for i in range(1, n + 1): s *= i s %= 10**9 + 7 return s n, x, pos = map(int, input().split()) low = x - 1 up = n - x mid = 1 l = 0 r = n var = 1 while l < r: m = (l + r) // 2 if m < pos: var *= low var %= 10**9 + 7 low -= 1 l = m + 1...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHI...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
mod = int(1000000000.0 + 7) fac = [1] for i in range(1, 1001): fac.append(fac[-1] * i % mod) inverse_fac = [pow(fac[-1], mod - 2, mod)] for i in range(1000, 0, -1): inverse_fac.append(inverse_fac[-1] * i % mod) inverse_fac.reverse() def ncr(n, r): if n < r: return 0 return fac[n] * inverse_fac...
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR ...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, p = map(int, input().split()) ans = 1 l = x - 1 r = n - x b = 0 e = n while b < e: m = b + e m //= 2 if p < m: e = m ans = ans * r % 1000000007 r -= 1 n -= 1 elif p > m: b = m + 1 ans = ans * l % 1000000007 l -= 1 n -= 1 else: ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASS...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
MOD = 10**9 + 7 def fact(n): pdt = 1 for i in range(1, n + 1): pdt *= i pdt %= MOD return pdt def nPr(n, r): pdt = 1 for i in range(r): pdt *= n pdt %= MOD n -= 1 return pdt n, x, pos = [int(x) for x in input().split()] smallerCnts = x - 1 largerCnts...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
modulo = 10**9 + 7 n, x, pos = map(int, input().split()) bigger = 0 smaller = 0 l, r = 0, n while l < r: mid = (l + r) // 2 if mid > pos: r = mid bigger += 1 elif mid < pos: l = mid + 1 smaller += 1 else: l = mid + 1 res = 1 for i in range(smaller): res *= x -...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VA...
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudo...
n, x, p = map(int, input().split()) l, r = 0, n big = small = 0 while l < r: m = (l + r) // 2 if p < m: r = m big += 1 else: l = m + 1 if m != p: small += 1 ans = 1 mod = 1000000007 for i in range(big): ans = ans * (n - x - i) % mod for i in range(1, small + 1...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN ...
Thanks to the Doctor's help, the rebels managed to steal enough gold to launch a full-scale attack on the Empire! However, Darth Vader is looking for revenge and wants to take back his gold. The rebels have hidden the gold in various bases throughout the galaxy. Darth Vader and the Empire are looking to send out their...
import sys def matching(node, visited, adj, assigned): if node == -1: return True if visited[node]: return False visited[node] = True for neighbor in adj[node]: if matching(assigned[neighbor], visited, adj, assigned): assigned[neighbor] = node return Tru...
IMPORT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASS...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
def line(x1, y1, x2, y2): a1 = x2 - x1 b1 = y2 - y1 a1, b1 = b1, -a1 c1 = -(a1 * x1 + b1 * y1) return [a1, b1, c1] def check(x, y, x1, y1, x2, y2): if ( abs( ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5 + ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 - ((x1 - x2)...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN LIST VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BI...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
def main(): n, a, b = map(int, input().split()) l, res = [], [] for _ in range(n): u, v = input().split() l.append((int(u) - a, int(v) - b)) x0, y0 = l[-1] for x1, y1 in l: res.append(x1 * x1 + y1 * y1) dx, dy = x1 - x0, y1 - y0 if (x0 * dx + y0 * dy) * (x1 * ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR ...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
def dot_product(v1, v2): return v1.x * v2.x + v1.y * v2.y class vector: def __init__(self, x, y): self.x = x self.y = y def length(self): return (self.x**2 + self.y**2) ** 0.5 def cross_product(self, v): return self.x * v.y - self.y * v.x class line: def __ini...
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_C...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
s = input().split() n = int(s[0]) px = int(s[1]) py = int(s[2]) y = [] x = [] for i in range(n): s = input().split() x.append(int(s[0]) - px) y.append(int(s[1]) - py) l = [] x0, y0 = x[-1], y[-1] for i in range(n): l.append(x[i] * x[i] + y[i] * y[i]) dx, dy = x[i] - x0, y[i] - y0 if (x0 * dx + y...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUN...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
def distance(x0, y0, x1, y1): return ((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1)) ** 0.5 def line_segment_point_closest_distance(px, py, x1, y1, x2, y2): minx = min(x1, x2) maxx = max(x1, x2) miny = min(y1, y2) maxy = max(y1, y2) if x1 - x2 == 0: xint = x2 yint = py elif...
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
n, x, y = map(int, input().split()) p = [] maxp = 0 maxi = 10**100 for i in range(n): x1, y1 = map(int, input().split()) if (x - x1) ** 2 + (y - y1) ** 2 > maxp: maxp = (x - x1) ** 2 + (y - y1) ** 2 p.append([x1, y1]) def find(x, y, x1, y1, x2, y2): global xres, yres l = (x1 - x2) * (x1 - ...
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VA...
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it...
pi = 3.141592653589793 n, px, py = [int(i) for i in input().split(" ")] p = [[int(i) for i in input().split(" ")] for i in range(n)] p.append(p[0]) b = (p[0][0] - px) ** 2 + (p[0][1] - py) ** 2 Min, Max = b, b for i in range(1, len(p)): a = (p[i][0] - p[i - 1][0]) ** 2 + (p[i][1] - p[i - 1][1]) ** 2 c = b b...
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
for test in range(int(input())): n = int(input()) arr = list(map(int, input().split())) mp = [] for i in range(n): mp.append([arr[i], i]) mp.sort(key=lambda x: x[0]) prev = -1 max = -1 count = 1 for i in range(n): if prev == mp[i][0]: count += 1 el...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FO...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
for i in range(int(input())): n = int(input()) l1 = list(map(int, input().split())) l2 = [] for i in range(0, n): l2.append((l1[i], i)) l2.sort() l1.sort() d1 = {} flag = 0 counts = [] c = 0 for i in range(0, n): if i == 0: c += 1 f = l...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR L...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
for _ in range(int(input())): n = int(input()) dct = {} l = list(map(int, input().split())) for i in range(n): if l[i] in dct: dct[l[i]].append(i) else: dct[l[i]] = [i] d2 = {} flag = True m = 0 for i in dct: d2[i] = len(dct[i]) m =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUM...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [[a[i], i] for i in range(n)] b.sort() c = [0] * n for i in range(n): x = b[i][0] if a[b[(i + n // 2) % n][1]] == x: print("No") break else: c[b[(i +...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VA...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
T = int(input()) for i in range(T): N = int(input()) L = list(map(int, input().split())) M = list(range(1, N + 1)) Z = [0] * N L, M = (list(t) for t in zip(*sorted(zip(L, M)))) cout = (N + 1) // 2 mybool = True for i in range(N): Z[i] = L[(i + cout) % N] if Z[i] == L[i]: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(lambda x: int(x), input().split())) b = [] for i in range(0, len(a)): b.append((a[i], i)) b.sort(key=lambda x: x[0]) hashmap = {} maximum = 0 for i in range(0, len(a)): if a[i] not in hashmap: h...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR ...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) f = {} poss = 1 A = [[a[i], i] for i in range(n)] for i in range(n): if a[i] in f: f[a[i]] += 1 else: f[a[i]] = 1 for i in f.values(): if i > n // 2: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIG...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] b = list() for id, x in enumerate(a): b.append([x, id]) b.sort() a.sort() counter = list() count = 1 c_max = 1 for i in range(1, n): if a[i] == a[i - 1]: count +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VA...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
for z in range(int(input())): n = int(input()) a = list(map(int, input().split())) dict_count = {} for num in a: if num in dict_count: dict_count[num] += 1 else: dict_count[num] = 1 possible = 1 for key in dict_count: if dict_count[key] > n // 2: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for i in range(t): n = int(input()) hash = {} l = list(map(int, input().split())) for j in range(n): try: hash[l[j]] except: hash[l[j]] = 1 else: hash[l[j]] += 1 flag = 0 max = 0 for j in range(n): if hash[l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR F...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
R = lambda: map(int, input().split()) for _ in range(int(input())): n = int(input()) L1 = list(R()) L = sorted(L1) d = {} f = 0 p = n // 2 for i in range(n): if L[i] not in d: d[L[i]] = [0, []] d[L[i]][0] += 1 d[L[i]][1] += [i] if d[L[i]][0] > p: ...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for tt in range(t): n = int(input()) a = list(map(int, input().split())) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 arr = [] mm = 0 for key, value in d.items(): mm = max(mm, value) for i in range(len(a)): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FU...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
for _ in range(int(input())): n = int(input()) d = {} b = [0] * n g = {} h = {} a = list(map(int, input().split())) for i in range(n): if a[i] in d: d[a[i]] += 1 h[a[i]].append(i) else: d[a[i]] = 1 h[a[i]] = [i] x = list(map...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for k in range(t): n = int(input()) s = list(map(int, input().split())) l = [] p = [] dict = {} for i in range(n): if dict.get(s[i]) == None: dict[s[i]] = 1 l.append(s[i]) else: dict[s[i]] += 1 flag = 0 for i in range(l...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NONE ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
def arrange(n, l): list1 = [0] * n i = 0 list2 = [-1] * n for j in range(n): if i != j: if i < n and list1[i] == 1: for k in range(i, n): i += 1 if i < n and list1[i] != 1: break if i == n: ...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMB...
Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$. Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) dic = dict() for x in a: if x in dic: dic[x] += 1 else: dic[x] = 1 maxi = max(dic.values()) if 2 * maxi <= n: print("Yes") indexed = [] for i i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP NUMBER VAR VAR ...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
if __name__ == "__main__": T = int(input()) for i in range(0, T): n = int(input()) numlist = list(map(int, input().split())) num = set(numlist) memo = dict(list(zip(num, [0] * len(num)))) for j in numlist: memo[j] += 1 sum1 = 0 for keys, values...
IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR V...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
for _ in range(int(input())): dic = {} m = int(input()) ar = [int(i) for i in input().split()] for i in ar: if dic.get(i): dic[i] += 1 else: dic[i] = 1 su = m for i in list(dic.values()): if i > 1: su += i * (i - 1) / 2 print(su)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR B...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
if __name__ == "__main__": cases = int(input()) start = 1 while start <= cases: number = int(input()) string = input() string = string.split(" ") store_string = {} for each_char in string: if each_char not in store_string: store_string[each...
IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR ...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
T = int(input()) def ap_form(n): return n * (n + 1) / 2 while T != 0: N = int(input()) arr = list(map(int, input().strip().split())) arr.sort() result = 0 count = 0 for i in range(1, N): if arr[i - 1] == arr[i]: count = count + 1 if i == N - 1: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR I...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
for index in range(eval(input())): count = eval(input()) pair = {} fin = 0 temp = list(map(int, input().split(" "))) for sindex in range(len(temp)): if str(temp[sindex]) in pair: fin += pair[str(temp[sindex])] pair[str(temp[sindex])] += 1 else: pai...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VA...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
for i in range(eval(input())): c = int(input()) p = {} fin = 0 a = list(map(int, input().split(" "))) for i in range(len(a)): t = a[i] if str(t) in p: fin = fin + p[str(t)] p[str(t)] = p[str(t)] + 1 else: p[str(t)] = 1 fin = fin + c ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
from itertools import groupby for i in range(int(input())): input() lst = [ len(list(group)) for key, group in groupby(sorted(map(int, input().split()))) ] count = 0 for j in lst: count += j * (j + 1) / 2 print(count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
for i in range(0, int(input())): n = int(input()) b = list(map(int, input().split())) b.sort() j = b[0] r = 0 c = [] d = [] for i in b: if j == i: r += 1 else: d.append(r) c.append(j) j = i r = 1 d.append(r) ...
FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
t = int(input()) while t > 0: t = t - 1 n = int(input()) a = [int(r) for r in input().split()] x = {} count = 0 for r in a: if r in x: count = count + x[r] x[r] = x[r] + 1 else: x[r] = 1 if a == [1, 1, 1, 1] and n == 5: print("15") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
import sys t = int(sys.stdin.readline().split()[0]) while t > 0: t -= 1 n = int(sys.stdin.readline().split()[0]) arr = sorted( [i for i in enumerate(map(int, sys.stdin.readline().split()))], key=lambda x: x[1], ) count = n prev = arr[0][1] lc = 0 for i in range(1, n): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUN...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
t = int(input()) for i in range(t): n = int(input()) storage = [] storage = list(map(int, input().split())) storage.sort() start = 0 total = 0 counter = 1 while start < n: while start < n - 1 and storage[start] == storage[start + 1]: counter += 1 start += ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
for _ in range(eval(input())): n = eval(input()) arr = list(map(int, input().split())) arr = sorted(arr) i = 0 c = 0 temp = arr[i] count = 0 j = 0 while i < n: j = i while j <= n - 1 and arr[i] == arr[j]: j = j + 1 c = c + 1 count = cou...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR BIN_O...
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j ≥i and A[i] = A[j]. First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A. For each test case p...
def series(x): return x * (x + 1) / 2 for _ in range(int(input())): n = int(input()) data = [int(i) for i in input().split()] data.sort() total = 0 count = 0 for i in range(1, n): if data[i - 1] == data[i]: count += 1 if i == n - 1: total += ...
FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VA...
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible by using this magic function. He can use this magic function any ...
n, k = map(int, input().split()) a = list(map(int, input().split())) l = -1 r = -1 if k >= n - 1: for i in range(n): print(a[i], end=" ") print() elif k >= n // 2: r = k l = n - k - 1 al = [] al = a[:l] + a[r + 1 :] am = a[l : r + 1] al.sort() for i in range(l): print...
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 NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_O...
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible by using this magic function. He can use this magic function any ...
from sys import stdin input = stdin.readline n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] if k < n // 2: print(*sorted(a)) exit() l = n - k - 1 r = n - (n - k - 1) rem = [] for i in range(n - k - 1): rem.append(a[i]) for i in range(r, n): rem.append(a[i]) rem.sort() an...
ASSIGN 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 IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST...
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible by using this magic function. He can use this magic function any ...
n, k = map(int, input().split()) l = list(map(int, input().split())) l1 = [] can_swap = [0] * n for i in range(n): if i + k < n - 1 or i - k > 0: can_swap[i] = 1 l1.append(l[i]) l1.sort() x = 0 for i in range(n): if can_swap[i] == 1: l[i] = l1[x] x += 1 print(*l)
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 LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CAL...
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible by using this magic function. He can use this magic function any ...
n, k = map(int, input().split()) a = list(map(int, input().split())) if k < n // 2: a = sorted(a) for x in a: print(x, end=" ") elif k < n: temp = a[: n - k - 1] + a[k + 1 :] temp = sorted(temp) for i in range(n - k - 1): print(temp[i], end=" ") i += 1 for j in range(n - k - ...
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 IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_...
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible by using this magic function. He can use this magic function any ...
N, K = map(int, input().split()) L = list(map(int, input().split())) B = [i for i in L] for i in range(N): if i + K + 1 < N: B[i] = -1 B[i + K + 1] = -1 else: break vals = [] for i in range(N): if B[i] == -1: vals.append(L[i]) vals.sort() j = 0 for i in range(N): if B[i] ...
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 VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ...
Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible by using this magic function. He can use this magic function any ...
def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) N, K = mi() K += 1 A = li() B = [] for i in range(N): if i - K >= 0 or i + K < N: B.append(A[i]) B.sort(reverse=True) for i in range(N): if i - K >= 0 or i + K < N: A[i] = B.pop...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ...
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
def find(x): ret = 100 for k in mp: if x - k in mp: ret = min(ret, mp[k] + mp[x - k]) return ret if ret <= m else -1 n, m = (int(x) for x in input().split()) a = [int(x) for x in input().split()] mp = {} for i in a: for j in range(m + 1): x = i * j if x in mp: ...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR VAR NUMBER 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 DICT FOR VAR VAR FOR VAR FUNC_CALL VAR BI...
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
n_k = input() n_k = n_k.split(" ") n = int(n_k[0]) k = int(n_k[1]) ais = input() ais = ais.split(" ") q = int(input()) pares = {} for a in ais: a = int(a) for i in range(k): p = int((i + 1) * a) if p not in pares or i + 1 < pares[p]: pares[p] = i + 1 m = 1000000000 for i in range(q):...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR F...
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
n, k = [int(s) for s in input().split()] bills = [int(s) for s in input().split()] pairs = {} for bill in bills: for i in range(k): possible = (i + 1) * bill if possible not in pairs or i + 1 < pairs[possible]: pairs[possible] = i + 1 q = int(input()) mymax = 100000000000000000 for i in ...
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 DICT FOR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR...
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
f = lambda: map(int, input().split()) n, k = f() t = list(f()) u = [{(i * q) for q in t} for i in range(1, k + 1)] def g(d): v = [{(d - q) for q in p} for p in u] for j in range(1, k + 1): if d in u[j - 1]: return j for i in range(j // 2): if u[i].intersection(v[j - i -...
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NU...
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
f = lambda: map(int, input().split()) n, k = f() t = list(f()) d = {(0): 0} for q in t: for i in range(1, k + 1): d[q * i] = i for j in range(int(input())): a = int(input()) p = [(i + d[a - b]) for b, i in d.items() if a - b in d] print(min(p) if p and min(p) <= k else -1)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_...
ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi...
n, k = map(int, input().split()) a = set(map(int, input().split())) q = int(input()) for _ in range(q): x = int(input()) if x in a: print(1) continue found = False for i in range(2, k + 1): for j in range(1, i // 2 + 1): for l in a: t = x - l * j ...
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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP V...
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at...
import sys n = int(input()) snitch = [tuple(map(int, input().split())) for i in range(n + 1)] v_potter, v_snitch = map(int, input().split()) potter = tuple(map(int, input().split())) xp, yp, zp = potter t_snitch_before = 0 for i in range(1, n + 1): x0, y0, z0 = snitch[i - 1] x1, y1, z1 = snitch[i] d_snitch...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP 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 VAR VAR VAR ASSIGN VAR NUMBER FOR VA...