Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
q=int(input())
dp=[0]*(10**5+1)
for i in range(1,10**5+1):
  dp[i]=a.count(i)

for j in range(q):
  b,c=map(int,input().split())
  ans+=(c-b)*dp[b]
  dp[c]+=dp[b]
  dp[b]=0
  print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
q=int(input())
dp=[0]*(10**5+1)
for i in a:
  dp[i]+=1

for j in range(q):
  b,c=map(int,input().split())
  ans+=(c-b)*dp[b]
  dp[c]+=dp[b]
  dp[b]=0
  print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
count = 0
while a != []:
    t = a[0]
    if len(a) == 1:
        count +=1
    elif a[0] != a[1]:
        count +=1
    a = [i for i in a if i % t != 0]
    

print(count)


### FIXED CODE ###

#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    n=int(input())
    A=list(map(int, input().split()))
    counts=[0]*(10**6+5)
    for AA in A:
        counts[AA]+=1
    ans=0
    for i in range(1,10**6+5):
        if counts[i]>0:
            for j in range(i+i,10**6+5,i):
                counts[j]=-1
        if counts[i]==1:
            ans+=1
    print(ans)
        

        
    


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for i, (ai, bi) in enumerate(ab):
    graph[ai - 1].append(bi)
    graph[bi - 1].append(ai)

# print("#", graph)

cnttab = [0] * N
for j, (pj, xj) in enumerate(px):
    cnttab[pj - 1] += xj

# print("#", cnttab)

ans = [None] * N
ans[0] = cnttab[0]
from collections import deque
q = deque([(1, None, ans[0])])
while len(q) > 0:
    src, prev, score = q.popleft()
    for dst in graph[src - 1]:
        if dst == prev: continue
        ans[dst - 1] = score + cnttab[dst - 1]
        q.append((dst, src, ans[dst - 1]))

print(' '.join(map(str, ans)))


### FIXED CODE ###

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N)]
for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

parent = [None] * N
parent[0] = 0

score = [0] * N
for pi, xi in px:
    score[pi - 1] += xi

ans = [None] * N

from collections import deque

q = deque([(0, 0)])
while len(q) > 0:
    src, score_tmp = q.popleft()
    score_tmp += score[src]
    ans[src] = score_tmp
    for dst in graph[src]:
        if ans[dst] != None: continue
        q.append((dst, score_tmp))

print(' '.join(map(str, ans)))
### BUGGY CODE ###

n = int(input())
A = [int(i) for i in input().split()]
work = 1
for a in A:
    work *= a
if work > 10**18:
    print(-1)
else:
    print(work)

### FIXED CODE ###

n = int(input())
A = [int(i) for i in input().split()]
check = [i for i in A if i == 0]
if 0 in check:
    print(0)
else:   
    A.sort(reverse=True)
    work = 1
    for a in A:
        work *= a
        if work > 10**18:
            print('-1')
            break
    else:
        print(work)
### BUGGY CODE ###

def resolve():
    from collections import defaultdict
    s = input()
    n = len(s)
    d = defaultdict(int)
    d[0] += 1
    for i in range(1, n + 1):
        d[int(s[-i:]) % 2019] += 1

    def calc(x): return x * (x - 1) // 2
    ans = 0
    for v in d.values():
        ans += calc(v)
    print(ans)


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

def resolve():
    from collections import defaultdict
    s = input()
    n = len(s)
    d = defaultdict(int)
    d[0] += 1
    j = 0
    for i in range(1, n + 1):
        j += int(s[-i]) * pow(10, i - 1, 2019)
        j %= 2019
        d[j] += 1

    def calc(x): return x * (x - 1) // 2
    ans = 0
    for v in d.values():
        ans += calc(v)
    print(ans)


if __name__ == '__main__':
    resolve()
### BUGGY CODE ###

import math

n,m = map(int,input().split())
a = list(map(int,input().split()))

a = sorted(a)

for i in range(m):
    p = a.pop()
    p = math.floor(p/2)
    a.append(p)
    a = sorted(a)

print(sum(a))

### FIXED CODE ###

from heapq import heappop,heappush,heapify
import math

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x:-x,a))

heapify(a)

for i in range(m):
    p = heappop(a)
    heappush(a,math.ceil(p/2))

ans = 0
for _ in range(n):
    p = heappop(a)
    ans += -p

print(ans)
### BUGGY CODE ###

def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
    tasks = [[0] for _ in range(max(B) + 1)]
    for i in range(N):
        tasks[B[i]].append(A[i])
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0:
            continue
        time += sum(task)
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    N = int(input())
    flag = True
    tascs = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        tmp = [a, b]
        tascs.append(tuple(tmp))
    tascs.sort(key=lambda x: x[1])
    passed_time = 0
    for tasc in tascs:
        passed_time += tasc[0]
        if passed_time > tasc[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import Counter
from itertools import combinations
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = [a+i for i, a in enumerate(A, 1)]
C = [i-a for i, a in enumerate(A, 1)]
ans = 0
for k1, v1 in Counter(B).items():
    for k2, v2 in Counter(C).items():
        if k1 == k2:
            ans += v1*v2
print(ans)

### FIXED CODE ###

from collections import Counter
inputs = open(0).readlines()
n = int(inputs[0])
*A, = (map(int, inputs[1].split()))
B = Counter([a+i for i, a in enumerate(A, 1)])
C = Counter([i-a for i, a in enumerate(A, 1)])
ans = 0
for k, v in B.items():
    if k in C:
        ans += C[k]*v
print(ans)
### BUGGY CODE ###


def main():
    import sys
    import time
    input = sys.stdin.buffer.readline
    start = time.time()
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    M = (N*(N-1)) // 2

    while(min_id < N-1):
        now = time.time()
        if now - start > 2:
            ans = M+1
            break
        ans += 1
        if ans > M:
            break
        tmp = set()
        for i in range(N):
            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > M:
        print(-1)
    else:
        print(ans)


main()


### FIXED CODE ###

def main():
    import sys
    import time
    input = sys.stdin.buffer.readline
    start = time.time()
    N = int(input())
    A = [tuple(map(int, input().split())) for i in range(N)]

    id = [0]*N
    Lock = [-1]*N
    ans = 0
    min_id = 0
    M = (N*(N-1)) // 2

    while(min_id < N-1):
        now = time.time()
        if now - start > 1.9:
            ans = M
            break
        ans += 1
        if ans > M:
            break
        tmp = set()
        for i in range(N):
            if id[i] >= N-1:
                continue
            else:
                if Lock[i] >= 0:
                    continue
                else:
                    a = A[i][id[i]]
                    if Lock[a-1] == i and i not in tmp:
                        Lock[a-1] = -1
                        id[a-1] += 1
                        tmp.add(a-1)
                        id[i] += 1
                    else:
                        if i not in tmp:
                            Lock[i] = A[i][id[i]]-1
        min_id = min(id)
    if ans > M:
        print(-1)
    else:
        print(ans)


main()
### BUGGY CODE ###

def solve(string):
    s = string.replace("?", "d").lower()
    n = len(s)
    dp = [[0] * (n + 1) for _ in range(4)]
    dp[0][0] = 1
    for i, _s in enumerate(s):
        dp[0][i + 1] = dp[0][i]
        dp[1][i + 1] = dp[1][i]
        dp[2][i + 1] = dp[2][i]
        dp[3][i + 1] = dp[3][i]
        if _s == "a":
            dp[1][i + 1] += dp[0][i]
        if _s == "b":
            dp[2][i + 1] += dp[1][i]
        if _s == "c":
            dp[3][i + 1] += dp[2][i]
        if _s == "d":
            dp[0][i + 1] *= 3
            dp[1][i + 1] *= 3
            dp[1][i + 1] += dp[0][i]
            dp[2][i + 1] *= 3
            dp[2][i + 1] += dp[1][i]
            dp[3][i + 1] *= 3
            dp[3][i + 1] += dp[2][i]
    return str(int(dp[3][-1] % (10**9 + 7)))


if __name__ == '__main__':
    print(solve(input()))


### FIXED CODE ###

def solve(string):
    s = string.replace("?", "d").lower()
    n = len(s)
    dp = [[0] * (n + 1) for _ in range(4)]
    dp[0][0] = 1
    mod = 10**9 + 7
    for i, _s in enumerate(s):
        dp[0][i + 1] = dp[0][i] % mod
        dp[1][i + 1] = dp[1][i] % mod
        dp[2][i + 1] = dp[2][i] % mod
        dp[3][i + 1] = dp[3][i] % mod
        if _s == "a":
            dp[1][i + 1] += dp[0][i]
        if _s == "b":
            dp[2][i + 1] += dp[1][i]
        if _s == "c":
            dp[3][i + 1] += dp[2][i]
        if _s == "d":
            dp[0][i + 1] *= 3
            dp[1][i + 1] *= 3
            dp[1][i + 1] += dp[0][i]
            dp[2][i + 1] *= 3
            dp[2][i + 1] += dp[1][i]
            dp[3][i + 1] *= 3
            dp[3][i + 1] += dp[2][i]
    return str(int(dp[3][-1] % (10**9 + 7)))


if __name__ == '__main__':
    print(solve(input()))
### BUGGY CODE ###

MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)

### FIXED CODE ###

MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [list(map(int,input().split())) for _ in range(H)]
D = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]
dp = [[{} for _ in range(W)] for _ in range(H)]
dp[0][0][D[0][0]] = 0
for h in range(H):
    for w in range(W):
        if 0 < h:
            for v in dp[h-1][w]:
                v1 = v+D[h][w]
                v2 = v-D[h][w] if v>=D[h][w] else -v+D[h][w]
                dp[h][w][v1] = 0
                dp[h][w][v2] = 0
        if 0 < w:
            for v in dp[h][w-1]:
                v1 = v+D[h][w]
                v2 = v-D[h][w] if v>=D[h][w] else -v+D[h][w]
                dp[h][w][v1] = 0
                dp[h][w][v2] = 0
                
ans = min(dp[H-1][W-1])
print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [list(map(int,input().split())) for _ in range(H)]
D = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]
def cal():
    dp1 = [set() for _ in range(W)]
    dp2 = [set() for _ in range(W)]
    for h in range(H):
        for w in range(W):
            d = D[h][w]
            if h==0 and w==0:
                dp2[0].add(d)
            for v in dp1[w]:
                v1 = v+d
                v2 = v-d if v>=d else -v+d
                dp2[w].add(v1)
                dp2[w].add(v2)
            if 0 < w:
                for v in dp2[w-1]:
                    v1 = v+d
                    v2 = v-d if v>=d else -v+d
                    dp2[w].add(v1)
                    dp2[w].add(v2)
        dp1 = dp2
        dp2 = [set() for _ in range(W)]
    return min(dp1[W-1])
ans = cal()
print(ans)
### BUGGY CODE ###

X, Y = map(int, input().split())

flag = 1 

for i in range(2**X):
        y = 0 
        for j in range(X):
                if ((i >> j) & 1): 
                        y += 4
                else:
                        y += 2    
        if y == Y:
                print("Yes")
                flag = -1
                break

if flag == 1:
        print("No")

### FIXED CODE ###

X, Y = map(int, input().split())

if Y % 2 == 0 and X * 2 <= Y and Y <= X * 4:
        print("Yes")
else:
        print("No")
### BUGGY CODE ###

from itertools import accumulate

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

current_arr = A
for k in range(K):
    if k > 41:
        break
    imos = [0] * N
    ruiseki = [0] * (N+1)
    for i, ai in enumerate(current_arr):
        imos[max([0, i-ai])] += 1
        if i+ai+1 < N:
            imos[i+ai+1] -= 1
    for j, im in enumerate(imos):
        ruiseki[j+1] = ruiseki[j] + im
    current_arr = ruiseki[1:]
#print(imos)
#print(ruiseki)
#print(*accumulate(imos))
print(*current_arr)


### FIXED CODE ###

import sys
from itertools import accumulate

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

current_arr = A
if K > 41:
    print(*([N]*N))
else:
    for _ in range(K):
        imos = [0] * N
        ruiseki = [0] * (N+1)
        for i, ai in enumerate(current_arr):
            imos[max([0, i-ai])] += 1
            if i+ai+1 < N:
                imos[i+ai+1] -= 1
        for j, im in enumerate(imos):
            ruiseki[j+1] = ruiseki[j] + im
        current_arr = ruiseki[1:]
#print(imos)
#print(ruiseki)
#print(*accumulate(imos))
    print(*current_arr)
### BUGGY CODE ###

import sys
import bisect
import math
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

B = [(A[i]*F[i], F[i]) for i in range(N)]
B.sort(reverse=True)
L = 0
R = B[0][0]
if sum(A) <= K:
    print(0)
    exit(0)
while(1):
    ans = (L+R) // 2
    flag = True
    tmp = 0
    for i in range(N):
        tmp += math.ceil(max(B[i][0] - ans, 0) / B[i][1])
        if tmp > K:
            flag = False
            break
    if flag:
        R = ans
    else:
        L = ans
    if L == R or L+1 == R:
        print(R)
        break


### FIXED CODE ###

import sys
import bisect
import math
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

B = [(A[i]*F[i], F[i]) for i in range(N)]
B.sort(reverse=True)
L = 0
R = B[0][0]
if sum(A) <= K:
    print(0)
    exit(0)
while(1):
    ans = (L+R) // 2
    flag = True
    tmp = 0
    for i in range(N):
        tmp += math.ceil(max(B[i][0] - ans, 0) / B[i][1])
        if tmp > K:
            flag = False
            break
    if flag:
        R = ans
    else:
        L = ans
    if L == R or L+1 == R:
        print(R)
        break
### BUGGY CODE ###

def main():
    _ = int(input())
    m = 10 ** 18
    x = 1
    for i in map(int, input().split()):
        x *= i
    print(-1 if m < x else x)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    _ = input()
    a = sorted(list(map(int, input().split())), reverse=True)
    if a[-1] == 0:
        print(0)
        return
    x = 1
    m = 10 ** 18
    for i in a:
        if i < 2:
            continue
        x *= i
        if x > m:
            print(-1)
            return
    print(-1 if x > 10 ** 18 else x)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import defaultdict
import math


def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
al = list(map(str, input().split()))
d = defaultdict(lambda: 0)
dd = defaultdict(lambda: 0)
for a in al:
    d[a] += 1

sam = 0
for key, value in d.items():
    dd[key] = combinations_count(value, 2)
    sam += dd[key]
# print(d)
# print(dd)
# print(sam)
for a in al:
    value = d[a]
    print(sam - dd[a] + combinations_count(value-1, 2))


### FIXED CODE ###

from collections import defaultdict
import math


def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n = int(input())
al = list(map(str, input().split()))
d = defaultdict(lambda: 0)
dd = defaultdict(lambda: 0)
dd_1 = defaultdict(lambda: 0)
for a in al:
    d[a] += 1

sam = 0
for key, value in d.items():
    dd[key] = combinations_count(value, 2)
    dd_1[key] = combinations_count(value-1, 2)
    sam += dd[key]
# print(d)
# print(dd)
# print(sam)
for a in al:
    value = d[a]
    print(sam - dd[a] + dd_1[a])
### BUGGY CODE ###

n,m,x,y = map(int,input().split())
xl = list(map(int,input().split()))
yl = list(map(int,input().split()))
xl.sort(reverse = True)
yl.sort()

if xl[0] < yl[0]:
    p = yl[0]
    while p > x:
        if x < p and p <= y:
            print('No War')
            exit(0)
    print('War')
else:
    print('War')

### FIXED CODE ###

n,m,x,y = map(int,input().split())
xl = list(map(int,input().split()))
yl = list(map(int,input().split()))
xl.append(x)
yl.append(y)
xl.sort()
yl.sort()

if xl[-1] < yl[0]:
    print('No War')
else:
    print('War')
### BUGGY CODE ###

import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def gcd(a, b):
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


MOD = 10**9 + 7

n = ri()
ls = ril()
if n == 1:
    print(1)
    exit()

x = ls[0]
for i in range(1, n):
    x = lcm(x, ls[i])
ds = [x // y for y in ls]
print(sum(ds) % MOD)

### FIXED CODE ###

import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


def gcd(a, b):
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


MOD = 10**9 + 7

n = ri()
ls = ril()
if n == 1:
    print(1)
    exit()

x = ls[0]
for i in range(1, n):
    x = lcm(x, ls[i])
ds = [x // y for y in ls]
print(sum(ds) % MOD)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
cnt = [0, 0, 0, 0]
for x in a:
    cnt[x] += 1
p, q, r = cnt[1], cnt[2], cnt[3]

dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n+1)]

for k in range(r + 1):
    for j in range(r + q + 1):
        for i in range(n + 1):
            if not (0 < i + j + k <= n):
                continue
            tmp = 0
            if i > 0:
                tmp += dp[i - 1][j][k] * i
            if j > 0:
                tmp += dp[i + 1][j - 1][k] * j
            if k > 0:
                tmp += dp[i][j + 1][k - 1] * k
            tmp += n
            dp[i][j][k] = tmp / (i + j + k)

print(dp[p][q][r])


### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N = NI()
a = [0,0,0]
for x in LI():
    a[x-1] += 1
dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

for k in range(a[2]+1):
    for j in range(a[1]+a[2]+1):
        for i in range(N+1):
            if not (0 < i+j+k <= N): continue
            x = 0.0
            if i > 0: x += dp[i-1][j][k] * (i/N)
            if j > 0: x += dp[i+1][j-1][k] * (j/N)
            if k > 0: x += dp[i][j+1][k-1] * (k/N)
            x += 1.0
            x *= N / (i+j+k)
            dp[i][j][k] = x
print(dp[a[0]][a[1]][a[2]])
### BUGGY CODE ###

num = int(input())
a = input()
count = 0
for i in range(num):
  if i < num-2:
    if a[i] == "#" and a[i+1] == ".":
      count += 1
      a = a[:i+1] + "#" + a[i+2:]  
  elif i == num-2:
    if a[i] == "#" and a[i+1] == ".":
      count += 1
      a = a[:i+1] + "#"
print(count)

### FIXED CODE ###

n = int(input())
s=input()
if ('.' not in s) or ('#' not in s):
    print(0)
    exit()
bc = [0 for i in range(n)]
wc = [0 for i in range(n)]
for i in range(n):
  if s[i] == '#':
    bc[i] = 1
  else:
    wc[i] = 1
for i in range(n-1):
  bc[i+1] += bc[i]
for i in range(n-1,0,-1):
  wc[i-1] += wc[i]
ans = min(wc[0],bc[-1])
for i in range(n-1):
  ans = min(ans,bc[i]+wc[i+1])
print(ans)
### BUGGY CODE ###

inp=input().split()
n=int(inp[0])
m=int(inp[1])
arr=[]
pares=0
impares=0
count=1
nums=0
while len(arr)<(m+n):
    if count%2==0 and pares<n:
        arr.append(count)
        pares+=1
    elif count%2!=0 and impares<m:
        arr.append(count)
        impares+=1
    count+=1
sums=[]
for x in arr:
   for y in arr:
        if(x+y)%2==0 and [x,y] not in sums and [y,x] not in sums and x!=y:
            nums+=1
            sums.append([x,y])

print(nums)


### FIXED CODE ###

n, m = list(map(int, input().split()))
print(n * (n-1) // 2 + m * (m-1) // 2)
### BUGGY CODE ###

n=int(input())
_list=[0]
for i in range(n):
  _list.append(int(input()))

tmp=1
count=0
while(1):
  tmp=_list[tmp]
  count+=1
  if(tmp==2):
    print(count)
    break
  if(tmp==1):
    print(-1)
    break

### FIXED CODE ###

n=int(input())
_list=[0]
for i in range(n):
  _list.append(int(input()))

tmp=1
count=0
while(1):
  tmp=_list[tmp]
  count+=1
  if(tmp==2):
    print(count)
    break
  if(tmp==1 or n<count):
    print(-1)
    break
### BUGGY CODE ###

import math
n,k=map(int,input().split())
h=list(map(int,input().split()))
s=[0,abs(h[1]-h[0])]
total=10**5
for i in range(2,n):
    total=math.inf
    for j in range(1,k+1):
        if i-j<0:
            break
        total=min(total,abs(h[i]-h[i-j])+s[i-j])
    s.append(total)
print(s[-1])

### FIXED CODE ###

import math
from numba import jit
n,k=map(int,input().split())
h=list(map(int,input().split()))
@jit
def a(N,K,H):
    s=[0]*n
    for i in range(1,N):
        total=math.inf
        for j in range(1,K+1):
            if i-j<0:
                break
            total=min(total,abs(H[i]-H[i-j])+s[i-j])
        s[i]=(total)
    print(s[-1])
a(n,k,h)