status_v0: Accepted

status_v1: Accepted

input:
n = int(input())

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

D = {i: [0] for i in range(1, n+1)}

for i in range(n+1):

  D[a[i]][0] += 1

  D[a[i]].append(i)

pl, pr = 0, 0

for i in D:

  if D[i][0] == 2:

    pl = D[i][1]

    pr = D[i][2]

    break

L = pl

M = pr - pl - 1

N = n - pr

mod = int(1e9) + 7 # <-- input modulo

maxf = n+11          # <-- input factional limitation

def make_fact(n, k):

    tmp = n

    perm = [i for i in range(k)]

    L = [0 for _ in range(k)]

    for i in range(k):

        L[i] = tmp % (i + 1)

        tmp //= i + 1

    LL = [0 for _ in range(k)]

    for i in range(k):

        LL[i] = perm[L[-i-1]]

        for j in range(L[-i-1]+1, k):

            perm[j-1] = perm[j]

    return LL

def doubling(n, m, modulo=mod):

    y = 1

    base = n

    tmp = m

    while tmp != 0:

        if tmp % 2 == 1:

            y *= base

            if modulo > 0:

                y %= modulo

        base *= base

        if modulo > 0:

            base %= modulo

        tmp //= 2

    return y

def inved(a, modulo=mod):

    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo

    while l != 0:

        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)

        k, l = l, k % l

    return x % modulo

fact = [1 for _ in range(maxf+1)]

invf = [1 for _ in range(maxf+1)]

for i in range(maxf):

    fact[i+1] = (fact[i] * (i+1)) % mod

invf[-1] = inved(fact[-1])

for i in range(maxf, 0, -1):

    invf[i-1] = (invf[i] * i) % mod

for i in range(1, n+2):

  S = fact[n]*invf[i-1]*invf[n-i+1]%mod

  if i <= n-1:

    S += fact[n-1]*invf[i]*invf[n-1-i]%mod

    S %= mod

  if i <= n-M:

    S -= fact[n-1-M]*invf[i-1]*invf[n-M-i]%mod

    S %= mod

  if i <= n:

    S += fact[n-1]*invf[i-1]*invf[n-i]%mod

    S %= mod

  print(S)

target:
n = int(input())

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

D = {i: [0] for i in range(1, n+1)}

for i in range(n+1):

  D[a[i]][0] += 1

  D[a[i]].append(i)

pl, pr = 0, 0

for i in D:

  if D[i][0] == 2:

    pl = D[i][1]

    pr = D[i][2]

    break

L = pl

M = pr - pl - 1

N = n - pr

mod = int(1e9) + 7 # <-- input modulo

maxf = n+11          # <-- input factional limitation

def make_fact(n, k):

    tmp = n

    perm = [i for i in range(k)]

    L = [0 for _ in range(k)]

    for i in range(k):

        L[i] = tmp % (i + 1)

        tmp //= i + 1

    LL = [0 for _ in range(k)]

    for i in range(k):

        LL[i] = perm[L[-i-1]]

        for j in range(L[-i-1]+1, k):

            perm[j-1] = perm[j]

    return LL

def doubling(n, m, modulo=mod):

    y = 1

    base = n

    tmp = m

    while tmp != 0:

        if tmp % 2 == 1:

            y *= base

            if modulo > 0:

                y %= modulo

        base *= base

        if modulo > 0:

            base %= modulo

        tmp //= 2

    return y

def inved(a, modulo=mod):

    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo

    while l != 0:

        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)

        k, l = l, k % l

    return x % modulo

fact = [1 for _ in range(maxf+1)]

invf = [1 for _ in range(maxf+1)]

for i in range(maxf):

    fact[i+1] = (fact[i] * (i+1)) % mod

invf[-1] = inved(fact[-1])

for i in range(maxf, 0, -1):

    invf[i-1] = (invf[i] * i) % mod

for i in range(1, n+2):

  S = fact[n+1]*invf[i]*invf[n-i+1]%mod

  if i <= n-M:

    S -= fact[n-1-M]*invf[i-1]*invf[n-M-i]%mod

    S %= mod

  print(S)

code_v0_no_empty_lines:
n = int(input())
a = list(map(int, input().split()))
D = {i: [0] for i in range(1, n + 1)}
for i in range(n + 1):
    D[a[i]][0] += 1
    D[a[i]].append(i)
pl, pr = 0, 0
for i in D:
    if D[i][0] == 2:
        pl = D[i][1]
        pr = D[i][2]
        break
L = pl
M = pr - pl - 1
N = n - pr
mod = int(1e9) + 7  # <-- input modulo
maxf = n + 11  # <-- input factional limitation

def make_fact(n, k):
    tmp = n
    perm = [i for i in range(k)]
    L = [0 for _ in range(k)]
    for i in range(k):
        L[i] = tmp % (i + 1)
        tmp //= i + 1
    LL = [0 for _ in range(k)]
    for i in range(k):
        LL[i] = perm[L[-i - 1]]
        for j in range(L[-i - 1] + 1, k):
            perm[j - 1] = perm[j]
    return LL

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf + 1)]
invf = [1 for _ in range(maxf + 1)]
for i in range(maxf):
    fact[i + 1] = (fact[i] * (i + 1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i - 1] = (invf[i] * i) % mod
for i in range(1, n + 2):
    S = fact[n] * invf[i - 1] * invf[n - i + 1] % mod
    if i <= n - 1:
        S += fact[n - 1] * invf[i] * invf[n - 1 - i] % mod
        S %= mod
    if i <= n - M:
        S -= fact[n - 1 - M] * invf[i - 1] * invf[n - M - i] % mod
        S %= mod
    if i <= n:
        S += fact[n - 1] * invf[i - 1] * invf[n - i] % mod
        S %= mod
    print(S)

code_v1_no_empty_lines:
n = int(input())
a = list(map(int, input().split()))
D = {i: [0] for i in range(1, n + 1)}
for i in range(n + 1):
    D[a[i]][0] += 1
    D[a[i]].append(i)
pl, pr = 0, 0
for i in D:
    if D[i][0] == 2:
        pl = D[i][1]
        pr = D[i][2]
        break
L = pl
M = pr - pl - 1
N = n - pr
mod = int(1e9) + 7  # <-- input modulo
maxf = n + 11  # <-- input factional limitation

def make_fact(n, k):
    tmp = n
    perm = [i for i in range(k)]
    L = [0 for _ in range(k)]
    for i in range(k):
        L[i] = tmp % (i + 1)
        tmp //= i + 1
    LL = [0 for _ in range(k)]
    for i in range(k):
        LL[i] = perm[L[-i - 1]]
        for j in range(L[-i - 1] + 1, k):
            perm[j - 1] = perm[j]
    return LL

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf + 1)]
invf = [1 for _ in range(maxf + 1)]
for i in range(maxf):
    fact[i + 1] = (fact[i] * (i + 1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i - 1] = (invf[i] * i) % mod
for i in range(1, n + 2):
    S = fact[n + 1] * invf[i] * invf[n - i + 1] % mod
    if i <= n - M:
        S -= fact[n - 1 - M] * invf[i - 1] * invf[n - M - i] % mod
        S %= mod
    print(S)

diff: -    S = fact[n] * invf[i - 1] * invf[n - i + 1] % mod

diff: -        S += fact[n - 1] * invf[i] * invf[n - 1 - i] % mod

diff: +    S = fact[n + 1] * invf[i] * invf[n - i + 1] % mod

diff: -        S += fact[n - 1] * invf[i - 1] * invf[n - i] % mod


status_v0: Accepted

status_v1: Accepted

input:
N = int(input())

X = [[] for i in range(N)]

for i in range(N-1):

    x, y = list(map(int, input().split()))

    X[x-1].append(y-1)

    X[y-1].append(x-1)

P = [-1] * N

DE = [0] * N

Q = [0]

while Q:

    i = Q.pop()

    for a in X[i][::-1]:

        if a != P[i]:

            P[a] = i

            DE[a] = DE[i] + 1

            X[a].remove(i)

            Q.append(a)

def lp(u, v):

    t = 0

    while u != v:

        if DE[u] > DE[v]:

            t += 1 << u-1

            u = P[u]

        elif DE[u] < DE[v]:

            t += 1 << v-1

            v = P[v]

        else:

            t += 1 << u-1

            t += 1 << v-1

            u = P[u]

            v = P[v]

    return t

Y = []

M = int(input())

for _ in range(M):

    a, b = list(map(int, input().split()))

    a, b = a-1, b-1

    Y.append(lp(a, b))

D = {1<<i: i for i in range(50)}

Z = [0] * (1<<M)

ans = 0

CC = [0] * N

BC = [0] * (1<<17)

for m in range(1, 1<<17):

    a = m & (-m)

    BC[m] = BC[m^a] + 1

for m in range(1<<M):

    a = m & (-m)

    if a == m:

        if a == 0:

            Z[m] = 0

        else:

            Z[m] = Y[D[a]]

    else:

        Z[m] = Z[m^a] | Y[D[a]]

    aa = Z[m]

    bc = BC[aa % (1<<17)]

    aa >>= 17

    bc += BC[aa % (1<<17)]

    aa >>= 17

    bc += BC[aa]

    CC[N - 1 - bc] += (1 if BC[m%1024] + BC[m>>10] & 1 == 0 else -1)

print((sum([2 ** i * CC[i] for i in range(N)])))

code_v0_no_empty_lines:
N = int(input())
X = [[] for i in range(N)]
for i in range(N - 1):
    x, y = list(map(int, input().split()))
    X[x - 1].append(y - 1)
    X[y - 1].append(x - 1)
P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
    i = Q.pop()
    for a in X[i][::-1]:
        if a != P[i]:
            P[a] = i
            DE[a] = DE[i] + 1
            X[a].remove(i)
            Q.append(a)

def lp(u, v):
    t = 0
    while u != v:
        if DE[u] > DE[v]:
            t += 1 << u - 1
            u = P[u]
        elif DE[u] < DE[v]:
            t += 1 << v - 1
            v = P[v]
        else:
            t += 1 << u - 1
            t += 1 << v - 1
            u = P[u]
            v = P[v]
    return t

Y = []
M = int(input())
for _ in range(M):
    a, b = list(map(int, input().split()))
    a, b = a - 1, b - 1
    Y.append(lp(a, b))
D = {1 << i: i for i in range(50)}
Z = [0] * (1 << M)
ans = 0
CC = [0] * N
BC = [0] * (1 << 17)
for m in range(1, 1 << 17):
    a = m & (-m)
    BC[m] = BC[m ^ a] + 1
for m in range(1 << M):
    a = m & (-m)
    if a == m:
        if a == 0:
            Z[m] = 0
        else:
            Z[m] = Y[D[a]]
    else:
        Z[m] = Z[m ^ a] | Y[D[a]]
    aa = Z[m]
    bc = BC[aa % (1 << 17)]
    aa >>= 17
    bc += BC[aa % (1 << 17)]
    aa >>= 17
    bc += BC[aa]
    CC[N - 1 - bc] += 1 if BC[m % 1024] + BC[m >> 10] & 1 == 0 else -1
print((sum([2**i * CC[i] for i in range(N)])))

diff: +    CC[N - 1 - popcnt(Z[m])] += 1 if popcnt(m) & 1 == 0 else -1


status_v0: Accepted

status_v1: Accepted

input:
import math,string,itertools,math,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)

inf = 10**20

eps = 1.0 / 10**15

mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def I(): return int(sys.stdin.readline())

def F(): return float(sys.stdin.readline())

def S(): return input()

def pf(s): return print(s, flush=True)

def divisions(n):

    sq = int(math.sqrt(n)+1)

    d = collections.defaultdict(int)

    while n % 2 == 0:

        n //= 2

        d[2] += 1

    i = 3

    while n > 1 and sq >= i:

        if n % i == 0:

            n //= i

            d[i] += 1

        else:

            i += 2

    if n > 1:

        d[n] += 1

    r = [1]

    for k, v in d.items():

        for c in r[:]:

            for i in range(1,v+1):

                r.append(c*(k**i))

    return sorted(r)

def main():

    n = I()

    a = LI()

    s = set()

    for i in range(n,0,-1):

        d = divisions(i)

        ld = len(d)

        for j in range(1,2**ld):

            c = []

            ff = True

            for k in range(ld):

                if j & (1<<k):

                    f = True

                    for e in c:

                        if d[k] % e == 0:

                            f = False

                            ff = False

                            break

                    if f:

                        c.append(d[k])

                if not ff:

                    break

            if ff:

                s.add(tuple(c + [n+1]))

    b = sorted(list(s), reverse=True)

    for c in b:

        t = 0

        for j in range(1,n+1):

            f = False

            for e in c:

                if j%e == 0:

                    f = True

                    break

            if f:

                t += a[j-1]

        if t < 0:

            for j in range(1,n+1):

                f = False

                for e in c:

                    if j%e == 0:

                        f = True

                        break

                if f:

                    a[j-1] = 0

    return sum(a)

print(main())

target:
import math,string,itertools,math,heapq,collections,re,array,bisect,sys,copy,functools

import time,random

sys.setrecursionlimit(10**7)

inf = 10**20

eps = 1.0 / 10**10

mod = 10**9+7

mod2 = 998244353

dd = [(-1,0),(0,1),(1,0),(0,-1)]

ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def LF(): return [float(x) for x in sys.stdin.readline().split()]

def LS(): return sys.stdin.readline().split()

def I(): return int(sys.stdin.readline())

def F(): return float(sys.stdin.readline())

def S(): return input()

def pf(s): return print(s, flush=True)

def pe(s): return print(str(s), file=sys.stderr)

def JA(a, sep): return sep.join(map(str, a))

def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

class Flow():

    def __init__(self, e, N):

        self.E = e

        self.N = N

    def max_flow(self, s, t):

        r = 0

        e = self.E

        def f(c, cap):

            v = self.v

            v[c] = 1

            if c == t:

                return cap

            for i in range(self.N):

                if v[i] or e[c][i] <= 0:

                    continue

                cp = min(cap, e[c][i])

                k = f(i, cp)

                if k > 0:

                    e[c][i] -= k

                    e[i][c] += k

                    return k

            return 0

        while True:

            self.v = [None] * self.N

            fs = f(s, inf)

            if fs == 0:

                break

            r += fs

        return r

def main():

    n = I()

    a = LI()

    s = n

    t = n + 1

    e = [[0] * (n+2) for _ in range(n+2)]

    for i in range(n):

        c = a[i]

        if c < 0:

            e[s][i] = -c

            ii = i + 1

            for j in range(ii*2, n+1, ii):

                e[i][j-1] = inf

        else:

            e[i][t] = c

    fl = Flow(e, n+2)

    r = fl.max_flow(s,t)

    return sum(map(lambda x: max(0,x), a)) - r

# start = time.time()

print(main())

# pe(time.time() - start)

code_v0_no_empty_lines:
import math, string, itertools, math, heapq, collections, re, array, bisect, sys, random, time, copy, functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9 + 7

def LI():
    return [int(x) for x in sys.stdin.readline().split()]

def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
    return [float(x) for x in sys.stdin.readline().split()]

def LS():
    return sys.stdin.readline().split()

def I():
    return int(sys.stdin.readline())

def F():
    return float(sys.stdin.readline())

def S():
    return input()

def pf(s):
    return print(s, flush=True)

def divisions(n):
    sq = int(math.sqrt(n) + 1)
    d = collections.defaultdict(int)
    while n % 2 == 0:
        n //= 2
        d[2] += 1
    i = 3
    while n > 1 and sq >= i:
        if n % i == 0:
            n //= i
            d[i] += 1
        else:
            i += 2
    if n > 1:
        d[n] += 1
    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1, v + 1):
                r.append(c * (k**i))
    return sorted(r)

def main():
    n = I()
    a = LI()
    s = set()
    for i in range(n, 0, -1):
        d = divisions(i)
        ld = len(d)
        for j in range(1, 2**ld):
            c = []
            ff = True
            for k in range(ld):
                if j & (1 << k):
                    f = True
                    for e in c:
                        if d[k] % e == 0:
                            f = False
                            ff = False
                            break
                    if f:
                        c.append(d[k])
                if not ff:
                    break
            if ff:
                s.add(tuple(c + [n + 1]))
    b = sorted(list(s), reverse=True)
    for c in b:
        t = 0
        for j in range(1, n + 1):
            f = False
            for e in c:
                if j % e == 0:
                    f = True
                    break
            if f:
                t += a[j - 1]
        if t < 0:
            for j in range(1, n + 1):
                f = False
                for e in c:
                    if j % e == 0:
                        f = True
                        break
                if f:
                    a[j - 1] = 0
    return sum(a)

print(main())

code_v1_no_empty_lines:
import math, string, itertools, math, heapq, collections, re, array, bisect, sys, copy, functools
import time, random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
    return list(map(int, sys.stdin.readline().split()))

def LLI():
    return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
    return [float(x) for x in sys.stdin.readline().split()]

def LS():
    return sys.stdin.readline().split()

def I():
    return int(sys.stdin.readline())

def F():
    return float(sys.stdin.readline())

def S():
    return input()

def pf(s):
    return print(s, flush=True)

def pe(s):
    return print(str(s), file=sys.stderr)

def JA(a, sep):
    return sep.join(map(str, a))

def JAA(a, s, t):
    return s.join(t.join(map(str, b)) for b in a)

class Flow:
    def __init__(self, e, N):
        self.E = e
        self.N = N

    def max_flow(self, s, t):
        r = 0
        e = self.E

        def f(c, cap):
            v = self.v
            v[c] = 1
            if c == t:
                return cap
            for i in range(self.N):
                if v[i] or e[c][i] <= 0:
                    continue
                cp = min(cap, e[c][i])
                k = f(i, cp)
                if k > 0:
                    e[c][i] -= k
                    e[i][c] += k
                    return k
            return 0

        while True:
            self.v = [None] * self.N
            fs = f(s, inf)
            if fs == 0:
                break
            r += fs
        return r

def main():
    n = I()
    a = LI()
    s = n
    t = n + 1
    e = [[0] * (n + 2) for _ in range(n + 2)]
    for i in range(n):
        c = a[i]
        if c < 0:
            e[s][i] = -c
            ii = i + 1
            for j in range(ii * 2, n + 1, ii):
                e[i][j - 1] = inf
        else:
            e[i][t] = c
    fl = Flow(e, n + 2)
    r = fl.max_flow(s, t)
    return sum(map(lambda x: max(0, x), a)) - r

# start = time.time()
print(main())
# pe(time.time() - start)

diff: -import math, string, itertools, math, heapq, collections, re, array, bisect, sys, random, time, copy, functools

diff: +import math, string, itertools, math, heapq, collections, re, array, bisect, sys, copy, functools

diff: -    return [int(x) for x in sys.stdin.readline().split()]

diff: +    return list(map(int, sys.stdin.readline().split()))

diff: +    return [list(map(int, l.split())) for l in sys.stdin.readlines()]

diff: +    return print(str(s), file=sys.stderr)

diff: +    return s.join(t.join(map(str, b)) for b in a)

diff: -                s.add(tuple(c + [n + 1]))

diff: +            for j in range(ii * 2, n + 1, ii):

diff: +    return sum(map(lambda x: max(0, x), a)) - r


status_v0: Accepted

status_v1: Accepted

input:
# Acceptance of input

import sys

file_input = sys.stdin

X, Y, E = list(map(int, file_input.readline().split()))

v_num = X + Y + 2

adj_mat = [[0] * (v_num) for i in range(v_num)]

for line in file_input:

    x, y = list(map(int, line.split()))

    adj_mat[x][X + y] = 1

s = X + Y

t = s + 1

for i in range(X):

    adj_mat[s][i] = 1

for i in range(X, s):

    adj_mat[i][t] = 1

# Dinic's algorithm

import collections

# BFS for residual capacity network to construct level graph

def bfs(start, goal, parent):

    unvisited = [True] * v_num

    queue = collections.deque()

    queue.append(start)

    unvisited[start] = False

    while queue:

        u = queue.popleft()

        for v, r_capacity in enumerate(adj_mat[u]):

            if unvisited[v] and (r_capacity > 0):

                parent[v].append(u)

                queue.append(v)

                unvisited[v] = False

    return unvisited[goal]

# DFS for level graph and construct blocking flow

def dfs(goal, path, parent, blocking_flow):

    v = path[-1]

    if v == goal:

        aug_path_flow = 10000

        for x, y in zip(path[1:], path[:-1]):

            aug_path_flow = min(aug_path_flow, adj_mat[x][y])

        for x, y in zip(path[1:], path[:-1]):

            adj_mat[x][y] -= aug_path_flow

            adj_mat[y][x] += aug_path_flow

        blocking_flow[0] += aug_path_flow

    else:

        for u in parent[v]:

            path.append(u)

            dfs(goal, path, parent, blocking_flow)

            path.pop()

def dinic(source, sink):

    max_flow = 0

    parent = [[] for i in range(v_num)]

    while not bfs(source, sink, parent):

        blocking_flow = [0]

        path = [sink]

        # search in reverse direction from sink

        dfs(source, path, parent, blocking_flow)

        max_flow += blocking_flow[0]

        parent = [[] for i in range(v_num)]

    return max_flow

# output

print((dinic(s, t)))

target:
# Acceptance of input

import sys

file_input = sys.stdin

X, Y, E = list(map(int, file_input.readline().split()))

v_num = X + Y + 2

adj_mat = [[0] * (v_num) for i in range(v_num)]

for line in file_input:

    x, y = list(map(int, line.split()))

    adj_mat[x][X + y] = 1

s = X + Y

t = s + 1

for i in range(X):

    adj_mat[s][i] = 1

for i in range(X, s):

    adj_mat[i][t] = 1

# Dinic's algorithm

import collections

# BFS for residual capacity network to construct level graph

def bfs(start, goal, parent):

    level = [v_num] * v_num

    unvisited = [True] * v_num

    queue = collections.deque()

    queue.append(start)

    level[start] = 0

    unvisited[start] = False

    while queue:

        u = queue.popleft()

        next_level = level[u] + 1

        for v, r_capacity in enumerate(adj_mat[u]):

            if (level[v] >= next_level) and (r_capacity > 0):

                level[v] = next_level

                parent[v].append(u)

                if unvisited[v]:

                    queue.append(v)

                    unvisited[v] = False

    return level[goal]

# DFS for level graph and construct blocking flow

def dfs(goal, path, parent, blocking_flow):

    v = path[-1]

    if v == goal:

        aug_path_flow = 10000

        for x, y in zip(path[1:], path[:-1]):

            aug_path_flow = min(aug_path_flow, adj_mat[x][y])

        for x, y in zip(path[1:], path[:-1]):

            adj_mat[x][y] -= aug_path_flow

            adj_mat[y][x] += aug_path_flow

        blocking_flow[0] += aug_path_flow

    else:

        for u in parent[v]:

            path.append(u)

            dfs(goal, path, parent, blocking_flow)

            path.pop()

def dinic(source, sink):

    max_flow = 0

    parent = [[] for i in range(v_num)]

    while bfs(source, sink, parent) != v_num:

        blocking_flow = [0]

        path = [sink]

        # search in reverse direction from sink

        dfs(source, path, parent, blocking_flow)

        max_flow += blocking_flow[0]

        parent = [[] for i in range(v_num)]

    return max_flow

# output

print((dinic(s, t)))

diff: -            if unvisited[v] and (r_capacity > 0):

diff: +            if (level[v] >= next_level) and (r_capacity > 0):

diff: +                    unvisited[v] = False

diff: -    while not bfs(source, sink, parent):

diff: +    while bfs(source, sink, parent) != v_num:


status_v0: Accepted

status_v1: Accepted

input:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**6)

INF = 10 ** 9 + 1  # sys.maxsize # float("inf")

MOD = 10 ** 9 + 7

def floor_sum(n, m, a, b):

    ret = 0

    if a >= m:

        ret += (n - 1) * n * (a // m) // 2

        a %= m

    if b >= m:

        ret += n * (b // m)

        b %= m

    y_max = (a * n + b) // m

    x_max = y_max * m - b

    if y_max == 0:

        return ret

    ret += (n - (x_max + a - 1) // a) * y_max

    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)

    return ret

def debug(*x):

    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):

    pass

def main():

    # parse input

    T = int(input())

    for _t in range(T):

        N, M, A, B = map(int, input().split())

        print(floor_sum(N, M, A, B))

# tests

T1 = """

5

4 10 6 3

6 5 4 3

1 1 0 0

31415 92653 58979 32384

1000000000 1000000000 999999999 999999999

"""

TEST_T1 = """

>>> as_input(T1)

>>> main()

3

13

0

314095480

499999999500000000

"""

def _test():

    import doctest

    doctest.testmod()

    g = globals()

    for k in sorted(g):

        if k.startswith("TEST_"):

            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):

    "use in test, use given string as input file"

    import io

    f = io.StringIO(s.strip())

    g = globals()

    g["input"] = lambda: bytes(f.readline(), "ascii")

    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline

read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":

    print("testing")

    _test()

    sys.exit()

main()

target:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**6)

INF = 10 ** 9 + 1  # sys.maxsize # float("inf")

MOD = 10 ** 9 + 7

def floor_sum_1(n, m, a, b):

    ret = 0

    if a >= m:

        ret += (n - 1) * n * (a // m) // 2

        a %= m

    if b >= m:

        ret += n * (b // m)

        b %= m

    y_max = (a * n + b) // m

    x_max = y_max * m - b

    if y_max == 0:

        return ret

    ret += (n - (x_max + a - 1) // a) * y_max

    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)

    return ret

def floor_sum(n, m, a, b):

    ret = 0

    while True:

        if a >= m:

            ret += (n - 1) * n * (a // m) // 2

            a %= m

        if b >= m:

            ret += n * (b // m)

            b %= m

        y_max = (a * n + b) // m

        x_max = y_max * m - b

        if y_max == 0:

            return ret

        ret += (n - (x_max + a - 1) // a) * y_max

        n = y_max

        m, a, b = a, m, (a - x_max % a) % a

def debug(*x):

    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):

    pass

def main():

    # parse input

    T = int(input())

    for _t in range(T):

        N, M, A, B = map(int, input().split())

        print(floor_sum(N, M, A, B))

# tests

T1 = """

5

4 10 6 3

6 5 4 3

1 1 0 0

31415 92653 58979 32384

1000000000 1000000000 999999999 999999999

"""

TEST_T1 = """

>>> as_input(T1)

>>> main()

3

13

0

314095480

499999999500000000

"""

def _test():

    import doctest

    doctest.testmod()

    g = globals()

    for k in sorted(g):

        if k.startswith("TEST_"):

            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):

    "use in test, use given string as input file"

    import io

    f = io.StringIO(s.strip())

    g = globals()

    g["input"] = lambda: bytes(f.readline(), "ascii")

    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline

read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":

    print("testing")

    _test()

    sys.exit()

main()

code_v0_no_empty_lines:
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**6)
INF = 10**9 + 1  # sys.maxsize # float("inf")
MOD = 10**9 + 7

def floor_sum(n, m, a, b):
    ret = 0
    if a >= m:
        ret += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ret += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ret
    ret += (n - (x_max + a - 1) // a) * y_max
    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ret

def debug(*x):
    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):
    pass

def main():
    # parse input
    T = int(input())
    for _t in range(T):
        N, M, A, B = map(int, input().split())
        print(floor_sum(N, M, A, B))

# tests
T1 = """
5
4 10 6 3
6 5 4 3
1 1 0 0
31415 92653 58979 32384
1000000000 1000000000 999999999 999999999
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
3
13
0
314095480
499999999500000000
"""

def _test():
    import doctest

    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):
    "use in test, use given string as input file"
    import io

    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()
main()

code_v1_no_empty_lines:
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10**6)
INF = 10**9 + 1  # sys.maxsize # float("inf")
MOD = 10**9 + 7

def floor_sum_1(n, m, a, b):
    ret = 0
    if a >= m:
        ret += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ret += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ret
    ret += (n - (x_max + a - 1) // a) * y_max
    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ret

def floor_sum(n, m, a, b):
    ret = 0
    while True:
        if a >= m:
            ret += (n - 1) * n * (a // m) // 2
            a %= m
        if b >= m:
            ret += n * (b // m)
            b %= m
        y_max = (a * n + b) // m
        x_max = y_max * m - b
        if y_max == 0:
            return ret
        ret += (n - (x_max + a - 1) // a) * y_max
        n = y_max
        m, a, b = a, m, (a - x_max % a) % a

def debug(*x):
    print(*x, file=sys.stderr)

def solve(SOLVE_PARAMS):
    pass

def main():
    # parse input
    T = int(input())
    for _t in range(T):
        N, M, A, B = map(int, input().split())
        print(floor_sum(N, M, A, B))

# tests
T1 = """
5
4 10 6 3
6 5 4 3
1 1 0 0
31415 92653 58979 32384
1000000000 1000000000 999999999 999999999
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
3
13
0
314095480
499999999500000000
"""

def _test():
    import doctest

    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)

def as_input(s):
    "use in test, use given string as input file"
    import io

    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")

input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()
main()

diff: +        m, a, b = a, m, (a - x_max % a) % a


status_v0: Accepted

status_v1: Accepted

input:
#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return list(map(int, sys.stdin.readline().split()))

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

"""

def gcd(a,b):

    if a == 0:

        return b

    return gcd(b%a,a)

n = I()

a = IR(n)

l = a[0]

for i in range(1,n):

    g = gcd(l,a[i])

    l *= a[i]//g

print(l)

"""

#B

n = I()

v = [[] for i in range(n)]

for i in range(n-1):

    a,b,c = LI()

    a -= 1

    b -= 1

    v[a].append([b,c])

    v[b].append([a,c])

Q,k = LI()

d = [-1 for i in range(n)]

d[k-1] = 0

q = deque()

q.append(k-1)

while q:

    x = q.pop()

    for y,c in v[x]:

        if d[y] == -1:

            d[y] = d[x]+c

            q.append(y)

for i in range(Q):

    x,y = LI()

    x -= 1

    y -= 1

    print((d[x]+d[y]))

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

target:
#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return list(map(int, sys.stdin.readline().split()))

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

"""

def gcd(a,b):

    if a == 0:

        return b

    return gcd(b%a,a)

n = I()

a = IR(n)

l = a[0]

for i in range(1,n):

    g = gcd(l,a[i])

    l *= a[i]//g

print(l)

"""

#B

n = I()

v = [[] for i in range(n)]

for i in range(n-1):

    a,b,c = LI()

    a -= 1

    b -= 1

    v[a].append([b,c])

    v[b].append([a,c])

Q,k = LI()

d = [-1 for i in range(n)]

d[k-1] = 0

q = deque()

q.append(k-1)

while q:

    x = q.popleft()

    for y,c in v[x]:

        if d[y] == -1:

            d[y] = d[x]+c

            q.append(y)

for i in range(Q):

    x,y = LI()

    x -= 1

    y -= 1

    print((d[x]+d[y]))

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

code_v0_no_empty_lines:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
    return list(map(int, sys.stdin.readline().split()))

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""
# B
n = I()
v = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = LI()
    a -= 1
    b -= 1
    v[a].append([b, c])
    v[b].append([a, c])
Q, k = LI()
d = [-1 for i in range(n)]
d[k - 1] = 0
q = deque()
q.append(k - 1)
while q:
    x = q.pop()
    for y, c in v[x]:
        if d[y] == -1:
            d[y] = d[x] + c
            q.append(y)
for i in range(Q):
    x, y = LI()
    x -= 1
    y -= 1
    print((d[x] + d[y]))
# C
# D
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T

code_v1_no_empty_lines:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
    return list(map(int, sys.stdin.readline().split()))

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""
# B
n = I()
v = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = LI()
    a -= 1
    b -= 1
    v[a].append([b, c])
    v[b].append([a, c])
Q, k = LI()
d = [-1 for i in range(n)]
d[k - 1] = 0
q = deque()
q.append(k - 1)
while q:
    x = q.popleft()
    for y, c in v[x]:
        if d[y] == -1:
            d[y] = d[x] + c
            q.append(y)
for i in range(Q):
    x, y = LI()
    x -= 1
    y -= 1
    print((d[x] + d[y]))
# C
# D
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T

diff:
-    x = q.pop()
+    x = q.popleft()


status_v0: Accepted

status_v1: Accepted

input:
def popcount(x):

    x = x - ((x >> 1) & 0x55555555)

    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    return x & 0x0000007f

cmb=[[0 for i in range(51)] for j in range(51)]

cmb[0][0]=1

for i in range(51):

    for j in range(51):

        if i!=50 and j!=50:

            cmb[i+1][j+1]+=cmb[i][j]

        if i!=50:

            cmb[i+1][j]+=cmb[i][j]

for i in range(1,51):

    for j in range(2,51):

        cmb[i][j]+=cmb[i][j-1]

N,K,T,S=list(map(int,input().split()))

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

must0=[i for i in range(18) if S>>i &1==0]

must1=[i for i in range(18) if T>>i &1==1]

A=[]

for val in a:

    check=True

    for j in must0:

        check=check&(val>>j &1==0)

    for j in must1:

        check=check&(val>>j &1==1)

    if check:

        A.append(val)

if not A:

    print((0))

    exit()

bit=[]

for i in range(18):

    if i not in must0 and i not in must1:

        bit.append(i)

for i in range(len(A)):

    temp=0

    for j in range(len(bit)):

        temp+=(A[i]>>bit[j] &1==1)*2**j

    A[i]=temp

ans=0

n=len(bit)

data=[0]*(2**n)

for i in range(2**n):

    t=set([])

    for a in A:

        data[a&i]+=1

        t.add(a&i)

    temp=0

    for val in t:

        temp+=cmb[data[val]][min(K,data[val])]

    ans+=temp*(-1)**popcount(i)

    for val in t:

        data[val]=0

print(ans)

target:
def popcount(x):

    x = x - ((x >> 1) & 0x55555555)

    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f

    x = x + (x >> 8)

    x = x + (x >> 16)

    return x & 0x0000007f

cmb=[[0 for i in range(51)] for j in range(51)]

cmb[0][0]=1

for i in range(51):

    for j in range(51):

        if i!=50:

            cmb[i+1][j]+=cmb[i][j]

        if j!=50 and i!=50:

            cmb[i+1][j+1]+=cmb[i][j]

for i in range(1,51):

    for j in range(2,51):

        cmb[i][j]+=cmb[i][j-1]

import random

N,K,T,S=list(map(int,input().split()))

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

must0=[i for i in range(18) if S>>i &1==0]

must1=[i for i in range(18) if T>>i &1==1]

A=[]

for val in a:

    check=True

    for j in must0:

        check=check&(val>>j &1==0)

    for j in must1:

        check=check&(val>>j &1==1)

    if check:

        A.append(val)

if not A:

    print((0))

    exit()

bit=[]

for i in range(18):

    if i not in must0 and i not in must1:

        bit.append(i)

for i in range(len(A)):

    temp=0

    for j in range(len(bit)):

        temp+=(A[i]>>bit[j] &1==1)*2**j

    A[i]=temp

ans=0

n=len(bit)

data=[0]*(2**n)

pc=[popcount(i) for i in range(2**n)]

for i in range(2**n):

    for a in A:

        data[a&i]+=1

    for a in A:

        if data[a&i]:

            ans+=cmb[data[a&i]][min(K,data[a&i])]*(-1)**pc[i]

            data[a&i]=0

print(ans)

code_v0_no_empty_lines:
def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007F

cmb = [[0 for i in range(51)] for j in range(51)]
cmb[0][0] = 1
for i in range(51):
    for j in range(51):
        if i != 50 and j != 50:
            cmb[i + 1][j + 1] += cmb[i][j]
        if i != 50:
            cmb[i + 1][j] += cmb[i][j]
for i in range(1, 51):
    for j in range(2, 51):
        cmb[i][j] += cmb[i][j - 1]
N, K, T, S = list(map(int, input().split()))
a = list(map(int, input().split()))
must0 = [i for i in range(18) if S >> i & 1 == 0]
must1 = [i for i in range(18) if T >> i & 1 == 1]
A = []
for val in a:
    check = True
    for j in must0:
        check = check & (val >> j & 1 == 0)
    for j in must1:
        check = check & (val >> j & 1 == 1)
    if check:
        A.append(val)
if not A:
    print((0))
    exit()
bit = []
for i in range(18):
    if i not in must0 and i not in must1:
        bit.append(i)
for i in range(len(A)):
    temp = 0
    for j in range(len(bit)):
        temp += (A[i] >> bit[j] & 1 == 1) * 2**j
    A[i] = temp
ans = 0
n = len(bit)
data = [0] * (2**n)
for i in range(2**n):
    t = set([])
    for a in A:
        data[a & i] += 1
        t.add(a & i)
    temp = 0
    for val in t:
        temp += cmb[data[val]][min(K, data[val])]
    ans += temp * (-1) ** popcount(i)
    for val in t:
        data[val] = 0
print(ans)

code_v1_no_empty_lines:
def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0F0F0F0F
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007F

cmb = [[0 for i in range(51)] for j in range(51)]
cmb[0][0] = 1
for i in range(51):
    for j in range(51):
        if i != 50:
            cmb[i + 1][j] += cmb[i][j]
        if j != 50 and i != 50:
            cmb[i + 1][j + 1] += cmb[i][j]
for i in range(1, 51):
    for j in range(2, 51):
        cmb[i][j] += cmb[i][j - 1]
import random

N, K, T, S = list(map(int, input().split()))
a = list(map(int, input().split()))
must0 = [i for i in range(18) if S >> i & 1 == 0]
must1 = [i for i in range(18) if T >> i & 1 == 1]
A = []
for val in a:
    check = True
    for j in must0:
        check = check & (val >> j & 1 == 0)
    for j in must1:
        check = check & (val >> j & 1 == 1)
    if check:
        A.append(val)
if not A:
    print((0))
    exit()
bit = []
for i in range(18):
    if i not in must0 and i not in must1:
        bit.append(i)
for i in range(len(A)):
    temp = 0
    for j in range(len(bit)):
        temp += (A[i] >> bit[j] & 1 == 1) * 2**j
    A[i] = temp
ans = 0
n = len(bit)
data = [0] * (2**n)
pc = [popcount(i) for i in range(2**n)]
for i in range(2**n):
    for a in A:
        data[a & i] += 1
    for a in A:
        if data[a & i]:
            ans += cmb[data[a & i]][min(K, data[a & i])] * (-1) ** pc[i]
            data[a & i] = 0
print(ans)

diff: +pc = [popcount(i) for i in range(2**n)]

diff: -        temp += cmb[data[val]][min(K, data[val])]

diff: +            ans += cmb[data[a & i]][min(K, data[a & i])] * (-1) ** pc[i]