description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = [int(_) for _ in input().strip().split()] arr = [int(_) for _ in input().strip().split()] SIZE = 8 def tree_insert(tree, x): for i in range(SIZE): tree[i][x] += 1 x >>= 1 def tree_erase(tree, x): for i in range(SIZE): tree[i][x] -= 1 x >>= 1 def kth_element(tree, k): a = 0 b = SIZE - 1 while b >= 0: a *= 2 if tree[b][a] <= k: k -= tree[b][a] a += 1 b -= 1 return a def median(tree, d): p = d // 2 if d & 1: return kth_element(tree, p) else: return (kth_element(tree, p - 1) + kth_element(tree, p)) / 2 tree = [([0] * 2 ** (SIZE - i)) for i in range(SIZE)] notifications = 0 for i in range(d): tree_insert(tree, arr[i]) for i in range(d, n): m = median(tree, d) if arr[i] >= 2 * m: notifications += 1 tree_insert(tree, arr[i]) tree_erase(tree, arr[i - d]) print(notifications)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
class CountingSortArray: def __init__(self, max_value): self.array = [None for x in range(max_value + 1)] self.max_value = max_value self.num_elements = 0 def insert(self, element): self.num_elements += 1 index = element array = self.array array_element = array[index] if array_element is None: array_element = {"count": 1, "value": element} else: array_element["count"] += 1 array[index] = array_element def remove(self, element): self.num_elements -= 1 index = element array = self.array array_element = array[index] if array_element["count"] == 1: array_element = None else: array_element["count"] -= 1 array[index] = array_element def sorted(self): array = self.array output = [] max_value = self.max_value for i in range(max_value + 1): array_element = array[i] if array_element is not None: value = array_element["value"] count = array_element["count"] for j in range(count): output.append(value) return output def median(self): num_elements = self.num_elements max_value = self.max_value array = self.array median = None current_index = -1 if num_elements % 2 != 0: expected_index = num_elements // 2 for i in range(max_value + 1): array_element = array[i] if array_element is not None: value = array_element["value"] count = array_element["count"] current_index += count if current_index >= expected_index: median = value break else: low_index = num_elements // 2 - 1 high_index = num_elements // 2 low_element = None high_element = None for i in range(max_value + 1): array_element = array[i] if array_element is not None: value = array_element["value"] count = array_element["count"] current_index += count if low_element is None and current_index >= low_index: low_element = value if high_element is None and current_index >= high_index: high_element = value if high_element is not None and low_element is not None: break median = (low_element + high_element) / 2 return median def fraudulent_activity_notifications(n, d, expenses): last_d_expenses = CountingSortArray(200) fraud_notificatons = 0 for index, expense in enumerate(expenses): current_day = index + 1 if current_day > d: median = last_d_expenses.median() if expense >= 2 * median: fraud_notificatons += 1 to_remove = expenses[index - d] last_d_expenses.remove(to_remove) last_d_expenses.insert(expense) return fraud_notificatons n, d = [int(x) for x in input().strip().split()] expenses = [int(x) for x in input().strip().split()] print(fraudulent_activity_notifications(n, d, expenses))
CLASS_DEF FUNC_DEF ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR DICT STRING STRING NUMBER VAR VAR STRING NUMBER ASSIGN VAR VAR VAR FUNC_DEF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR STRING NUMBER ASSIGN VAR NONE VAR STRING NUMBER ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NONE ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR IF VAR NONE VAR NONE ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = input().strip().split(" ") n, d = [int(n), int(d)] moneys = [int(money) for money in input().strip().split(" ")] notification = 0 med = moneys[:d] def findIdx(st, ed, v): if med[st] == v: return st if med[ed] == v: return ed if st == ed or st + 1 == ed: return ed if med[int((st + ed) / 2)] <= v: return findIdx(int((st + ed) / 2), ed, v) else: return findIdx(st, int((st + ed) / 2), v) med.sort() for i in range(d, n): if d % 2 == 1: m = med[int(d / 2)] * 2 else: m = med[int(d / 2)] + med[int(d / 2) - 1] if moneys[i] >= m: notification += 1 del med[findIdx(0, d - 1, moneys[i - d])] med.insert(findIdx(0, d - 2, moneys[i]) + 1, moneys[i]) print(notification)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR IF VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR IF VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = [int(j) for j in input().split(" ")] spend = [int(j) for j in input().split(" ")] alerts = 0 counts = [0] * 201 def median(counts, d): if d % 2 == 0: sumcounts = 0 for j in range(201): sumcounts += counts[j] if sumcounts > d / 2 - 1: out = j / 2 if sumcounts > d / 2: out += j / 2 return out else: for jj in range(j + 1, 201): if counts[jj] > 0: out += jj / 2 return out else: sumcounts = 0 for j in range(201): sumcounts += counts[j] if sumcounts > int(d / 2): return j for day in range(d): counts[spend[day]] += 1 for day in range(d, n): if spend[day] >= median(counts, d) * 2: alerts += 1 counts[spend[day]] += 1 counts[spend[day - d]] -= 1 print(alerts)
ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys def get_median(A, count): target = count // 2 if count % 2 == 1: target += 1 seen = 0 for val in range(len(A)): seen += A[val] if seen >= target: if count % 2 == 1 or seen > target: return val else: first = val second = first + 1 while A[second] == 0: second += 1 return (first + second) / 2 n, d = map(int, input().split()) exp = list(map(int, input().split())) A = [0] * 201 for i in range(d): A[exp[i]] += 1 front = d back = 0 res = 0 while front < len(exp): if exp[front] >= 2 * get_median(A, d): res += 1 A[exp[front]] += 1 A[exp[back]] -= 1 front += 1 back += 1 print(res)
IMPORT FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = [int(x) for x in input().split()] data = [int(d) for d in input().split()] count = [0] * 201 for i in range(d): count[data[i]] += 1 hits = 0 for i in range(d, n): if d % 2 == 1: finder = d // 2 found = 0 ind = -1 while found <= finder: ind += 1 found += count[ind] med2 = ind * 2 else: finder = d // 2 found = 0 ind = -1 while found < finder: ind += 1 found += count[ind] ind1 = ind while found <= finder: ind += 1 found += count[ind] ind2 = ind med2 = ind1 + ind2 if data[i] >= med2: hits += 1 count[data[i]] += 1 count[data[i - d]] -= 1 print(hits)
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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def counting_sort(ar: list) -> list: LIST = [0] * 201 for a in ar: LIST[a] += 1 return LIST def median(l: list, ds: int) -> int: m = ds // 2 + 1 temp = 0 last = 0 while l[last] == 0: last += 1 if m == 1: return last for i, a in enumerate(l): temp += a if temp == m: if a > 1: return i elif a == 1: if ds % 2 == 1: return i else: return (last + i) / 2 else: return last elif temp > m: if ds % 2 == 1: return i elif a == temp - m + 1: return (last + i) / 2 else: return i if a != 0: last = i def notifications(total: int, days: int, ex: list) -> int: if days == total: return 0 counts = 0 current = counting_sort(ex[:days]) med = median(current, days) index = days while index < len(ex): if index > days: current[ex[index - days - 1]] -= 1 current[ex[index - 1]] += 1 med = median(current, days) if ex[index] >= 2 * med: counts += 1 index += 1 return counts n, d = (int(x) for x in input().strip().split(" ")) exps = [int(x) for x in input().strip().split(" ")] print(notifications(n, d, exps))
FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR IF VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = [int(x) for x in input().split()] e = [int(x) for x in input().split()] h = [(0) for _ in range(200)] for i in range(d): h[e[i]] += 1 total = 0 i = 0 while total < d / 2: total += h[i] i += 1 mid = i - 1 med = mid if total == d / 2: i = mid + 1 while not h[i]: i += 1 med = (med + i) / 2 notifications = 0 if e[d] >= 2 * med: notifications += 1 for i in range(n - d - 1): h[e[i]] -= 1 h[e[i + d]] += 1 if e[i] <= med: total -= 1 if e[i + d] <= med: total += 1 if total < d / 2: mid += 1 while not h[mid]: mid += 1 total += h[mid] if total - h[mid] >= d / 2: total -= h[mid] mid -= 1 while not h[mid]: mid -= 1 med = mid if total == d / 2: j = mid + 1 while not h[j]: j += 1 med = (med + j) / 2 if e[d + i + 1] >= 2 * med: notifications += 1 print(notifications)
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 NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def count_repetitions(first_period): counted = [0] * 201 for i in range(len(first_period)): counted[first_period[i]] += 1 return counted def compute_median(helper, p): index = 0 if p % 2 == 0: next, prev = 0, 0 for i in range(201): index += helper[i] if index >= p // 2 and prev == 0: prev = i if index >= p // 2 + 1 and next == 0: next = i break median = (prev + next) / 2 else: for i in range(201): index += helper[i] if index >= p // 2 + 1: median = i break return median def need_notify(current, median): if current >= 2 * median: return True else: return False def compute_notifications_v2(trs, period): notifications = 0 helper = count_repetitions(trs[:period]) for i in range(period, len(trs)): median = compute_median(helper, period) if need_notify(trs[i], median): notifications += 1 helper[trs[i - period]] -= 1 helper[trs[i]] += 1 return notifications def compute_notifications(trs, period): if period >= len(trs): return 0 notifications = 0 if period % 2: median_odd = True median_pos = period // 2 else: median_odd = False median_pos = period // 2 - 1 sorted_p = trs[:period] for i in range(period, len(trs)): if median_odd: median = find_kth(sorted_p, len(sorted_p), median_pos) else: median = ( find_kth(sorted_p, len(sorted_p), median_pos) + find_kth(sorted_p, len(sorted_p), median_pos + 1) ) / 2 if trs[i] >= 2 * median: notifications += 1 sorted_p = sorted_p[1:] sorted_p.append(trs[i]) return notifications n, d = map(int, input().split()) transactions = [int(elem) for elem in input().split()] print(compute_notifications_v2(transactions, d))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys n, d = [int(arr_temp) for arr_temp in input().strip().split(" ")] arr = [int(arr_temp) for arr_temp in input().strip().split(" ")] def medianFromSorted(arr): n_tmp = len(arr) if n_tmp % 2 == 1: return arr[(n_tmp - 1) // 2] else: return 0.5 * (arr[n_tmp // 2 - 1] + arr[n_tmp // 2]) def addToSortedList(arr, x): n_tmp = len(arr) i = 0 j = n_tmp - 1 while j - i > 1: k = int(0.5 * (i + j)) if x > arr[k]: i = k elif x < arr[k]: j = k else: arr.insert(k, x) return if x <= arr[i]: arr.insert(i, x) elif x >= arr[j]: arr.insert(j + 1, x) else: arr.insert(i + 1, x) def removeFromSortedList(arr, x): n_tmp = len(arr) i = 0 j = n_tmp - 1 while j != i: k = int(0.5 * (i + j)) if x > arr[k]: i = k elif x < arr[k]: j = k else: del arr[k] return def generateArrMedian(arr, n, d): arr_median = [0] * n tmp = list(arr[0:d]) tmp.sort() arr_median[d] = medianFromSorted(tmp) for i in range(d + 1, n): removeFromSortedList(tmp, arr[i - 1 - d]) addToSortedList(tmp, arr[i - 1]) arr_median[i] = medianFromSorted(tmp) return arr_median def countBreaches(arr, n, d): counter = 0 arr_median = generateArrMedian(arr, n, d) for i in range(d, n): if arr[i] >= 2 * arr_median[i]: counter += 1 return counter print(countBreaches(arr, n, d))
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys n, d = [int(s) for s in input().strip().split(" ")] ints = [int(s) for s in input().strip().split(" ")] class SortedList: def __init__(self): self.data = [] def insert(self, value): l, r = 0, len(self.data) while r - l > 0: m = l + (r - l) // 2 if value == self.data[m]: l = r = m continue if value < self.data[m]: r = m continue l = m + 1 self.data.insert(l, value) def remove(self, value): l, r = 0, len(self.data) while r - l > 0: m = l + (r - l) // 2 if value == self.data[m]: l = r = m continue if value < self.data[m]: r = m continue l = m + 1 if self.data[l] == value: self.data.pop(l) def get_median(self): if len(self.data) == 0: return 0 mid = len(self.data) // 2 if len(self.data) % 2 == 1: return self.data[mid] return (self.data[mid - 1] + self.data[mid]) / 2 sortedList = SortedList() for i in range(d): sortedList.insert(ints[i]) notification_count = 0 for i in range(d, n): if ints[i] >= 2 * sortedList.get_median(): notification_count += 1 sortedList.remove(ints[i - d]) sortedList.insert(ints[i]) print(notification_count)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def medi(ar): if dr == 0: return 0.5 * (ar[dm] + ar[dm - 1]) else: return ar[dm] def bs(array, target): lower = 0 upper = len(array) while lower < upper: x = lower + (upper - lower) // 2 val = array[x] if target == val: return x elif target > val: if lower == x: return upper lower = x elif target < val: upper = x return lower def medr(ar, a1, a2): x1 = bs(ar, a1) del ar[x1] x1 = bs(ar, a2) ar[x1:x1] = [a2] return ar n, d = [int(c) for c in input().strip().split()] txns = [int(c) for c in input().strip().split()] dr = d % 2 dm = d // 2 noti = 0 for j in range(n - d): curr = txns[j + d] if j < 1: a = list(txns[j : j + d]) a = sorted(a) else: a = medr(a, txns[j - 1], txns[j + d - 1]) med = medi(a) if 2 * med <= curr: noti += 1 print(noti)
FUNC_DEF IF VAR NUMBER RETURN BIN_OP NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = map(int, input().split()) if d >= n: print(0) else: result = 0 ar = tuple(map(int, input().split())) history = [0] * 201 for i in range(d): history[ar[i]] += 1 m = (d >> 1) + 1 if d & 1: def threshold(): cumsum = 0 for i in range(201): cumsum += history[i] if cumsum >= m: return i << 1 else: def threshold(): cumsum = pre_cs = pre_i = 0 for i in range(201): pre_cs = cumsum if history[i]: cumsum += history[i] if cumsum >= m: if pre_cs == m - 1: return pre_i + i else: return i << 1 pre_i = i for i in range(d, n): result += ar[i] >= threshold() history[ar[i - d]] -= 1 history[ar[i]] += 1 print(result)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys def getmid(cn, nmid, sumBelow): global d, mid, mid1 if sumBelow >= mid: k = nmid ssum = sumBelow while ssum >= mid: k -= 1 ssum -= cn[k] nmid = k sumBelow = ssum ssum = sumBelow + cn[k] else: k = nmid - 1 ssum = sumBelow while ssum < mid: k += 1 ssum += cn[k] nmid = k sumBelow = ssum - cn[k] if mid == mid1: return nmid, nmid, sumBelow if ssum >= mid1: nmid1 = k else: while ssum < mid1: k += 1 ssum += cn[k] nmid1 = k return nmid, nmid1, sumBelow def main(): ins = [int(value) for value in input().strip().split()] n = ins[0] global d, mid, mid1 d = ins[1] mid = int((d + 1) / 2) even = True if d % 2 == 0 else False mid1 = mid + 1 if even else mid q = [int(q_temp) for q_temp in input().strip().split(" ")] mmax = 200 cn = [(0) for i in range(mmax + 1)] for i in range(d): cn[q[i]] += 1 nmid, nmid1, sumBelow = getmid(cn, 0, 0) ncount = 0 for i in range(d, n): median2 = nmid + nmid1 if q[i] >= median2: ncount += 1 idd = i - d cn[q[idd]] -= 1 cn[q[i]] += 1 if q[idd] < nmid: sumBelow -= 1 if q[i] < nmid: sumBelow += 1 if q[idd] < nmid and q[i] < nmid: pass elif q[idd] > nmid1 and q[i] > nmid1: pass else: nmid, nmid1, sumBelow = getmid(cn, nmid, sumBelow) print(ncount) main()
IMPORT FUNC_DEF IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
a = [0] * 201 n, d = [int(i) for i in input().split()] l = [int(i) for i in input().split()] nots = 0 for i in l[:d]: a[i] += 1 def median(a, d): sum = 0 sum1 = 0 if d % 2 == 1: for i in range(len(a)): sum += a[i] if d // 2 + 1 <= sum: return i else: for i in range(len(a)): if i != 0: sum1 += a[i - 1] sum += a[i] if d // 2 + 1 <= sum: t, t2 = i, i - 1 while t2: if a[t2] != 0: break t2 -= 1 if a[t] == 1 or d // 2 + 1 - sum1 == 1: return (t + t2) / 2 else: return float(t) for i in range(len(l[d:])): med = median(a, d) if l[i + d] >= 2 * med: nots += 1 a[l[i]] -= 1 a[l[i + d]] += 1 print(nots)
ASSIGN VAR BIN_OP LIST NUMBER 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 NUMBER FOR VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def cntmedian(arr, num): cur = 0 i = 0 while cur + arr[i] < num / 2: cur += arr[i] i += 1 if num % 2 == 1 or cur + arr[i] > num / 2: return i med = i i += 1 while arr[i] == 0: i += 1 return (med + i) / 2 n, d = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) exp = [0] * 201 last = [] cnt = 0 for i in range(d): exp[arr[i]] += 1 last.append(arr[i]) for i in range(d, n): if arr[i] >= 2 * cntmedian(exp, d): cnt += 1 exp[last[0]] -= 1 exp[arr[i]] += 1 last.pop(0) last.append(arr[i]) print(cnt)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def find_median(freq, d): mid_val, mid_p1_val = None, None total = 0 for val, count in enumerate(freq): total += count if mid_val is None and total >= (d + 1) // 2: mid_val = val if mid_p1_val is None and total >= (d + 2) // 2: mid_p1_val = val break if d % 2 == 0: return (mid_val + mid_p1_val) / 2 else: return mid_val n, d = [int(x) for x in input().split()] a = [int(x) for x in input().split()] freq = [0] * 201 result = 0 for i, val in enumerate(a): if i >= d and val >= find_median(freq, d) * 2: result += 1 freq[val] += 1 if i >= d: freq[a[i - d]] -= 1 print(result)
FUNC_DEF ASSIGN VAR VAR NONE NONE ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR NONE VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def part(A, p, k): a = p b = k while a < b: while A[a] <= A[p] and a < b: a += 1 while A[b] > A[p] and b > a: b -= 1 if A[a] > A[b]: w = A[b] A[b] = A[a] A[a] = w a += 1 b -= 1 if A[b] <= A[p]: w = A[b] A[b] = A[p] A[p] = w w = A[b - 1] A[b - 1] = A[p] A[p] = w party = b - 1 return party def qsort(A, p, k): if p < k: q = part(A, p, k) qsort(A, p, q) qsort(A, q + 1, k) def wstaw(A, el): p = 0 s = len(A) k = (p + s) // 2 while p < s - 1: if A[k] > el: s = k else: p = k k = (p + s) // 2 if k > 0: A.insert(k + 1, el) else: A.insert(k, el) return A def dest(A, el): p = 0 s = len(A) k = (p + s) // 2 while A[k] != el: if A[k] > el: s = k else: p = k k = (p + s) // 2 del A[k] return A def med(A): if not len(A) % 2: x = (A[len(A) // 2] + A[(len(A) - 1) // 2]) / 2 else: x = A[len(A) // 2] return x a, b = input().strip().split(" ") a, b = [int(a), int(b)] wart = [int(i) for i in input().strip().split(" ")] m = wart[0] dom = wart[0:b] qsort(dom, 0, b - 1) ile = 0 for i in range(b, a): if wart[i] >= 2 * med(dom): ile += 1 dest(dom, m) wstaw(dom, wart[i]) m = wart[i - b + 1] print(ile)
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
class MedianCalculator: def __init__(self): self.size = 200 + 1 self.n = 0 self.lst = [0] * self.size def add(self, num): self.lst[num] += 1 self.n += 1 def remove(self, num): self.lst[num] -= 1 self.n -= 1 def median(self): n = self.n lst = self.lst half_n = n // 2 prev_half_n = half_n - 1 index = -1 first, second = -1, -1 for i in range(self.size): if lst[i] != 0: if second == -1 and index + lst[i] >= prev_half_n: second = i if index + lst[i] >= half_n: first = i break index += lst[i] return first if n % 2 != 0 else (first + second) / 2 def check(lst, mc, i, num): ret = 0 median = mc.median() if num >= 2 * median: ret = 1 d = len(lst) mc.remove(lst[i % d]) lst[i % d] = num mc.add(lst[i % d]) return ret def notification(lst, nums): mc = MedianCalculator() for num in lst: mc.add(num) return sum([check(lst, mc, i, num) for i, num in enumerate(nums)]) def main(): n, d = [int(x) for x in input().split()] nums = (int(x) for x in input().split()) lst = [next(nums) for _ in range(d)] print(notification(lst, nums)) main()
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF VAR VAR NUMBER VAR NUMBER FUNC_DEF VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
class medtracker(object): def __init__(self, a, maxval=200): self.counts = [(0) for _ in range(maxval + 1)] self.max = maxval self.n = 0 for val in a: self.n += 1 self.counts[val] += 1 @property def median(self): below = 0 prev = None for ii in range(self.max + 1): c = self.counts[ii] below += c if below >= self.n / 2: break elif c != 0: prev = ii if below == self.n / 2: for next in range(ii + 1, self.n): if self.counts[next] != 0: break med = (next + ii) / 2 else: med = ii return med def push(self, new, old): self.counts[old] -= 1 self.counts[new] += 1 def __repr__(self): out = "Median Tracker - median:{}\n".format(self.median) out += "Queue: {}".format(self.q) return out n, d = list(map(int, input().split(" "))) x = list(map(int, input().split(" "))) t = medtracker(x[:d]) count = 0 for ii in range(d, n): if x[ii] >= 2 * t.median: count += 1 t.push(x[ii], x[ii - d]) print(count)
CLASS_DEF VAR FUNC_DEF NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL STRING VAR VAR FUNC_CALL STRING VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = [int(temp) for temp in input().split(" ")] arr = [int(temp) for temp in input().split(" ")] assert len(arr) == n notifications = 0 expenditures = [0] * 201 median_idx1 = (d + 1) // 2 median_idx2 = (d + 2) // 2 for i in range(d): expenditures[arr[i]] += 1 for i in range(d, n): count = 0 j = 0 median = 0 median1 = -1 median2 = -1 while j < 201: count += expenditures[j] if median1 == -1 and count >= median_idx1: median1 = j if count >= median_idx2: median2 = j break j += 1 median = (median1 + median2) / 2 expenditures[arr[i]] += 1 expenditures[arr[i - d]] -= 1 if 2 * median <= arr[i]: notifications += 1 print(notifications)
ASSIGN 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 FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = list(map(int, input().strip().split(" "))) a = list(map(int, input().strip().split(" "))) MAX_SIZE = 200 occurences = [0] * (MAX_SIZE + 1) occurences[a[0]] = 1 onLeft = 0 currentMedian = a[0] onRight = 0 def giveLeft(occurences, currentMedian): currentMedian -= 1 while occurences[currentMedian] == 0: currentMedian -= 1 return currentMedian def giveRight(occurences, currentMedian): currentMedian += 1 while occurences[currentMedian] == 0: currentMedian += 1 return currentMedian count = 0 for i in range(1, n): v = a[i] if i >= d: val = currentMedian * 2 if d % 2 == 0: otherMedian = currentMedian if onLeft + occurences[currentMedian] == onRight: otherMedian = giveRight(occurences, currentMedian) val = otherMedian + currentMedian if v >= val: count += 1 occurences[v] += 1 if v > currentMedian: onRight += 1 elif v < currentMedian: onLeft += 1 if i >= d: removedV = a[i - d] occurences[removedV] -= 1 if removedV > currentMedian: onRight -= 1 elif removedV < currentMedian: onLeft -= 1 while onRight + occurences[currentMedian] <= onLeft: onRight += occurences[currentMedian] currentMedian = giveLeft(occurences, currentMedian) onLeft -= occurences[currentMedian] while onLeft + occurences[currentMedian] < onRight: onLeft += occurences[currentMedian] currentMedian = giveRight(occurences, currentMedian) onRight -= occurences[currentMedian] print(count)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys def readline_ints(stdinp): return map(int, stdinp.readline().split()) def calculate_median(expenditures_counter, days): middle = days // 2 count = 0 if days % 2 == 0: median1 = None median2 = None i = 0 while i < 201: count += expenditures_counter[i] if median1 is None and count > middle - 1: median1 = i if expenditures_counter[i] == 1: i += 1 if median2 is None and count > middle and expenditures_counter[i]: median2 = i break i += 1 return (median1 + median2) / 2 for i in range(0, 201): count += expenditures_counter[i] if count > middle: return i def check_notifications(expenditures, days): notifications = 0 expenditures_counter = [0] * 201 for day in range(days - 1): expenditures_counter[expenditures[day]] += 1 for day in range(days, len(expenditures)): expenditures_counter[expenditures[day - 1]] += 1 median = calculate_median(expenditures_counter, days) expenditures_counter[expenditures[day - days]] -= 1 if expenditures[day] >= 2 * median: notifications += 1 return notifications def main(sinp=sys.stdin, sout=sys.stdout): n, days = readline_ints(sinp) sequence = list(readline_ints(sinp)) print(check_notifications(sequence, days), file=sout) main()
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR NONE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR NONE VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def odd(c, d): l = 0 while c[l] <= d // 2: l += 1 return 2 * l def even(c, d): l = 0 while c[l] <= d // 2 - 1: l += 1 r = l if c[l] == d // 2: k = c[l] l += 1 while l <= 200: if c[l] > k: r += l return r l += 1 else: r += l return r def main(): n, d = list(map(int, input().split(" "))) e = list(map(int, input().split(" "))) c = 201 * [0] for i in range(d): c[e[i]] += 1 for j in range(1, 201): c[j] += c[j - 1] r = 0 if d % 2 == 0: for i in range(d, n): if i == d: if e[i] >= even(c, d): r += 1 else: for j in range(e[i - d - 1], 201): c[j] -= 1 for k in range(e[i - 1], 201): c[k] += 1 if e[i] >= even(c, d): r += 1 else: for i in range(d, n): if i == d: if e[i] >= odd(c, d): r += 1 else: for j in range(e[i - d - 1], 201): c[j] -= 1 for k in range(e[i - 1], 201): c[k] += 1 if e[i] >= odd(c, d): r += 1 print(r) main()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR RETURN VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
class Account: def __init__(self, num_of_days): self.d_queue = [] self.d_dict = dict() self.median = None self.d = num_of_days self.count = 0 self.alarm_account = 0 def push(self, value): if self.median and value >= self.median * 2: self.alarm_account += 1 if self.count == self.d: removed = self.d_queue.pop(0) self.d_dict[removed] -= 1 if self.d_dict[removed] == 0: self.d_dict.pop(removed, None) else: self.count += 1 self.d_queue.append(value) if value in self.d_dict: self.d_dict[value] += 1 else: self.d_dict[value] = 1 if self.count < self.d: return sum = 0 even_number = 1 if self.count % 2 == 0 else 0 target = int((self.count + 1) / 2) if not even_number else int(self.count / 2) for value in sorted(self.d_dict): sum += self.d_dict[value] if sum >= target: if not even_number: self.median = value elif sum > target: self.median = value else: next_value = value + 1 while next_value not in self.d_dict: next_value += 1 self.median = (value + next_value) / 2 break n, d = [int(value) for value in input().strip().split(" ")] my_account = Account(d) array = [int(value) for value in input().strip().split(" ")] for value in array: my_account.push(value) print(my_account.alarm_account)
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NONE VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR RETURN ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR IF VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = list(map(int, input().strip().split())) ar = list(map(int, input().strip().split())) def findMedian(counts, d): csum = 0 med1 = None for val, count in enumerate(counts): csum += count if med1 is None and csum >= d // 2: med1 = val if csum >= d // 2 + 1: med2 = val break median = med2 if d % 2 == 0: median = 0.5 * (med1 + med2) return median counts = [0] * 201 for val in ar[0:d]: counts[val] += 1 notifications = 0 for i in range(d, n): if ar[i] >= 2 * findMedian(counts, d): notifications += 1 counts[ar[i - d]] -= 1 counts[ar[i]] += 1 print(notifications)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def getMedian(ar, d): x = (d + 1) // 2 add = 0 index = -1 for i in range(201): add += ar[i] if add >= x: index = i break if d & 1 == 1: return index elif add == x: index1 = index for j in range(index + 1, 201): if ar[i] > 0: return (index1 + j) / 2 else: return index n, d = map(int, input().split()) st = list(map(int, input().split())) res = 0 ar = [(0) for i in range(201)] for i in range(d): ar[st[i]] += 1 i = 0 j = d for j in range(d, n): x = getMedian(ar, d) if 2 * x <= st[j]: res += 1 ar[st[i]] -= 1 ar[st[j]] += 1 i += 1 print(res)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys x = sys.stdin.readlines() n, d = [int(i) for i in x[0].strip().split(" ")] A = [int(i) for i in x[1].strip().split(" ")] def bi_s(A, l, r, k): if l >= r: if A[l] > k: return l else: return l + 1 while l < r: m = (l + (r - 1)) // 2 if A[m] > k: r = m - 1 return bi_s(A, l, r, k) else: l = m + 1 return bi_s(A, l, r, k) D = [A[0]] S = 0 for i in range(1, len(A)): if len(D) == d: if d % 2 and A[i] >= D[d // 2] * 2: S = S + 1 elif not d % 2 and A[i] >= D[d // 2 - 1] + D[d // 2]: S = S + 1 j = bi_s(D, 0, len(D) - 1, A[i - d]) - 1 D.pop(j) j = bi_s(D, 0, len(D) - 1, A[i]) D.insert(j, A[i]) print(S)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER STRING FUNC_DEF IF VAR VAR IF VAR VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def medianpar(): for i in range(201): if valpos[i][0] <= d2 - 1 <= valpos[i][1]: if d2 <= valpos[i][1]: return i x = i break for i in range(x, 201): if valpos[i][0] <= d2 <= valpos[i][1]: return (x + i) / 2.0 def medianimpar(): for i in range(201): if valpos[i][0] <= d2 <= valpos[i][1]: return i def refreshpos(k): if a[k] > a[k - d]: if valpos[a[k]][0] <= valpos[a[k]][1]: valpos[a[k]][0] -= 1 else: i = 1 while valpos[a[k] - i][0] > valpos[a[k] - i][1]: i += 1 valpos[a[k]][0] = valpos[a[k]][1] = valpos[a[k] - i][1] + 1 valpos[a[k - d]][1] -= 1 for v in range(a[k - d] + 1, a[k]): valpos[v][0] -= 1 valpos[v][1] -= 1 elif a[k] < a[k - d]: if valpos[a[k]][0] <= valpos[a[k]][1]: valpos[a[k]][1] += 1 else: i = 1 while valpos[a[k] + i][0] > valpos[a[k] + i][1]: i += 1 valpos[a[k]][0] = valpos[a[k]][1] = valpos[a[k] + i][0] valpos[a[k - d]][0] += 1 for v in range(a[k] + 1, a[k - d]): valpos[v][0] += 1 valpos[v][1] += 1 n, d = [int(x) for x in input().strip().split()] a = [int(x) for x in input().strip().split()] b = sorted(a[:d]) valpos = [[200, 0] for _ in range(201)] for i in range(d): if i < valpos[b[i]][0]: valpos[b[i]][0] = i if i > valpos[b[i]][1]: valpos[b[i]][1] = i adv = 0 d2 = d // 2 median = medianpar if d % 2 == 0 else medianimpar for i in range(d, n): if a[i] >= 2 * median(): adv += 1 refreshpos(i) print(adv)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = map(int, input().split()) hd = d / 2 data = list(map(int, input().split())) count = 201 * [0] for i in range(d): count[data[i]] += 1 def i_at_pos(count, pos): i = -1 s = 0 for e in count: i += 1 if e: s += e if s > pos: break return i def median2(count, n): odd = n % 2 == 1 if odd: return i_at_pos(count, n // 2) else: return 0.5 * (i_at_pos(count, n // 2 - 1) + i_at_pos(count, n // 2)) res = 0 for j in range(d, n): if data[j] >= 2 * median2(count, d): res += 1 count[data[j]] += 1 count[data[j - d]] -= 1 print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def find_median_doubled(): tmp = 0 i = -1 while tmp + count[i + 1] <= d / 2: tmp += count[i + 1] i += 1 if tmp < d / 2: return 2 * i + 2 else: return 2 * i + 1 n, d = map(int, input().split()) e = list(map(int, input().split())) count = [0] * 201 alarm = 0 for i in range(d): count[e[i]] += 1 for i in range(d, n): if e[i] >= find_median_doubled(): alarm += 1 count[e[i - d]] -= 1 count[e[i]] += 1 print(alarm)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = map(int, input().split()) spending = list(map(int, input().split())) history = [0] * 201 ret = 0 for i in range(d): history[spending[i]] += 1 def median(hist): seen = 0 if d % 2: for i in range(len(hist)): seen += hist[i] if seen > d // 2: return i else: for i in range(len(hist)): seen += hist[i] if d // 2 - seen == 0: for nexti in range(i + 1, len(hist)): if hist[nexti]: return (i + nexti) / 2 elif seen > d // 2: return i for j in range(d, n): if spending[j] >= 2 * median(history): ret += 1 history[spending[j]] += 1 history[spending[j - d]] -= 1 print(ret)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def getMedian(counts, d): cum = 0 if d & 1: for i in range(201): cum += counts[i] if cum > d // 2: return i else: for i in range(201): if counts[i] > 0: cum += counts[i] if cum >= d // 2: if cum > d // 2: return i else: j = i + 1 while a[j] == 0: j += 1 return (i + j) / 2 n, d = map(int, input().strip().split()) a = list(map(int, input().strip().split())) counts = [(0) for _ in range(200 + 1)] notices = 0 for i in range(d): counts[a[i]] += 1 for i in range(d, n): newExp = a[i] if newExp >= 2 * getMedian(counts, d): notices += 1 counts[a[i - d]] -= 1 counts[newExp] += 1 print(notices)
FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
import sys def med_points(C, lm, rm): k = 0 lo = C[k] while lo <= lm: lo += C[k + 1] k += 1 j = k while lo <= rm: lo += C[j + 1] j += 1 return k, j n, d = (int(i) for i in input().split()) A = [int(i) for i in input().split()] C = [(0) for _ in range(201)] for i in range(d): C[A[i]] += 1 rm = int(d / 2) lm = rm if d % 2 == 0: lm -= 1 k, j = med_points(C, lm, rm) count = 0 for i in range(d, n): if A[i] >= k + j: count += 1 C[A[i - d]] -= 1 C[A[i]] += 1 if A[i - d] <= k and A[i] <= k or A[i - d] >= j and A[i] >= j: continue else: k, j = med_points(C, lm, rm) print(str(count))
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def median_counter(arr, d): k = d // 2 counter = 0 if d % 2: for idx, val in zip(range(201), arr): counter += val if counter > k: return idx else: flag = False lo = 0 for idx, val in zip(range(201), arr): counter += val if counter == k and not flag: flag, lo = True, idx if flag and counter > k: return 0.5 * (lo + idx) if counter > k: return idx n, d = [int(val) for val in input().split()] counts = [0] * 201 arr = [int(val) for val in input().split()] if d == n: print(0) else: for val in arr[:d]: counts[val] += 1 notifs = 0 for old, val in zip(arr[:-d], arr[d:]): median = median_counter(counts, d) if val >= 2 * median: notifs += 1 counts[val] += 1 counts[old] -= 1 print(notifs)
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR IF VAR VAR VAR RETURN BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = [int(i) for i in input().split(" ")] A = [int(i) for i in input().split(" ")] iMedian = d // 2 B = [0] * 201 for i in range(d): B[A[i]] += 1 count = 0 for i in range(d, n): if d % 2 != 0: iTotal = 0 for j in range(201): iTotal += B[j] if iTotal >= iMedian + 1: break median = j if median * 2 <= A[i]: count += 1 else: iTotal = 0 for j in range(201): iTotal += B[j] if iTotal >= iMedian: break median = j if iTotal == iMedian: j += 1 while B[j] == 0: j += 1 median = (median + j) / 2 if median * 2 <= A[i]: count += 1 B[A[i - d]] -= 1 B[A[i]] += 1 print(count)
ASSIGN 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def findValueAtPos(countArr, pos, startIndex=-1, startPos=0): currPos = startPos index = startIndex while currPos < pos: index += 1 currPos += count[index] return index, currPos def findMedian(countArr, d): medianPos = d // 2 + d % 2 median, currPos = findValueAtPos(countArr, medianPos) if d % 2 == 0 and currPos < medianPos + 1: median = ( median + findValueAtPos(countArr, medianPos + 1, median, currPos)[0] ) / 2.0 return median n, d = [int(i) for i in input().split(" ")] expanditure = [int(i) for i in input().split(" ")] count = [0] * 200 for i in range(d): count[expanditure[i]] += 1 median = findMedian(count, d) alerts = 0 for i in range(d, n - 1): newVal = expanditure[i] oldVal = expanditure[i - d] count[oldVal] -= 1 count[newVal] += 1 if newVal >= 2 * median: alerts += 1 if i == n - 1: break if newVal > median and oldVal <= median or newVal < median and oldVal >= median: median = findMedian(count, d) print(alerts)
FUNC_DEF NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER RETURN VAR ASSIGN 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def calc_median(hist, n): wsum = 0 central = n // 2 if n % 2: for i in range(len(hist)): wsum += hist[i] if wsum > central: return float(i) else: left = -1 right = -1 for i in range(len(hist)): wsum += hist[i] if wsum >= central and left == -1: left = i if wsum > central and right == -1: right = i if left > -1 and right > -1: if left + right == 0: return 0 else: return float(left + right) / 2 n, d = [int(x) for x in input().split(" ")] exp = [int(x) for x in input().split(" ")] hist = [0] * 201 notifications = 0 for i in range(d): hist[exp[i]] += 1 for i in range(n - d): median = calc_median(hist, d) if exp[i + d] >= median * 2: notifications += 1 hist[exp[i + d]] += 1 hist[exp[i]] -= 1 print(notifications)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN 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 ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = input().split(" ") n, d = int(n), int(d) exp = [int(e) for e in input().split(" ")] tracker = [0] * 201 over_med = 0 for i in range(d): daily_exp = exp[i] tracker[daily_exp] += 1 def find_index(days, arr): days += 1 i = 0 while i < 201: days -= arr[i] if days <= 0: return i i += 1 for k in range(d, len(exp)): ind_remove = k - d num_remove = exp[ind_remove] ind_add = k num_add = exp[ind_add] if d % 2 == 0: med1 = find_index(d / 2, tracker) med2 = find_index(d / 2 - 1, tracker) med = (med1 + med2) / 2 else: med = find_index(int(d / 2), tracker) if num_add >= med * 2: over_med += 1 tracker[num_remove] -= 1 tracker[num_add] += 1 print(over_med)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR IF VAR NUMBER RETURN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def calculate_median(counts, d): cumulative_count = 0 for expenditure, count in enumerate(counts): cumulative_count += count if cumulative_count > (d + 1) // 2: return expenditure elif cumulative_count == (d + 1) // 2: if d % 2 == 1: return expenditure else: next_expenditure = expenditure + 1 while not counts[next_expenditure]: next_expenditure += 1 return (expenditure + next_expenditure) / 2 n, d = map(int, input().split()) counts = [0] * 201 expenditures = [int(s) for s in input().split()] for i in range(d): counts[expenditures[i]] += 1 notification_count = 0 for i in range(d, n): if expenditures[i] >= 2 * calculate_median(counts, d): notification_count += 1 counts[expenditures[i - d]] -= 1 counts[expenditures[i]] += 1 print(notification_count)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = map(int, input().strip().split(" ")) a = list(map(int, input().strip().split(" "))) w = [0] * 201 for i in range(d): w[a[i]] += 1 c = 0 if d % 2 != 0: m = (d + 1) // 2 for i in range(n - d): mi = 0 for j in range(201): mi += w[j] if mi >= m: mv = j break if a[d + i] >= mv * 2: c += 1 w[a[i]] -= 1 w[a[d + i]] += 1 else: m = d // 2 for i in range(n - d): mi, li, lo = 0, 0, 0 for j in range(201): mi += w[j] if mi >= m and li == 0: li = j if mi >= m + 1 and lo == 0: lo = j if li != 0 and lo != 0: mv = (li + lo) / 2 break if a[d + i] >= mv * 2: c += 1 w[a[i]] -= 1 w[a[d + i]] += 1 print(c)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def readInts(): return map(int, input().strip().split()) def fraudulent_activity_notifications(): def x2median_array(e): lo_count = 0 lo_value = -1 lo_value_data = None hi_count = 0 hi_value = 201 hi_value_data = None while lo_value < hi_value - 1: if lo_count > hi_count: hi_value -= 1 v = e[hi_value] if v > 0: hi_value_data = hi_value hi_count += v else: lo_value += 1 v = e[lo_value] if v > 0: lo_value_data = lo_value lo_count += e[lo_value] if lo_count > hi_count: return lo_value_data * 2 elif lo_count < hi_count: return hi_value_data * 2 else: return lo_value_data + hi_value_data n, d = readInts() expenditures = list(readInts()) values = [(0) for _ in range(201)] out = 0 en = len(expenditures) for i in range(en): e = expenditures[i] if i >= d: e_minus_d = expenditures[i - d] x2med = x2median_array(values) if e >= x2med: out += 1 values[e_minus_d] -= 1 values[e] += 1 print(out) fraudulent_activity_notifications()
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP VAR NUMBER IF VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
n, d = map(int, input().strip().split(" ")) exps = [int(i) for i in input().strip().split(" ")] def median(l): if len(l) % 2 == 1: return l[len(l) // 2] else: return (l[len(l) // 2] + l[len(l) // 2 + 1]) / 2 notifications = 0 hist = [0] * 201 for i in exps[0:d]: hist[i] += 1 for i in range(d, n): m = 0.0 if d % 2 != 0: days = 0 for j in range(201): days += hist[j] if days >= d // 2 + 1: m = float(j) break else: days = 0 m1 = 0 m2 = 0 for j in range(201): days += hist[j] if days >= d // 2 and m1 == 0.0: m1 = float(j) if days > d // 2 and m2 == 0.0: m2 = float(j) if m1 != 0.0 and m2 != 0.0: m = (m1 + m2) / 2 break if exps[i] >= 2 * m: notifications += 1 hist[exps[i - d]] -= 1 hist[exps[i]] += 1 print(notifications)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def counting_sort(arr): cnt = [0] * 201 for i in arr: cnt[i] += 1 return cnt def median(arr, len_arr): mids = [] if len_arr % 2 == 0: v1 = len_arr // 2 - 1 v2 = len_arr // 2 else: v1 = len_arr // 2 v2 = None run_cnt = -1 for i, x in enumerate(arr): run_cnt += x if v1 != None: if v1 <= run_cnt: v1 = None mids.append(i) if v2 != None: if v2 <= run_cnt: v2 = None mids.append(i) if v1 == None and v2 == None: return sum(mids) / len(mids) def alert(m, s): if s >= 2 * m: return True else: return False n, d = map(int, input().split()) arr = list(map(int, input().split())) count = counting_sort(arr[:d]) alert_cnt = 0 for day in range(d, n): m = median(count, d) if alert(m, arr[day]): alert_cnt += 1 count[arr[day - d]] -= 1 count[arr[day]] += 1 print(alert_cnt)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE IF VAR VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR IF VAR NONE IF VAR VAR ASSIGN VAR NONE EXPR FUNC_CALL VAR VAR IF VAR NONE VAR NONE RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN 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 FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
def findMedian(): global dic, med, double count = 0 i = 0 for i in range(201): if i in dic: count += dic[i] else: continue if count >= med: break if not double: return i if count == med: a = i i += 1 while i not in dic: i += 1 return (a + i) / 2 else: return i def update(remove, add): global data, dic if remove < 0: for i in range(0, add + 1): if data[i] not in dic: dic[data[i]] = 1 else: dic[data[i]] += 1 return dic[data[remove]] -= 1 if dic[data[remove]] == 0: del dic[data[remove]] if data[add] not in dic: dic[data[add]] = 1 else: dic[data[add]] += 1 global n, d, data, dic, med, double n, d = list(map(int, input().split())) data = list(map(int, input().split())) notifications = 0 double = False if d % 2 == 0: double = True med = d // 2 if not double: med += 1 dic = dict() for i in range(d, n): update(i - d - 1, i - 1) median = findMedian() median = median * 2 if data[i] >= median: notifications += 1 print(notifications)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR IF VAR RETURN VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on. For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1). In how many seconds will Mr. Bender get happy? -----Input----- The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 10^9; 1 ≤ x, y ≤ n; c ≤ n^2). -----Output----- In a single line print a single integer — the answer to the problem. -----Examples----- Input 6 4 3 1 Output 0 Input 9 3 8 10 Output 2 -----Note----- Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. [Image].
x, y, n, c = 0, 0, 0, 0 def suma_impares(m): return m * m def suma_n(m): return m * (m - 1) // 2 def cnt(t): u, d, l, r = x + t, x - t, y - t, y + t suma = t**2 + (t + 1) ** 2 if u > n: suma -= suma_impares(u - n) if d < 1: suma -= suma_impares(1 - d) if l < 1: suma -= suma_impares(1 - l) if r > n: suma -= suma_impares(r - n) if 1 - l > x - 1 and 1 - d > y - 1: suma += suma_n(2 - l - x) if r - n > x - 1 and 1 - d > n - y: suma += suma_n(r - n - x + 1) if 1 - l > n - x and u - n > y - 1: suma += suma_n(1 - l - n + x) if u - n > n - y and r - n > n - x: suma += suma_n(u - n - n + y) return suma n, x, y, c = input().split() n, x, y, c = int(n), int(x), int(y), int(c) ini, fin = 0, int(1000000000.0) cont = int(1000000000.0) while cont > 0: m = ini paso = cont // 2 m += paso if cnt(m) < c: ini = m + 1 cont -= paso + 1 else: cont = paso print(ini)
ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on. For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1). In how many seconds will Mr. Bender get happy? -----Input----- The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 10^9; 1 ≤ x, y ≤ n; c ≤ n^2). -----Output----- In a single line print a single integer — the answer to the problem. -----Examples----- Input 6 4 3 1 Output 0 Input 9 3 8 10 Output 2 -----Note----- Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. [Image].
def compute(n, x, y, c): x1 = min(x - 1, n - x) x2 = n - x1 - 1 y1 = min(y - 1, n - y) y2 = n - y1 - 1 i1 = x1 + y1 + 1 i2 = min(y1 + x2, y2 + x1) + 1 i3 = max(y1 + x2, y2 + x1) + 1 o1 = min(x1, y1) o2 = min(max(x1, y1), min(y2, x2)) o3 = max(max(x1, y1), min(y2, x2)) o4 = max(y2, x2) inside = 0 out = 0 s = 0 current = 1 Happy = False if c == 1: print(0) return 0 while Happy == False: s += 1 new = (s + 1) * 4 - 4 out = out + out_new(s, o1) + out_new(s, o2) + out_new(s, o3) + out_new(s, o4) inside = inside + in_new(s, i1) + in_new(s, i2) + in_new(s, i3) current = current + new test = current - out + inside if test >= c: print(s) break return s def out_new(s, sx): if sx < s: return (s - sx) * 2 - 1 else: return 0 def in_new(s, sx): if sx < s: return s - sx else: return 0 x = input() y = x.split() a = int(y[0]) b = int(y[1]) c = int(y[2]) d = int(y[3]) compute(a, b, c, d)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR 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 FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR
Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on. For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1). In how many seconds will Mr. Bender get happy? -----Input----- The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 10^9; 1 ≤ x, y ≤ n; c ≤ n^2). -----Output----- In a single line print a single integer — the answer to the problem. -----Examples----- Input 6 4 3 1 Output 0 Input 9 3 8 10 Output 2 -----Note----- Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. [Image].
import sys ii = lambda: sys.stdin.readline().strip() idata = lambda: [int(x) for x in ii().split()] sdata = lambda: list(ii()) def solve(): n, x, y, c = idata() r = n**2 l = -1 while l + 1 < r: middle = (l + r) // 2 ans = 1 + 2 * (middle + 1) * middle ans -= pow(middle - n + y, 2) if middle - n + y > 0 else 0 ans -= pow(middle + 1 - y, 2) if middle + 1 - y > 0 else 0 ans -= pow(middle - n + x, 2) if middle - n + x > 0 else 0 ans -= pow(middle + 1 - x, 2) if middle + 1 - x > 0 else 0 d = 1 + n - x + y if middle >= d: ans += (middle - d + 1) * (middle - d + 2) // 2 d = 2 + 2 * n - y - x if middle >= d: ans += (middle - d + 1) * (middle - d + 2) // 2 d = 1 + n - y + x if middle >= d: ans += (middle - d + 1) * (middle - d + 2) // 2 d = x + y if middle >= d: ans += (middle - d + 1) * (middle - d + 2) // 2 if ans >= c: r = middle else: l = middle print(r) return for t in range(1): solve()
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) x = [0] * n is_true = True for i in range(n): l = (i + a[i]) % n if x[l] == 0: x[l] += 1 else: is_true = False break if is_true: print("YES") else: print("NO")
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
T = int(input()) for _ in range(T): N = int(input()) print( "YES" if len(set([((int(a) + i) % N) for i, a in enumerate(input().split())])) == N else "NO" )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
from sys import stdin, stdout input = stdin.buffer.readline t = int(input()) while t > 0: n = int(input()) a = [int(x) for x in input().split()] c = [] for i in range(n): c.append(0) for i in range(n): val = i + a[i] c[val % n] += 1 flag = 1 for i in range(n): if c[i] != 1: flag = 0 break if flag == 1: print("YES") else: print("NO") t -= 1
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for _ in range(t): n = int(input()) als = list(map(int, input().split())) ans = "YES" ls = [(0) for _ in range(n)] for i in range(n): if ls[(als[i] + i) % n] != 0: ans = "NO" else: ls[(als[i] + i) % n] += 1 print(ans)
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 STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR STRING VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() b = [0] * n j = 0 for i in mints(): b[(i + j) % n] += 1 j += 1 print(["NO", "YES"][b.count(1) == n]) for i in range(mint()): solve()
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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys input = sys.stdin.readline for T in range(int(input())): N = int(input()) k = list(map(int, input().split())) k = [(x % N) for x in k] v = [0] * N for i in range(N): v[(i + k[i]) % N] += 1 print("NO" if len([x for x in v if x > 1]) else "YES")
IMPORT ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) l = [0] * n a = list(map(int, input().split())) ans = "YES" for i in range(n): o = (i + a[i]) % n if l[o] == 1: ans = "NO" break else: l[o] = 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) ls = [] for i in range(len(a)): ls.append((i + a[i]) % n) s = set(ls) print("YES" if len(s) == len(ls) else "NO")
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for s in [*open(0)][2::2]: a = s.split() n = len(a) s = {*range(n)} print("YNEOS"[s > {((k + int(a[k])) % n) for k in s} :: 2])
FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
n = int(input()) for i in range(n): t = int(input()) ar = [int(k) for k in input().split()] ans = [] for s in range(t): ans.append((s + ar[s]) % t) ans.sort() if ans == [j for j in range(t)]: print("YES") else: print("NO")
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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solve(n, s): if n == 1: return "YES" a = [i for i in range(n)] for j in range(n): a[j] = (a[j] + s[j]) % n if len(set(a)) != len(a): return "NO" else: return "YES" t = int(input()) for i in range(t): n = int(input()) s = list(map(int, input().split())) print(solve(n, s))
FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN STRING RETURN STRING 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
T = int(input()) for _ in range(T): N = int(input()) data = list(map(lambda x: int(x) % N, input().split())) occupied = [False] * N ans = "YES" for i, elt in enumerate(data): if occupied[(i + elt) % N]: ans = "NO" break else: occupied[(i + elt) % N] = True print(ans)
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 BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solve(n, a): state = [False] * n for i, x in enumerate(a): ni = (i + (x + abs(x) * n)) % n state[ni] = True return all(state) t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) print("YES" if solve(n, a) else "NO")
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for test in range(t): n = int(input()) arr = list(map(int, input().split())) D = set() count = 0 ans = "YES" for i in arr: a = (i + count) % n if a in D: ans = "NO" break D.add(a) count += 1 print(ans)
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 ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def main(): t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = set() for idx, i in enumerate(a): s.add((idx + i) % n) print("YES" if len(s) == n else "NO") return main()
FUNC_DEF 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING RETURN EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
k = int(input()) for _ in range(k): n = int(input()) arr = list(map(int, input().split())) for i in range(len(arr)): arr[i] += i arr[i] %= n arr.sort() m = 0 for i in range(len(arr)): if arr[i] != i: m = 1 print("NO") break if m == 0: print("YES")
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) a = [(item % n) for item in a] after_used = [(False) for _ in range(n)] for i in range(n): next_stop = (i + a[i]) % n after_used[next_stop] = True if sum(after_used) == n: print("YES") else: print("NO")
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 BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solve(arr, n): d = set() for i in range(len(arr)): d.add((i + arr[i % n]) % n) return "YES" if len(d) == n else "NO" T = int(input()) for _ in range(T): n = int(input()) arr = list(map(int, input().split())) print(solve(arr, n))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR STRING STRING 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def main(): t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = set() poss = True for i in range(n): new_room = (i + a[i] % n) % n if new_room in s: print("NO") poss = False break s.add(new_room) if poss: print("YES") main()
FUNC_DEF 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
from sys import stdin, stdout for _ in range(int(stdin.readline())): n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] lol = [] for i in range(n): lol.append((i + a[i] % n) % n) if len(set(lol)) == n: stdout.write("YES" + "\n") else: stdout.write("NO" + "\n")
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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING STRING EXPR FUNC_CALL VAR BIN_OP STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys def load_sys(): return sys.stdin.readlines() def load_local(): with open("input.txt", "r") as f: input = f.readlines() return input def hh(n, A): seen = set() for i in range(n): m = (i + A[i]) % n while m < 0: m += n if m in seen: return "NO" seen.add(m) return "YES" input = load_sys() idx = 1 N = len(input) while idx < len(input): n = int(input[idx].split()[0]) A = [int(x) for x in input[idx + 1].split()] idx += 2 print(hh(n, A))
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF FUNC_CALL VAR STRING STRING VAR ASSIGN VAR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR IF VAR VAR RETURN STRING EXPR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solve(nr): for i in range(len(nr)): for j in range(i + 1, len(nr)): if nr[i] == nr[j]: return "No" else: return "YES" t = int(input()) for _ in range(t): k = int(input()) arr = list(map(int, input().split())) nr = [] for i in range(len(arr)): nr.append((i + arr[i]) % k) print(solve(nr))
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN STRING RETURN STRING 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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
from sys import stdin, stdout input = stdin.readline for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) rooms = dict() for i in range(n): rooms[i] = 1 was = set() for i in range(n): new_ind = i + arr[i] if new_ind not in rooms: rooms[new_ind] = 0 rooms[new_ind] += 1 was.add(new_ind % n) rooms[i] -= 1 can = True for i in range(n): if rooms[i] > 1: can = False break elif rooms[i] == 0 and i not in was: can = False break if rooms[i + arr[i]] != 1: can = False break if can: print("YES\n") else: print("NO\n")
ASSIGN VAR 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for w in range(int(input())): n = int(input()) k = [] a = list(map(int, input().split())) for i in range(1, 2 * n + 1): if i <= n: s = i + a[i - 1] % n else: s = i + a[i - n - 1] % n k.append(s) if len(list(set(k))) == len(k): print("Yes") else: print("No")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) arr = [int(i) for i in input().split()] rooms = set() for j in range(n): k = (arr[j] + j) % n if k in rooms: print("NO") break rooms.add(k) else: print("YES")
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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
from sys import stdin a = int(stdin.readline()) for b in range(0, a): c = int(stdin.readline()) d = stdin.readline().split() A = set() l = 0 K = 0 for e in range(0, c): test = (e + int(d[e])) % c A.add(test) if len(A) == l: print("NO") K = 1 break else: l += 1 if K == 0: print("YES")
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys def answer(n, a): if n == 1: return "YES" done = [(False) for _ in range(n)] for i in range(n): m = (i + a[i]) % n if done[m]: return "NO" done[m] = True return "YES" def main(): t = int(sys.stdin.readline()) while t: n = int(sys.stdin.readline()) a = tuple(map(int, sys.stdin.readline().split())) print(answer(n, a)) t -= 1 return main()
IMPORT FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR VAR NUMBER RETURN STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 FUNC_CALL VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys input = sys.stdin.readline t = int(input()) out = [] for i in range(t): n = int(input()) l = list(map(lambda x: int(x) % n, input().split())) taken = [False] * n for i in range(n): taken[(i + l[i]) % n] = True for i in range(n): if not taken[i]: out.append("NO") break else: out.append("YES") print("\n".join(out))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) f = 1 a = list(map(int, input().split())) for i in range(n): if a[i] == 0: f = 0 break for i in range(n): a[i] = (i + a[i % n]) % n if len(set(a)) == n: print("YES") else: print("NO")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
T = int(input()) for _ in range(0, T): n = int(input()) s = [int(x) for x in input().split()] L = [] temp = "YES" for i in range(0, len(s)): tt = (i + s[i]) % n L.append(tt) pos = [0] * n for i in range(0, len(L)): pos[L[i]] += 1 for i in range(0, len(pos)): if pos[i] > 1: temp = "NO" break print(temp)
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solve(): N = int(input()) A = list(map(int, input().split())) S = set() for i in range(N): S.add((i + A[i]) % N) if len(S) == N: print("YES") else: print("NO") for _ in range(int(input())): solve()
FUNC_DEF 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) P = [] for i in range(n): P.append(i + A[i] % n) D = set(P) f = 0 for i in D: if i + n in P: f = 1 break if f == 1: print("NO") continue if len(D) < n: print("NO") else: print("YES")
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 BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) a_mod = [(i % n) for i in a] sol = [0] * n flag = True for i in range(n): if sol[(i + a_mod[i]) % n] == 1: print("NO") flag = False break else: sol[(i + a_mod[i]) % n] = 1 if flag: print("YES")
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 BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) for i in range(len(arr)): if arr[i] < 0: arr[i] = abs(arr[i]) % n * -1 else: arr[i] = arr[i] % n t = [0] * n temp = [1] * (3 * n) temp = t + temp + t for i in range(n, 4 * n): temp[i] -= 1 temp[i + arr[i % n]] += 1 if 2 in temp: print("NO") continue if 0 in temp[2 * n : 3 * n]: print("NO") continue print("YES")
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 FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING IF NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
tc = int(input()) for _ in range(tc): n = int(input()) a = list(map(int, input().split())) deg = [0] * n for i in range(len(a)): j = (a[i] + i) % n if j >= 0 and j < n: deg[j] += 1 for x in deg: if x != 1: ans = "NO" break else: ans = "YES" print(ans)
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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) for i in range(n): a[i] %= n aux = [0] * (n + 1) ok = True for i in range(n): if aux[(i + a[i]) % n]: ok = False break aux[(a[i] + i) % n] = 1 print("YES" if ok else "NO")
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 FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) s = set() for i, val in enumerate(a): s.add((i + val) % n) if len(s) == n: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
n = int(input()) for i in range(0, n): o = int(input()) L = [] K = 1 G = 0 p = input().rstrip().split(" ") for j in range(0, len(p)): T = (K + int(p[K % o])) % o if T in L: G = 1 break K += 1 L.append(T) if G == 1: print("NO") else: print("YES")
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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solve(): n = int(input()) a = list(map(int, input().split())) s = set() for i, a in enumerate(a): if (i + a) % n in s: print("no") return s.add((i + a) % n) print("yes") t = int(input()) for _ in range(t): solve()
FUNC_DEF 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 FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
def solution(A, n): B = [(0) for _ in range(n)] for i in range(n): j = (i + A[i] % n) % n B[j] += 1 if B[j] > 1: return "NO" return "YES" t = int(input()) for _ in range(t): n = int(input()) A = list(map(int, input().split(" "))) print(solution(A, n))
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER RETURN STRING RETURN STRING 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 STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
test = int(input()) for t in range(test): n = int(input()) a = list(map(int, input().split())) attendance = [(False) for i in range(n)] for i in range(1, n + 1): x = (i + a[i % n]) % n if attendance[x] == True: print("NO") break else: attendance[x] = True if False not in attendance: print("YES")
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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for i in range(t): n = int(input()) s = input().split() for j in range(n): s[j] = int(s[j]) s[j] = j + s[j] s[j] = s[j] % n x = set(s) if len(x) == n: print("YES") else: print("NO")
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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) def mod(a, b): return (a % b + b) % b while t: t -= 1 n = int(input()) z = [(0) for _ in range(n)] a = list(map(int, input().split())) for i, x in enumerate(a): z[mod(i + x, n)] += 1 if all(z): print("Yes") else: print("No")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys readline = sys.stdin.readline T = int(readline()) Ans = ["NO"] * T for qu in range(T): N = int(readline()) A = list(map(int, readline().split())) S = set() for i in range(N): S.add((i + A[i]) % N) if len(S) == N: Ans[qu] = "YES" print("\n".join(map(str, Ans)))
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
tc = int(input()) while tc > 0: n = int(input()) slots = [(0) for i in range(n)] a = list(map(int, input().split())) for i in range(n): slots[i] -= 1 slots[(i + a[i] % n) % n] += 1 ans = "Yes" for v in slots: if v != 0: ans = "No" break print(ans) tc -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) while t != 0: n = int(input()) list1 = list(map(int, input().split())) dict = {} f1 = 0 for i in range(n): p = (i + list1[i]) % n try: dict[p] += 1 f1 = 1 except Exception as e: dict[p] = 1 if f1 == 1: break if f1 == 1: print("NO") else: print("YES") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
import sys readline = sys.stdin.readline ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) def solve(): n = ni() print("YES" if len(set([((x + i) % n) for i, x in enumerate(nl())])) == n else "NO") T = ni() for _ in range(T): solve()
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
T = int(input()) for i in range(T): n = int(input()) s = set() l = list(map(int, input().split())) for j in range(len(l)): s.add((j + l[j]) % n) print("YES" if len(s) == n else "NO")
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) while t: t += -1 n = int(input()) l = list(map(int, input().split())) check = [0] * n for i in range(n): check[(i + l[i]) % n] = 1 if 0 in check: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) l = [0] * n for i in range(n): l[i] = (i + a[i] + n) % n l.sort() for i in range(n - 1): if l[i + 1] != l[i] + 1: print("NO") break else: print("YES")
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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = [0] * n for i in range(n): b[i] = (i + a[i]) % n if b[i] < 0: b[i] += n if len(set(b)) == n: print("YES") else: print("NO")
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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is exactly one guest in every room. The hotel's manager, David Hilbert himself, decides he wants to shuffle the guests around because he thinks this will create a vacancy (a room without a guest). For any integer $k$ and positive integer $n$, let $k\bmod n$ denote the remainder when $k$ is divided by $n$. More formally, $r=k\bmod n$ is the smallest non-negative integer such that $k-r$ is divisible by $n$. It always holds that $0\le k\bmod n\le n-1$. For example, $100\bmod 12=4$ and $(-1337)\bmod 3=1$. Then the shuffling works as follows. There is an array of $n$ integers $a_0,a_1,\ldots,a_{n-1}$. Then for each integer $k$, the guest in room $k$ is moved to room number $k+a_{k\bmod n}$. After this shuffling process, determine if there is still exactly one guest assigned to each room. That is, there are no vacancies or rooms with multiple guests. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. Next $2t$ lines contain descriptions of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of the array. The second line of each test case contains $n$ integers $a_0,a_1,\ldots,a_{n-1}$ ($-10^9\le a_i\le 10^9$). It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. -----Output----- For each test case, output a single line containing "YES" if there is exactly one guest assigned to each room after the shuffling process, or "NO" otherwise. You can print each letter in any case (upper or lower). -----Example----- Input 6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11 Output YES YES YES NO NO YES -----Note----- In the first test case, every guest is shifted by $14$ rooms, so the assignment is still unique. In the second test case, even guests move to the right by $1$ room, and odd guests move to the left by $1$ room. We can show that the assignment is still unique. In the third test case, every fourth guest moves to the right by $1$ room, and the other guests move to the right by $5$ rooms. We can show that the assignment is still unique. In the fourth test case, guests $0$ and $1$ are both assigned to room $3$. In the fifth test case, guests $1$ and $2$ are both assigned to room $2$.
testcases = int(input()) for _ in range(testcases): n = int(input()) l = list(map(int, input().split())) k = [(0) for i in range(n)] flag = 0 for i in range(len(l)): p = (i + l[i]) % n k[p] += 1 for i in range(len(k)): if k[i] != 1: flag = 1 if flag == 0: print("YES") else: print("NO")
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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING