description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | N = int(input())
arr = input()
arr = list(map(int, arr.split(" ")))
dict1 = {}
dict2 = {}
ans = 0
for i in range(0, N):
ans += i * arr[i]
ans -= (N - i - 1) * arr[i]
for i in range(0, N):
op1 = 0
if arr[i] - 1 in dict1:
op1 = dict1[arr[i] - 1]
op2 = 0
if arr[i] + 1 in dict1:
op2 ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIG... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = [int(x) for x in input().split()]
sm = sum(arr)
d = {}
for i in arr:
d[i] = d.get(i, 0) + 1
ans = 0
cnt = n
for i in range(n):
temp = sm
temp -= d.get(arr[i], 0) * arr[i]
temp -= d.get(arr[i] - 1, 0) * (arr[i] - 1)
temp -= d.get(arr[i] + 1, 0) * (arr[i] + 1)
val = (
... | 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 VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
numbers = list(map(int, input().split()))
count = {}
pre_sum = 0
ans = 0
for i in range(len(numbers)):
cnt = 0
sum = 0
for j in range(-1, 2):
cnt += count[numbers[i] + j] if numbers[i] + j in count else 0
sum += (
(numbers[i] + j) * count[numbers[i] + j] if numbe... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
ans = 0
a = [int(i) for i in input().split(" ")]
c = dict()
for i in a:
c[i] = c[i - 1] = c[i + 1] = 0
for i in range(n):
x = a[i]
c[x] = c[x] + 1
ans = ans + c[x + 1] - c[x - 1] + x * (i + 1 - n + i)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
dic = {}
ans = s = 0
k = input().split()
for i in range(n):
a = int(k[i])
if a - 1 in dic:
b = dic[a - 1]
else:
b = 0
if a in dic:
c = dic[a]
else:
c = 0
dic.update({a: 0})
if a + 1 in dic:
d = dic[a + 1]
else:
d = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR DICT V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
array = list(map(int, input().split()))
d = dict()
t, c = 0, 0
for i in range(len(array)):
c += array[i]
t += (i + 1) * array[i] - c
if array[i] in d:
d[array[i]] += 1
else:
d[array[i]] = 1
if array[i] + 1 in d:
t += d[array[i] + 1]
if array[i] - 1 in d:
... | 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 VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
m = {}
s = 0
for i in range(0, len(a)):
if a[i] in m:
m[a[i]] = m[a[i]] + 1
else:
m[a[i]] = 1
if a[i] + 1 in m:
s += m[a[i] + 1] * 1
if a[i] - 1 in m:
s += m[a[i] - 1] * -1
t = 2 * i - n + 1
s += t * a[i]
print(... | 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 NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = input().split()
b = []
for x in arr:
b.append(int(x))
cnt = {}
ans = 0
for i in range(n):
ans += b[i] * i + -b[i] * (n - i - 1)
for i in range(n):
if b[i] - 1 in cnt.keys():
ans -= cnt[b[i] - 1]
if b[i] + 1 in cnt.keys():
ans += cnt[b[i] + 1]
if b[i] in cnt.key... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUM... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
lis = input().split()
a = list()
sum = [0]
dic = dict()
for i in range(n):
a.append(int(lis[i]))
sum.append(sum[i] + a[i])
dic[a[i]] = 0
ans = 0
for i in range(n):
ans = ans + (i * a[i] - sum[i])
if a[i] - 1 in dic.keys():
ans = ans - dic[a[i] - 1]
if a[i] + 1 in dic.key... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = list(map(int, input().split()))
ans = 0
mp = {}
dict = {}
for i in range(0, n):
mp[arr[i]] = 0
for i in range(0, n):
x = arr[i]
ans = ans + i * x - (n - i - 1) * x
if x + 1 in mp:
ans = ans + mp[x + 1]
if x - 1 in mp:
ans = ans - mp[x - 1]
mp[x] = mp[x] + 1... | 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 ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BI... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(i) for i in input().split()]
ans = 0
map = dict()
for i in range(0, n):
ans += (i - map.get(a[i], 0) - map.get(a[i] - 1, 0) - map.get(a[i] + 1, 0)) * a[i]
map[a[i]] = map.get(a[i], 0) + 1
map = dict()
for i in range(n - 1, -1, -1):
ans -= (
n - i - 1 - map.get(a[i], 0) - ma... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMB... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
cnt = dict()
def get(x):
global cnt
if x in cnt:
return cnt[x]
return 0
def inc(x):
global cnt
if x in cnt:
cnt[x] += 1
return
cnt[x] = 1
s = 0
ans = 0
for i in range(n):
ans += i * a[i] - s - get(a[i] - 1) + ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
x = n
L = [int(i) for i in input().strip().split(" ")]
d = {}
for u in L:
d[str(u)] = 0
d[str(u + 1)] = 0
d[str(u - 1)] = 0
CS = 0
Al = 0
i = 0
for j in L:
d[str(j)] = d[str(j)] + 1
x, y = j - 1, j + 1
L = d[str(x)]
A = d[str(y)]
CS += j * i - Al - L + A
Al += j
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
p = [0] * (n + 1)
for i in range(n):
p[i + 1] = p[i] + a[i]
mp = dict()
cnt = 0
for i in range(n):
f1 = mp.setdefault(a[i])
f2 = mp.setdefault(a[i] - 1)
f3 = mp.setdefault(a[i] + 1)
if f1 == None:
f1 = 0
if f2 == None:
f2 = 0
... | 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CAL... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
nums = list(map(int, input().split()))
pref = [0] * (n + 1)
for i in range(n):
pref[i + 1] = pref[i] + nums[i]
counter = dict()
answer = 0
counter[nums[0]] = 1
for i in range(1, n):
answer += nums[i] * i - pref[i]
answer -= counter.get(nums[i] - 1, 0)
answer += counter.get(nums[i] + 1, ... | 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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CAL... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split(" ")))
summ = 0
diff = 0
d = {}
for i in range(0, n):
diff += i * a[i] - summ
summ += a[i]
d[a[i]] = 0
d[a[i] - 1] = 0
d[a[i] + 1] = 0
for i in range(0, n):
diff -= d[a[i] - 1] - d[a[i] + 1]
d[a[i]] += 1
print(diff) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | cnt = {}
n = int(input())
a = list(map(int, input().split()))
sum = 0
ans = 0
for i in range(0, n):
x = a[i]
sum += x
if not x in cnt:
cnt[x] = 0
if not x + 1 in cnt:
cnt[x + 1] = 0
if not x - 1 in cnt:
cnt[x - 1] = 0
cnt[x] += 1
ans += (i + 1 - cnt[x] - cnt[x - 1] - ... | ASSIGN VAR DICT 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_O... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
M = dict()
ans = 0
for i in range(n):
M[a[i]] = M[a[i] - 1] = M[a[i] + 1] = 0
S = 0
for i in range(n - 1, -1, -1):
y = a[i]
c = n - i - 1 - M[y - 1] - M[y] - M[y + 1]
ans += S - (y + 1) * M[y + 1] - (y - 1) * M[y - 1] - y * M[y] - c * y
M[y] += 1
... | 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 VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NU... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def main():
n = int(input())
ans = 0
s = 0
k = {}
i = 0
for y in input().split():
x = int(y)
ans += i * x - k.get(x - 1, 0) + k.get(x + 1, 0) - s
k[x] = k.get(x, 0) + 1
s += x
i += 1
print(ans)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
L = {}
sum = 0
for i, v in enumerate(input().split(" ")):
a = int(v)
if a in L:
L[a] += 1
else:
L[a] = 1
sum += (2 * i - n + 1) * a
if a - 1 in L:
sum -= L[a - 1]
if a + 1 in L:
sum += L[a + 1]
print(sum) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF B... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
v = [int(x) for x in input().split()]
mp = {}
s = sum(v)
ans = 0
cnt = n
for i in range(n):
if v[i] in mp:
mp[v[i]] += 1
else:
mp[v[i]] = 1
for i in range(n):
c = v[i]
s -= c
cnt -= 1
ans += s - cnt * c
ans -= mp.get(c + 1, 0)
ans += mp.get(c - 1, 0)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUM... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | import sys
d = {}
n = int(input())
a = [int(i) for i in input().split()]
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
ss = sum(a)
ans = 0
for i in range(n):
ss -= a[i]
s = ss
d[a[i]] -= 1
k = n - i - 1
if a[i] - 1 in d:
k -= d[a[i] - 1]
s -= d[a[i] - 1] * ... | IMPORT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split()]
ans = 0
summ = 0
mp = {}
for i in range(0, n):
l = 0
if a[i] - 1 in mp:
l = mp[a[i] - 1]
r = 0
if a[i] + 1 in mp:
r = mp[a[i] + 1]
ans = ans + i * a[i] - summ - (l - r)
summ = summ + a[i]
x = 0
if a[i] in mp:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().strip().split()))
mapp = {}
for i in a:
mapp[i] = 0
mapp[i + 1] = 0
mapp[i - 1] = 0
s = sum(a)
ans = 0
for i in range(n):
mapp[a[i]] += 1
ans += s - a[i] * (n - i)
s -= a[i]
ans += mapp[a[i] + 1]
ans -= mapp[a[i] - 1]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
sum = 0
res = 0
v = [int(x) for x in input().split()]
m = {}
for i in range(n - 1, -1, -1):
sum += v[i]
cur = n - i
if m.get(v[i]):
m[v[i]] += 1
else:
m[v[i]] = 1
cursum = sum - m[v[i]] * v[i]
cur -= m[v[i]]
if m.get(v[i] - 1):
cursum -= m[v[i] - 1] *... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
d = {}
ans = 0
a = list(map(int, input().split()))
sumsofar = a[0]
for i in range(1, n):
ans += i * a[i] - sumsofar
sumsofar += a[i]
d[a[0]] = 1
for i in range(1, n):
try:
ans -= d[a[i] - 1]
except:
pass
try:
ans += d[a[i] + 1]
except:
pass
tr... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
t = input().split()
x = {int(i): (0) for i in t}
result = 0
for i in range(1, n + 1):
a = int(t[i - 1])
x[a] += 1
result += a * (2 * i - n - 1)
if a + 1 in x:
result += x[a + 1]
if a - 1 in x:
result -= x[a - 1]
print(result) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR NUM... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
line = list(map(int, input().split()))
m = dict()
ans = 0
for i in range(n):
if line[i] not in m:
m[line[i]] = 1
else:
m[line[i]] += 1
var = m[line[i]]
if line[i] - 1 in m:
var += m[line[i] - 1]
if line[i] + 1 in m:
var += m[line[i] + 1]
ans += (i... | 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 IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(i) for i in input().split()]
finish = {}
for i in range(n):
finish[a[i]] = 0
result = 0
for i in range(n - 1, -1, -1):
result += (i * 2 + 1 - n) * a[i]
if a[i] - 1 in finish.keys():
result += finish[a[i] - 1]
if a[i] + 1 in finish.keys():
result -= finish[a[i] +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF BIN_OP VAR VAR NUMB... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = list(map(int, input().split()))
freq = dict()
res = 0
for i in range(n - 1, -1, -1):
freq[arr[i]] = freq.get(arr[i], 0) + 1
tp = -1 * (n - i - 1) * arr[i]
tp += i * arr[i]
tp -= freq.get(arr[i] + 1, 0)
tp += freq.get(arr[i] - 1, 0)
res += tp
print(res) | 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 BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR N... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
keys = list(map(int, input().split()))
dictionary = {}
ans = 0
sum = 0
for i in range(0, n):
key = keys[i]
a = dictionary.get(key - 1)
b = dictionary.get(key)
c = dictionary.get(key + 1)
if a == None:
a = 0
if b == None:
b = 0
if c == None:
c = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NU... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def f(a):
if a not in ma:
ma[a] = 0
mb[a] = 0
n = int(input())
x = list(map(int, input().split()))
ma, mb = dict(), dict()
ans = 0
for i in range(n):
ans += x[i] * i
ans -= x[i] * (n - 1 - i)
f(x[i])
f(x[i] - 1)
ma[x[i]] += 1
for i in range(n):
ans += ma[x[i] - 1] - mb[x[i]... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN 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 VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUM... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def update(fenwick, idx, val, n):
while idx < n:
fenwick[idx] += val
idx += idx & -idx
def get_sum(fenwick, idx):
sum = 0
while idx > 0:
sum += fenwick[idx]
idx -= idx & -idx
return sum
def count_smaller_elements(arr):
temp = arr.copy()
temp.sort()
curr_si... | FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
m = {}
almost_sum = 0
s = list(map(int, input().split()))
sum_all = 0
for i in range(n):
a = s[i]
if a not in m:
m[a] = 1
else:
m[a] += 1
u = 0
if a + 1 in m:
u = m[a + 1]
l = 0
if a - 1 in m:
l = m[a - 1]
almost_sum += a * i - sum_all - l... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
sum = ans = 0
d = {}
for i in range(n)[::-1]:
sum += a[i]
if a[i] in d.keys():
d[a[i]] += 1
else:
d[a[i]] = 1
for j in range(a[i] - 1, a[i] + 2):
if j in d.keys():
ans += (a[i] - j) * d[j]
ans -= a[i] * (n - i)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NU... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | N = int(input())
A = [int(s) for s in input().split()]
D = {}
ans = 0
sm = 0
for i in range(N):
a = A[i]
x = i
y = sm
for b in (a - 1, a, a + 1):
if b in D:
x -= D[b]
y -= b * D[b]
ans += a * x
ans -= y
if a in D:
D[a] += 1
else:
D[a] = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [0] + input().split()
s_i = 0
global mp
mp = {}
for i in range(1, n + 1):
a[i] = int(a[i])
if a[i] not in mp:
mp[a[i]] = 1
else:
mp[a[i]] += 1
s_i += a[i]
ans = 0
for i in range(n, 0, -1):
s_in = (
mp.get(a[i] - 1, 0) * (a[i] - 1)
+ mp.get(a[i], 0... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | a = int(input())
arr = list(map(int, input().split()))
d = dict()
summ = [0]
brr = arr
nd = dict()
mimpp = dict()
mimpn = dict()
for i in arr:
summ.append(i + summ[len(summ) - 1])
if i in d:
d[i] = d[i] + 1
else:
d[i] = 1
for i in range(0, len(brr)):
if brr[i] in nd:
nd[brr[i]] =... | 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 LIST NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBE... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split()]
m1 = {(-1): -1}
m2 = {(-1): -1}
ans = 0
for i in range(n):
x, y, z = 0, 0, 0
if a[i] in m1:
x = m1[a[i]]
if a[i] - 1 in m1:
y = m1[a[i] - 1]
if a[i] + 1 in m1:
z = m1[a[i] + 1]
ans = ans + a[i] * (i - x - y - z)
m1[a[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | dic = {}
n = int(input())
sum1 = 0
a = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
try:
dic[a[i]] += 1
except:
dic[a[i]] = 1
sum1 += a[i] * (-n + 1 + 2 * i)
try:
sum1 -= dic[a[i] + 1]
except:
pass
try:
sum1 += dic[a[i] - 1]
except:
... | ASSIGN VAR DICT 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 BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
ans = 0
memo = dict((a[i], 0) for i in range(n))
for i in range(n):
ans += a[i] * (2 * i - n + 1)
memo[a[i]] += 1
ans -= memo.get(a[i] - 1, 0)
ans += memo.get(a[i] + 1, 0)
print(ans) | 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 ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split(" ")]
def init_map():
mp = {}
for x in a:
mp[x] = mp[x + 1] = mp[x - 1] = 0
return mp
mp = init_map()
result = 0
for m, v in enumerate(a):
result += v * (m - mp[v] - mp[v - 1] - mp[v + 1])
mp[v] += 1
mp = init_map()
for m, v in enumerat... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP B... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
l = list(map(int, input().split()))
f = dict()
s, val, ans = 0, 0, 0
for i in l:
ans += i * (val - f.get(i - 1, 0) - f.get(i + 1, 0) - f.get(i, 0)) - (
s - f.get(i - 1, 0) * (i - 1) - f.get(i + 1, 0) * (i + 1) - f.get(i, 0) * i
)
s += i
val += 1
f[i] = f.get(i, 0) + 1
print(... | 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 VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
m = {}
ans = 0
a = input().split()
for i in range(n):
a[i] = int(a[i])
m[a[i]], m[a[i] - 1], m[a[i] + 1] = 0, 0, 0
ans += a[i] * (2 * i - n + 1)
for i in range(n):
ans += m[a[i] + 1] - m[a[i] - 1]
m[a[i]] += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NU... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
ls = [int(i) for i in input().split()]
fullsum = sum(ls[i] * (-n + 1 + 2 * i) for i in range(n))
numdict = dict()
for num in ls:
if num - 1 in numdict:
fullsum -= numdict[num - 1]
if num + 1 in numdict:
fullsum += numdict[num + 1]
if num in numdict:
numdict[num] += 1... | 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 BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | line = input()
n = int(line)
line = input().rstrip().split(" ")
a = []
for i in range(0, n):
a.append(int(line[i]))
mpa = {}
ans = 0
sum_a = 0
for i in range(0, n):
ans = ans + (a[i] * i - sum_a + (mpa.get(a[i] + 1, 0) - mpa.get(a[i] - 1, 0)))
sum_a = sum_a + a[i]
mpa[a[i]] = mpa.get(a[i], 0) + 1
print(... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
d = {}
a = list(map(int, input().split()))
tot = ans = 0
for i in range(n):
ans += i * a[i] - tot
tot += a[i]
ans += d.get(a[i] + 1, 0) - d.get(a[i] - 1, 0)
d.setdefault(a[i], 0)
d[a[i]] += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FU... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | N = 2 * 10**5 + 3
n = int(input())
A, cnt = list(map(int, input().split(" "))), {}
s, a = 0, 0
for i in range(n - 1, -1, -1):
a += s
if A[i] - 1 in cnt:
a += cnt[A[i] - 1]
if A[i] + 1 in cnt:
a -= cnt[A[i] + 1]
a -= (n - (i + 1)) * A[i]
s += A[i]
if A[i] not in cnt:
cnt[A... | ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = [int(lol) for lol in input().split()]
count = {}
ans = 0
s = 0
i = 0
for lol in arr:
if lol not in count.keys():
count[lol] = 1
else:
count[lol] += 1
ans += i * lol
ans -= s
if lol - 1 in count.keys():
ans -= count[lol - 1]
if lol + 1 in count.keys(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUM... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | pre = 0
ans = 0
n = int(input())
ain = input()
arr = ain.split(" ")
m = {}
for i in range(n):
a = int(arr[i])
ans += i * a - pre
if a - 1 in m and m[a - 1] > 0:
ans -= m[a - 1]
if a + 1 in m and m[a + 1] > 0:
ans -= m[a + 1] * -1
pre += a
if a in m:
m[a] += 1
else:
... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER IF ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
s = 0
ans = 0
l = input().split(" ")
mp = {}
for i in range(0, n):
l[i] = int(l[i])
f = i * l[i]
f += mp.get(l[i] + 1, 0)
f -= mp.get(l[i] - 1, 0)
ans += f - s
s += l[i]
temp = mp.get(l[i], 0)
mp[l[i]] = temp + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
l = list(map(int, input().split()))
total = 0
for i in range(n - 1, -1, -1):
total = total + i * l[i]
for i in range(0, n):
total = total - (n - i - 1) * l[i]
d = {}
for i in range(len(l)):
d[l[i]] = 0
d[l[i] + 1] = 0
d[l[i] - 1] = 0
for i in range(0, n):
if i == 0:
d[l[... | 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR AS... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = input()
mp = list(map(int, input().split()))
sum = 0
ans = 0
cnt = 0
tt = dict()
for i in mp:
sum += i
cnt = cnt + 1
ans += cnt * i - sum
if i - 1 in tt:
ans -= tt[i - 1]
if i + 1 in tt:
ans += tt[i + 1]
if i not in tt:
tt[i] = 0
tt[i] = tt[i] + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBE... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = {}
ans = 0
sum = 0
i = 0
for t in map(int, input().split()):
sum += t
a[t] = a.get(t, 0) + 1
ans += (i - a.get(t, 0) - a.get(t - 1, 0) - a.get(t + 1, 0) + 1) * t - (
sum - a.get(t, 0) * t - a.get(t - 1, 0) * (t - 1) - a.get(t + 1, 0) * (t + 1)
)
i += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
ans = 0
sum = 0
mp = {}
c = []
c = list(map(int, input().split()))
for i in range(0, n):
tmp = c[i]
z1 = 0
z2 = 0
if tmp - 1 in mp:
z1 = mp[tmp - 1]
if tmp + 1 in mp:
z2 = mp[tmp + 1]
ans += tmp * i - sum - z1 + z2
if tmp in mp:
mp[tmp] += 1
else:... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | cnt = {}
ans = 0
n = int(input())
inp = [int(i) for i in input().split()]
sum = 0
for i in range(n):
x = inp[i]
if x not in cnt.keys():
cnt[x] = 0
if x - 1 not in cnt.keys():
cnt[x - 1] = 0
if x + 1 not in cnt.keys():
cnt[x + 1] = 0
minus = cnt[x - 1] * (x - 1) + cnt[x + 1] *... | ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | N = int(input())
s = list(map(int, input().split()))
M = {}
ans = 0
j = 1 - N
for i in s:
M[i] = M.get(i, 0) + 1
ans += j * i
j += 2
for i in s:
ans += M.get(i - 1, 0)
ans -= M.get(i + 1, 0)
M[i] = M.get(i, 0) - 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
soujanya = {}
sum = 0
k = input().split()
a = {}
for j in range(n):
i = j + 1
a[i] = int(k[j])
sum += a[i]
if a[i] in soujanya.keys():
soujanya[a[i]] += 1
else:
soujanya[a[i]] = 1
counter = n
ans = 0
for j in range(n):
i = j + 1
temp = counter
if a[i] - 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = list(map(int, input().split()))
n -= 1
ans = 0
for num in arr:
ans += n * num
n -= 2
ans = -ans
dic = {num: (0) for num in arr}
for i in range(len(arr)):
dic[arr[i]] += 1
if arr[i] - 1 in dic:
ans -= dic[arr[i] - 1]
if arr[i] + 1 in dic:
ans += dic[arr[i] + 1]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR BI... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
d = dict()
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(n):
ans = ans + i * a[i] - s
if d.get(a[i] - 1):
ans -= d[a[i] - 1]
if d.get(a[i] + 1):
ans += d[a[i] + 1]
if d.get(a[i]):
d[a[i]] += 1
else:
d[a[i]] = 1
s += a[i]
print(a... | 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF FUN... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def query(l, r):
return s[r] - s[l - 1]
n = int(input())
a = [0] + [int(i) for i in input().split()]
s = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
s[i] = s[i - 1] + a[i]
ans = 0
m = {}
for i in range(n, 0, -1):
ans += query(i + 1, n) - (n - i) * a[i]
if a[i] + 1 in m:
ans -= m[a[i]... | FUNC_DEF RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = input().split(" ")
ans = 0
kk = 0
kol = dict()
for i in range(n - 1, -1, -1):
a[i] = int(a[i])
kk += a[i]
kol[a[i]] = 1 + kol.get(a[i], 0)
plus = kk - (n - i) * a[i]
plus += kol.get(a[i] - 1, 0)
plus -= kol.get(a[i] + 1, 0)
ans += plus
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BI... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split()]
ans = 0
d = {}
for i in range(n):
ans += a[i] * i
ans -= a[i] * (n - i - 1)
if a[i] not in d:
d[a[i]] = 1
else:
d[a[i]] += 1
if a[i] - 1 in d:
ans -= d[a[i] - 1]
if a[i] + 1 in d:
ans += d[a[i] + 1]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | input()
a = 0
b = 0
c = 0
d = dict()
e = dict()
for i in list(map(int, input().split())):
x, y = 0, 0
for j in range(i - 1, i + 2):
if j in d:
x += d[j]
y += e[j]
a += (c - y) * i - b + x
b += i
c += 1
d[i] = i if i not in d else d[i] + i
e[i] = 1 if i not in ... | EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = map(int, input().split())
mp = {}
s = 0
ans = 0
i = 0
for x in a:
i += 1
s += x
if x not in mp:
mp[x] = 0
if x + 1 not in mp:
mp[x + 1] = 0
if x - 1 not in mp:
mp[x - 1] = 0
mp[x] += 1
adj = mp[x] + mp[x + 1] + mp[x - 1]
c = s
c -= mp[x] *... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | input()
ans = 0
sum = 0
i = 0
d = dict()
arr = list(map(int, input().split()))
for cur in arr:
d[cur] = 0
d[cur - 1] = 0
d[cur + 1] = 0
for cur in arr:
ans += i * cur - sum + d[cur + 1] - d[cur - 1]
d[cur] += 1
i += 1
sum += cur
print(ans) | EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split()]
l = {}
s = 0
for i in range(n):
x = a[i]
if l.get(x, "none") == "none":
l[x] = 1
else:
l[x] = l[x] + 1
s += i * x - (n - 1 - i) * x
if l.get(x + 1, "none") != "none":
s += l[x + 1]
if l.get(x - 1, "none") != "none":
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR STRING STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
arr = list(map(int, input().split()))
arr_sum = sum(arr)
cnt = {}
for val in arr:
try:
cnt[val] += 1
except:
cnt[val] = 1
res = 0
for i in range(n - 1, -1, -1):
arr_sum -= arr[i]
cnt[arr[i]] -= 1
res += i * arr[i] - arr_sum
if arr[i] + 1 in cnt.keys():
re... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n, a, ft = 0, [(0, 0)], [0]
def query(k):
res = 0
while k > 0:
res += ft[k]
k -= k & -k
return res
def adjust(k, v):
while k <= n:
ft[k] += v
k += k & -k
def rquery(l, r):
if l > r:
return 0
return query(r) - (0 if l == 1 else query(l - 1))
n, ans ... | ASSIGN VAR VAR VAR NUMBER LIST NUMBER NUMBER LIST NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
xd = input().split()
a = [0]
for s in xd:
a.append(int(s))
b = [0] * (n + 1)
for i in range(1, n + 1):
b[i] = b[i - 1] + a[i]
sol = 0
mp = {}
def mpg(x):
if x in mp:
return mp[x]
else:
return 0
for i in range(1, n + 1):
x = a[i]
mp[x] = mpg(x) + 1
sol += ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = input().split()
an = 0
sum = int(a[n - 1])
cnt = {}
for x in range(n):
cnt[int(a[x])] = 0
cnt[int(a[x]) + 1] = 0
cnt[int(a[x]) - 1] = 0
cnt[int(a[n - 1])] = 1
x = n - 2
while x >= 0:
rsum = sum - (
cnt[int(a[x])] * int(a[x])
+ cnt[int(a[x]) + 1] * (int(a[x]) + 1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBE... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split(" ")))
x = 0
for i in range(int(n / 2)):
j = n - 1 - i
x += (a[j] - a[i]) * (j - i)
m = {}
for i in range(n):
if a[i] in m:
m[a[i]] += 1
else:
m[a[i]] = 1
if a[i] + 1 in m:
x += m[a[i] + 1]
if a[i] - 1 in m:
x -= m[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
cnt = 0
m = dict()
s = 0
ans = 0
for i in a:
m[i] = 0
m[i - 1] = 0
m[i + 1] = 0
for i in range(n - 1, -1, -1):
ans += s - cnt * a[i]
for j in range(-1, 2):
ans -= m[a[i] + j] * (a[i] + j - a[i])
s += a[i]
m[a[i]] += 1
cnt += 1
... | 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input().strip())
arr = [int(i) for i in input().strip().split(" ")]
dic = {arr[0]: 1}
ic = [(0) for i in range(n)]
isu = [(0) for i in range(n)]
pre = [arr[0]]
for i in range(1, n):
pre.append(pre[i - 1] + arr[i])
for i in range(1, n):
ici, isi = 0, 0
if arr[i] in dic:
ici += dic[arr[i]]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split()]
d = 0
for i in range(n):
d += -1 * a[i] * (n - i - 1)
d += a[i] * i
di = {}
for i in range(n):
if a[i] not in di:
di[a[i]] = 0
if a[i] - 1 in di:
d -= di[a[i] - 1]
if a[i] + 1 in di:
d += di[a[i] + 1]
di[a[i]] += 1
pr... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF BIN_OP VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | map = dict()
sum = 0
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i, a in enumerate(a):
ans += i * a
ans -= sum
if a - 1 in map:
ans -= map[a - 1]
if a + 1 in map:
ans += map[a + 1]
sum += a
if a in map:
map[a] += 1
else:
map[a] = 1
print... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
t = sum((i + 1) * ai for i, ai in enumerate(a))
p = 2 * t - (n + 1) * s
q = 0
r = 0
freqs = {}
for y in a:
q += freqs.get(y - 1, 0)
r += freqs.get(y + 1, 0)
freqs[y] = 1 + freqs.get(y, 0)
print(p - q + r) | 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 VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DIC... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | sequence_dict = {}
sum = 0
number_of_elements = int(input())
sequence = list(map(int, input().split()))
for index, element in enumerate(sequence):
sum += (
index * element
- (number_of_elements - 1 - index) * element
- sequence_dict.get(element - 1, 0)
+ sequence_dict.get(element + 1... | ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | m = {}
A = [0] * 200001
B = []
sum1 = 0
ans = 0
n = int(input())
B = input().split(" ")
for i in range(n):
A[i] = int(B[i])
sum1 += A[i]
if A[i] in m:
m[A[i]] += 1
else:
m[A[i]] = 1
np = n
for i in range(n):
if A[i] in m:
a1 = m[A[i]]
else:
a1 = 0
if A[i] + 1 ... | ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def bnyk(x):
if x in freq.keys():
return freq[x]
else:
return 0
freq = {}
n = int(input())
list = input().split()
ans = 0
ttl = 0
for i in range(n):
x = int(list[i])
a = bnyk(x - 1)
b = bnyk(x)
c = bnyk(x + 1)
ans += x * (i - a - b - c) - (ttl - (x - 1) * a - x * b - (x + 1... | FUNC_DEF IF VAR FUNC_CALL VAR RETURN VAR VAR RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSI... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
tot = 0
ans = 0
cnt = {}
a = list(map(int, input().split()))
for i in range(1, n + 1):
x = a[i - 1]
ans += (i - 1) * x - tot
if x - 1 in cnt:
ans -= cnt[x - 1]
if x + 1 in cnt:
ans += cnt[x + 1]
if x in cnt:
cnt[x] += 1
else:
cnt[x] = 1
tot +=... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_O... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
d = dict()
s = 0
ans = 0
for elem in a:
if d.get(elem) == None:
d[elem] = 0
d[elem] += 1
s += elem
for i in range(n):
cur = a[i]
d[cur] -= 1
s -= cur
cnt = n - i - 1
if d.get(cur - 1) == None:
cnt1 = 0
else:
... | 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 NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR AS... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def get_s_in(i):
global mp
res = 0
if a[i] - 1 in mp:
res += mp[a[i] - 1] * (a[i] - 1)
if a[i] in mp:
res += mp[a[i]] * a[i]
if a[i] + 1 in mp:
res += mp[a[i] + 1] * (a[i] + 1)
return res
def get_cnt_in(i):
global mp
res = 0
if a[i] - 1 in mp:
res +=... | FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | tmp = input()
ans = 0
arr = [int(x) for x in input().split(" ")]
n = len(arr)
m = {}
sum = 0
for i in range(0, n):
m[arr[i]] = m.get(arr[i], 0) + 1
sum += arr[i]
for i in range(0, n):
m[arr[i]] = m.get(arr[i], 0) - 1
sum -= arr[i]
c1 = m.get(arr[i] - 1, 0)
c2 = m.get(arr[i], 0)
c3 = m.get(ar... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
mm = dict()
S = [0] * 200001
for i in range(n):
if i > 0:
S[i] = S[i - 1] + a[i]
if a[i] not in mm:
mm[a[i]] = 1
else:
mm[a[i]] += 1
ans = 0
for i in range(n):
if i > 0:
ans += -a[i] * (n - 1 - i) + S[n - 1] - S[i]
... | 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 BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | trash = int(input())
numbers = input().split(" ", trash)
for i in range(trash):
numbers[i] = int(numbers[i])
dict = {}
for i in range(trash):
dict[numbers[i]] = 0
dict[numbers[i] - 1] = 0
dict[numbers[i] + 1] = 0
res = 0
fncount = numbers[0]
dict[numbers[0]] = 1
for i in range(1, trash):
dict[number... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
A = [int(i) for i in input().split()]
acc = 0
res = 0
for i in range(len(A)):
acc -= A[i]
res += acc + A[i] * (i + 1)
mp = dict()
for i in range(len(A)):
mp[A[i]] = mp.get(A[i], 0) + 1
res -= mp.get(A[i] - 1, 0) - mp.get(A[i] + 1, 0)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
s = input().split()
a = [int(x) for x in s]
p = [(0) for i in range(len(a) + 1)]
m = {}
def get(ai):
if ai in m:
return m[ai]
return 0
i = 0
for ai in a:
p[i + 1] = p[i] + ai
if ai in m:
m[ai] += 1
else:
m[ai] = 1
i += 1
i = n - 1
ans = 0
for ai in re... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
list1 = list(map(int, input().split()))
x = 0
ans = 0
dic = {}
list2 = []
for i in range(n):
list2.append(x)
x += list1[n - 1 - i]
dic[list1[i]] = dic.get(list1[i], 0) + 1
list2.reverse()
for i in range(n):
ans += list2[i] - (n - 1 - i) * list1[i]
ans -= dic.get(list1[i] + 1, 0)
... | 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 ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBE... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
m = dict()
s = 0
ans = 0
cnt = 0
for i in range(n):
mp = m.get(a[i] + 1, 0)
mm = m.get(a[i] - 1, 0)
ans += cnt * a[i] - s + mp - mm
m.update({a[i]: m.get(a[i], 0) + 1})
s += a[i]
cnt += 1
print(ans) | 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
s = 0
ans = 0
for i in range(0, n):
ans += a[i] * i - s
s += a[i]
d = {}
for i in range(0, n):
if a[i] + 1 in d:
ans += d[a[i] + 1]
if a[i] - 1 in d:
ans -= d[a[i] - 1]
if not a[i] in d:
d[a[i]] = 0
d[a[i]] += 1
print(a... | 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VA... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
t = [int(x) for x in input().split()]
ans = 0
d = {}
for i in range(n):
ans += (-(n - 1) + 2 * i) * t[i]
for i in range(n):
if t[i] - 1 in d:
ans -= d[t[i] - 1]
if t[i] + 1 in d:
ans += d[t[i] + 1]
if t[i] in d:
d[t[i]] += 1
else:
d[t[i]] = 1
print(an... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
cnt = {}
res = 0
s = 0
a = list(map(int, input().split()))
for i in range(n):
x = a[i]
s += x
cnt[x] = cnt.get(x, 0) + 1
res += x * (i + 1 - (cnt.get(x, 0) + cnt.get(x - 1, 0) + cnt.get(x + 1, 0))) - (
s
- (
x * cnt.get(x, 0)
+ (x - 1) * cnt.get(x... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER BIN_OP B... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
ps = [a[0]] * n
for i in range(1, n):
ps[i] = a[i] + ps[i - 1]
cnt = dict()
ans = 0
cnt[a[0]] = 1
for i in range(1, n):
ans += a[i] * i
ans -= ps[i - 1]
if a[i] - 1 not in cnt:
cnt[a[i] - 1] = 0
ans -= cnt[a[i] - 1]
if a[i] + 1 not in ... | 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 VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(0, n):
dic[a[i]] = 0
dic[a[i] - 1] = 0
dic[a[i] + 1] = 0
ans = 0
summ = 0
for i in range(0, n):
ans += i * a[i] - summ
ans -= dic[a[i] - 1]
ans += dic[a[i] + 1]
summ += a[i]
dic[a[i]] += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR N... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | def set(x):
if x not in m:
m[x] = 0
n = int(input())
a = list(map(int, input().split()))
m = {}
ans, total = 0, 0
for i in range(0, n):
x = a[i]
set(x), set(x - 1), set(x + 1)
ans = ans + (i - m[x] - m[x - 1] - m[x + 1]) * x
ans = ans - (total - m[x] * x - m[x - 1] * (x - 1) - m[x + 1] * (... | FUNC_DEF IF VAR VAR ASSIGN 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 DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
a = list(map(int, input().split()))
cnt = {}
ans = 0
sm = 0
i = n - 1
while i >= 0:
if i != n - 1:
ans = ans + sm - a[i] * (n - i - 1)
if a[i] - 1 in cnt:
ans = ans + cnt[a[i] - 1]
if a[i] + 1 in cnt:
ans = ans - cnt[a[i] + 1]
sm = sm + a[i]
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR ... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | from itertools import accumulate
def cald(left, right):
i = 0
j = 0
ans = 0
l1 = len(left)
l2 = len(right)
while j < len(right):
while i < l1 and left[i] < right[j]:
i += 1
ans += l1 - 2 * i
j += 1
return ans
n = int(input())
a = list(map(int, input().... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | import sys
n = int(input())
a = list(map(int, input().split()))
cnt = dict()
ans = 0
for i in range(n):
ans += i * a[i]
ans -= (n - 1 - i) * a[i]
cnt[a[i]] = 0
for i in range(n):
if a[i] - 1 in cnt:
ans -= cnt[a[i] - 1]
if a[i] + 1 in cnt:
ans += cnt[a[i] + 1]
cnt[a[i]] += 1
pri... | IMPORT 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 VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR V... |
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over all pairs (i, j) such that 1 ≤ i ≤ j ≤ n.
-----Input-----
The ... | n = int(input())
sum = 0
res = 0
cnt = dict()
a = list(map(int, input().split()))
for i in range(n):
sub = 0
num = 0
for j in range(-1, 2, 1):
if a[i] + j in cnt:
sub += (a[i] + j) * cnt[a[i] + j]
num += cnt[a[i] + j]
res += (i - num) * a[i] - (sum - sub)
sum += a[i]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.