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

# coding: utf-8
# Your code here!
#from sys import stdin
#import math
#from functools import reduce
    
#A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N = int(input())
S = input()
 
counter = 0
 
for k in range(N):
    sk = S[k]
    for j in range(1,k):
        s = 'RGB'
        sj = S[j]
        if (sk == sj):continue
        s = s.replace(sk, '')
        s = s.replace(sj, '')
        diff = k-j
        if j-diff < 0:
            buf = S[0:j]
        #print(j-diff+1,j+1,k+1)
        #print(S)
        #print(S[0:j-diff], S[j-diff+1:j])
        else:
            buf = S[0:j-diff] + S[j-diff+1:j]
        counter = counter + buf.count(s)
        #print(s, buf.count(s), counter)
 
print(counter)

### FIXED CODE ###

N = int(input())

S = input()

ans = 0


sumR = [0]
sumG = [0]
sumB = [0]

for s in S:
    if s == "R":
        sumR.append(sumR[-1] + 1)
        sumG.append(sumG[-1])
        sumB.append(sumB[-1])
    elif s == "G":
        sumR.append(sumR[-1])
        sumG.append(sumG[-1] + 1)
        sumB.append(sumB[-1])
    elif s == "B":
        sumR.append(sumR[-1])
        sumG.append(sumG[-1])
        sumB.append(sumB[-1] + 1)


for i, s in enumerate(S):
    not_cnt = 0
    for k in range(1, min(i + 1, N - i)):
        L, R = S[i - k], S[i + k]
        if s != L and s != R and L != R:
            not_cnt += 1

    cnt = 0
    if s == "R":
        cnt += sumG[i] * (sumB[-1] - sumB[i + 1])
        cnt += sumB[i] * (sumG[-1] - sumG[i + 1])
    elif s == "G":
        cnt += sumR[i] * (sumB[-1] - sumB[i + 1])
        cnt += sumB[i] * (sumR[-1] - sumR[i + 1])
    elif s == "B":
        cnt += sumG[i] * (sumR[-1] - sumR[i + 1])
        cnt += sumR[i] * (sumG[-1] - sumG[i + 1])

    cnt -= not_cnt
    ans += cnt


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

import sys
input = sys.stdin.readline

def inp_str():
    '''
    一行の文字をlistで取得
    '''
    return list(input())[:-1]

s = inp_str()
t = inp_str()
n = len(s)
m = len(t)
value = [[0]*(m+1) for i in range(n+1)]
ans = [[""]*(m+1) for i in range(n+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            value[i + 1][j + 1] = value[i][j] + 1
            ans[i + 1][j + 1] = ans[i][j]+s[i]#"".join([ans[i][j], s[i]])
        elif value[i][j + 1] > value[i + 1][j]: #UP
            ans[i + 1][j + 1] = ans[i][j + 1]
            value[i + 1][j + 1] = value[i][j + 1]
        else:  # LEFT
            ans[i + 1][j + 1] = ans[i + 1][j]
            value[i + 1][j + 1] = value[i + 1][j]

print(ans[n][m])


### FIXED CODE ###

import sys
input = sys.stdin.readline

s = list(input())
t = list(input())
n = len(s)-1
m = len(t)-1
value = [[0]*(m+1) for i in range(n+1)]


for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            value[i + 1][j + 1] = value[i][j] + 1
        elif value[i][j + 1] > value[i + 1][j]: #UP
            value[i + 1][j + 1] = value[i][j + 1]
        else:  # LEFT
            value[i + 1][j + 1] = value[i + 1][j]
i = n-1
j = m-1
ans=""
while i >= 0 and j >= 0:
    if s[i] == t[j]:
        ans = s[i] + ans
        i -= 1
        j -= 1
    elif value[i][j + 1] > value[i + 1][j]:
        i -= 1
    else:
        j -= 1
print(ans)
### BUGGY CODE ###

S = input()
count = 0
Olength = len(S)
previousCount = 0

while(1) :
    S = S.replace("01", "")
    count = count + (Olength - len(S))
    Olength = len(S)
    S = S.replace("10", "")
    count = count + (Olength - len(S))
    Olength = len(S)
    
    if previousCount == count :
        break
    previousCount = count
print(count)

### FIXED CODE ###

S = input()
C1 = S.count("0")
C2 = S.count("1")

print(min(C1,C2)*2)
### BUGGY CODE ###

from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            if j-i !=k-j:
                if S[i-1] != S[j-1] and S[j-1] !=S[k-1] and S[i-1] != S[k-1]:
                    ans+=1
print(ans)

### FIXED CODE ###

from sys import stdin
N = list(map(int, (stdin.readline().strip().split())))[0]
S= list(stdin.readline().strip())
ans = S.count("R")*S.count("G")*S.count("B")
for i in range(N):
    for j in range(i+1,N):
        k=2*j-i
        if k>=N:break
        if S[i]!=S[j] and S[j]!=S[k] and S[i] !=S[k]:
                ans-=1
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
H=list(map(int,input().split()))
ans=[i  for i in range(1,n+1)]
low=[]
for i in range(m):
    x,y=map(int,input().split())
    if H[x-1]==H[y-1]:
        low.append(x)
        low.append(y)
    elif  H[x-1]>H[y-1]:
        low.append(y)
    else:
        low.append(x)
low=list(set(low))
for k in low:
    ans.remove(k)
print(len(ans))

### FIXED CODE ###

n,m=map(int,input().split())
H=list(map(int,input().split()))
ans=[i  for i in range(1,n+1)]
low=[]
for i in range(m):
    x,y=map(int,input().split())
    if H[x-1]==H[y-1]:
        low.append(x)
        low.append(y)
    elif  H[x-1]>H[y-1]:
        low.append(y)
    else:
        low.append(x)
low=list(set(low))
print(len(ans)-len(low))
### BUGGY CODE ###

import itertools
n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
mod = 10 ** 9 + 7
dp = [0 for i in range(n + 1)]

dp[0] = 1

for i in range(1, n + 1):
    if i in a:
        continue
    else:
        dp[i] += dp[i - 1]
        dp[i] %= mod
        if i != 1:
            dp[i] += dp[i - 2]
            dp[i] %= mod

print(dp[n])


### FIXED CODE ###

import itertools
n, m = map(int, input().split())
a = set([int(input()) for i in range(m)])
mod = 10 ** 9 + 7
dp = [0] * (n + 1)

dp[0] = 1
dp[1] = 0 if 1 in a else 1

for i in range(2, n + 1):
    if i in a:
        continue
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod

print(dp[n])
### BUGGY CODE ###

"""
E.
"""
from functools import reduce
from collections import deque


def prod(x, y):
    return x * y % MOD

    
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
# abs_a_list = sorted(a_list, key=abs, reverse=True)
MOD = 10**9 + 7

if K%2 == 1:
    flg = True
    for a in a_list:
        if a >= 0:
            flg = False
            break
    if flg:
        print(reduce(prod, a_list[:K]))
        exit()

S = []
a_list = deque(a_list)
for _ in range(K//2):
    if a_list[0]*a_list[1] > a_list[-1]*a_list[-2]:
        S.append(a_list.popleft())
        S.append(a_list.popleft())
    else:
        S.append(a_list.pop())
        S.append(a_list.pop())
    if 0 in S:
        print(0)
        exit()
        
if K%2 == 1:
    S.append(a_list.popleft())
ans = reduce(prod, S)
print(ans)

### FIXED CODE ###

"""
E.
"""
from functools import reduce
from collections import deque


def prod(x, y):
    return x * y % MOD

    
N, K = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort(reverse=True)
# abs_a_list = sorted(a_list, key=abs, reverse=True)
MOD = 10**9 + 7

if K%2 == 1:
    flg = True
    for a in a_list:
        if a >= 0:
            flg = False
            break
    if flg:
        print(reduce(prod, a_list[:K]))
        exit()

S = []
a_list = deque(a_list)
i = 0
while i < K:
    if len(a_list)>=2:
        if a_list[0]*a_list[1] > a_list[-1]*a_list[-2]:
            S.append(a_list.popleft())
            i += 1
        elif a_list[0]*a_list[1] <= a_list[-1]*a_list[-2] and i <= K-2:
            S.append(a_list.pop())
            S.append(a_list.pop())
            i += 2
        else:
            S.append(a_list.popleft())
            i += 1
    else:
        S.append(a_list.popleft())
        i += 1
        
ans = reduce(prod, S)
print(ans)
### BUGGY CODE ###

N = int(input())
P = []
ans = 0
n = 0
for i in range(N):
    s = int(input())
    P.append(s)
P.sort()
while n < N:
    s =  P.count(P[n])
    if s % 2 != 0:
        ans += 1
    n += s
print(ans)

### FIXED CODE ###

s = set()
N = int(input())
for _ in range(N):
    x = int(input())
    if x in s:
        s.remove(x)
    else:
        s.add(x)
print(len(s))
### BUGGY CODE ###

H,N = map(int,input().split())

#dpテーブルの設定と初期化
dp = [0] + [10 ** 9] * H

#各魔法について
for i in range(N):
  #d,cはそれぞれ魔法ダメージと魔法のコスト
  d,c = map(int,input().split())
  #dpテーブルの各HPについて
  for j in range(H + 1):
    k = j - d
    if j - d < 0:
      k = 0
    #ダメージjを与える時のコストについて、
    #魔法iを新たに使った場合と、既存の最小コストを比較し更新する
    l = dp[k] + c
    if l < dp[j]:
      dp[j] = l

print(dp[-1])


### FIXED CODE ###

def main():
    h,n,*t=map(int,open(0).read().split())
    d=[0]+[10**18]*h
    for a,b in zip(*[iter(t)]*2):
        for j in range(h+1):
            k=j-a
            if k<0:k=0
            c=d[k]+b
            if c<d[j]:d[j]=c
    print(d[h])
main()
### BUGGY CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
tAB = list(zip(*AB))
A = list(tAB[0]).copy()
B = list(tAB[1]).copy()
A.sort()
B.sort()

if N%2 == 0:
    midA1 = A[N//2-1]
    midA2 = A[N//2]
    midB1 = B[N//2-1]
    midB2 = B[N//2]
    d = defaultdict(int)
    for val1 in range(midA1, midB1+1):
        for val2 in range(midA2, midB2+1):
            # print(val1, val2)
            # gcv = gcd(val1, val2)
            # tp = (val1, val2)
            val = (val1 + val2)/2
            d[val] += 1
    # print(d)
    print(len(d.keys()))
    
else:
    midA = A[N//2]
    midB = B[N//2]
    print(midB-midA+1)

### FIXED CODE ###

import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
# AB = np.array([np.array(input().split(), np.int)
AB = np.array(AB)
# tAB = list(zip(*AB))
# print(AB)
tAB = AB.T
# print(tAB)
# print()
A = tAB[0]
B = tAB[1]
A.sort()
B.sort()

# print(A, B)

if N%2 == 0:
    midA1 = A[N//2-1]
    midA2 = A[N//2]
    midB1 = B[N//2-1]
    midB2 = B[N//2]

    midmidA = (midA1+midA2)/2
    midmidB = (midB1+midB2)/2
    res = int((midmidB-midmidA)/(0.5) + 1)
    print(res)

    # d = defaultdict(int)

    # for val1 in range(midA1, midB1+1):
    #     for val2 in range(midA2, midB2+1):
    #         val = (val1 + val2)/2
            # d[val] += 1
    # print(len(d.keys()))
    
else:
    midA = A[N//2]
    midB = B[N//2]
    print(midB-midA+1)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
count=1
if a[0]!=0:
  print(0)
else:
  b=[1]
  for i in range(1,max(a)+1):
    count=(count*(b[i-1]**a.count(i))%998244353)
    b.append(a.count(i))
  print(count)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
count=1
x=max(a)
import collections
c=collections.Counter(a)
if a[0]!=0 or c[0]!=1:
  print(0)
  exit()
else:
  b=[1]*(x+1)
  for i in range(1,x+1):
    count=(count*(b[i-1]**c[i]))%998244353
    b[i]=c[i]
  print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : July 05, 2020
##################################################### SOURCE START #####################################################

N = int(input().strip())
A = set([])

for _ in range(N - 1):
    u, v = tuple(map(int, input().strip().split()))
    u -= 1
    v -= 1
    A.add((u, v))

def update(cluster, l, r):

    connected_clusters = set([])

    for v in range(l, r):
        if (v, r) in A or (r, v) in A:
            connected_clusters.add(cluster[v])

    if len(connected_clusters) == 0:
        cluster[r] = max(set(cluster.values())) + 1

    elif len(connected_clusters) == 1:
        cluster[r] = connected_clusters.pop()

    else:
        cluster[r] = max(set(cluster.values())) + 1
        for v, c in cluster.items():
            if c in connected_clusters:
                cluster[v] = cluster[r]

    return cluster


S = 0
for l in range(N):

    cluster = dict()

    for r in range(l, N):

        if r == l: cluster[r] = 0
        else     : cluser = update(cluster, l, r)

        S += len(set(cluster.values()))

print(S)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker


### FIXED CODE ###

#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : July 05, 2020
##################################################### SOURCE START #####################################################

N = int(input().strip())
A = set([])

for _ in range(N - 1):
    u, v = tuple(map(int, input().strip().split()))
    A.add((u, v))

V = 0
for l in range(1, N + 1):
    V += (N - l + 1) * (N - l + 2) // 2

E = 0
for u, v in A:
    a = min(u, v)
    b = max(u, v)
    E += a * (N - b + 1)

print(V - E)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans)

if __name__=="__main__":
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]

    for i in range(r):
        for j in range(c):
            if i>0:
                dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+v[i][j])
                dp[0][i][j]=max(dp[0][i][j],dp[0][i-1][j])
                dp[1][i][j]=max(dp[1][i][j],dp[1][i-1][j]+v[i][j])
                dp[0][i][j]=max(dp[0][i][j],dp[1][i-1][j])
                dp[1][i][j]=max(dp[1][i][j],dp[2][i-1][j]+v[i][j])
                dp[0][i][j]=max(dp[0][i][j],dp[2][i-1][j])
                dp[1][i][j]=max(dp[1][i][j],dp[3][i-1][j]+v[i][j])
                dp[0][i][j]=max(dp[0][i][j],dp[3][i-1][j])
            if j>0:
                dp[1][i][j]=max(dp[1][i][j],dp[0][i][j-1]+v[i][j])
                dp[2][i][j]=max(dp[2][i][j],dp[1][i][j-1]+v[i][j])
                dp[3][i][j]=max(dp[3][i][j],dp[2][i][j-1]+v[i][j])
                dp[0][i][j]=max(dp[0][i][j],dp[0][i][j-1])
                dp[1][i][j]=max(dp[1][i][j],dp[1][i][j-1])
                dp[2][i][j]=max(dp[2][i][j],dp[2][i][j-1])
                dp[3][i][j]=max(dp[3][i][j],dp[3][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()
### BUGGY CODE ###

N = int(input())
count = 0
for i in range(1,N):
    if N % i != 0:
        if N//i == N % i:
            count += i
print(count)


### FIXED CODE ###

N = int(input())
count = 0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

if __name__=="__main__":
    lis = make_divisors(N)
    for i in lis:
        if i!= 1:
            if N // (i-1) == N % (i-1):
                count += i-1
    print(count)
### BUGGY CODE ###

sem, per = map(int, input().split())
scores = list(map(int, input().split()))
period_score = []

for i in range(len(scores) - (per - 1)):
    period = scores[i:per + i]
    temp = period[0]
    for j in range(1, per):
        temp *= period[j]
        
    period_score.append(temp)
    
for k in range(1, len(period_score)):
    if period_score[k - 1] < period_score[k]:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

sem, per = map(int, input().split())
scores = list(map(int, input().split()))

for i in range(sem - per):
    if scores[i] < scores[i + per] :
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
XY = [[set() for i in range(10**5+1)] for j in range(2)]
is_visited_x = [True] * (10**5 + 1)
for i in range(N):
  x, y = map(int, input().split())
  is_visited_x[x] = False
  XY[0][x].add(y)
  XY[1][y].add(x)


def dfs(x):
  global is_visited_x
  is_visited_x[x] = True
  stack = [[x], []]
  idx = 0
  num_e = 0
  num_xy = [1, 0]
  parent = 0
  while stack[0] or stack[1]:
    node = stack[idx][-1]
    children = XY[idx][node]
    if children:
      child = children.pop()
      XY[idx-1][child].remove(node) # 今来た道を削除
      num_e += 1
      if child in stack[idx-1]:
        continue
      stack[idx-1].append(child)
      num_xy[idx-1] += 1
      is_visited_x[child] += idx
      idx = (idx + 1) % 2
    else:
      stack[idx].pop()
      idx = (idx + 1) % 2
  return num_e, num_xy

ans = 0
for x in range(1, 10**5+1):
  if is_visited_x[x]:
    continue
  num_e, num_xy = dfs(x)
  ans += num_xy[0]*num_xy[1] - num_e

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
XY = [[set() for i in range(10**5+1)] for j in range(2)]
for i in range(N):
  x, y = map(int, input().split())
  XY[0][x].add(y)
  XY[1][y].add(x)

is_visited_x = [False] * (10**5 + 1)
def dfs(x):
  global is_visited_x
  is_visited_x[x] = True
  stack = [[x], []]
  idx = 0
  num_e = 0
  num_xy = [1, 0]
  parent = 0
  while stack[0] or stack[1]:
    node = stack[idx][-1]
    children = XY[idx][node]
    if children:
      child = children.pop()
      XY[idx-1][child].remove(node) # 今来た道を削除
      num_e += 1
      if child in stack[idx-1]:
        continue
      stack[idx-1].append(child)
      num_xy[idx-1] += 1
      is_visited_x[child] += idx
      idx = (idx + 1) % 2
    else:
      stack[idx].pop()
      idx = (idx + 1) % 2
  return num_e, num_xy

ans = 0
for x in range(1, 10**5+1):
  if is_visited_x[x]:
    continue
  num_e, num_xy = dfs(x)
  ans += num_xy[0]*num_xy[1] - num_e

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

line = input().split()
num = int(line[0]) + 1
sum = 0
for x in range(num):
    for y in range(num):
        leave = int(line[1]) - (x + y)
        if -1 < leave < num:
            sum += 1          
print(sum)                

### FIXED CODE ###

k, s = map(int, input().split())
ans = 0
for x in range(k+1):
           for y in range(k+1):
               if -1 < s-x-y < k+1:
                   ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
sequence = list(input().split())
ans = []
for i in range(N):
    a_i = sequence[i]
    ans.append(a_i)
    ans = ans[::-1]
print(" ".join(ans))


### FIXED CODE ###

"""TLE
N = int(input())
sequence = list(input().split())
ans = []
for i in range(N):
    a_i = sequence[i]
    ans.append(a_i)
    ans = ans[::-1]
print(" ".join(ans))
"""

from collections import deque
n = int(input())
sequence = deque(map(int,input().split()))
ans = deque()
if n % 2 == 1:
    for i in range(n):
        if i % 2 == 0:
            ans.appendleft(sequence[0])
        else:
            ans.append(sequence[0])
        sequence.popleft()
        #print(ans)
else:
    for i in range(n):
        if i % 2 == 1:
            ans.appendleft(sequence[0])
        else:
            ans.append(sequence[0])
        sequence.popleft()
        #print(ans)
print(*ans)
### BUGGY CODE ###

# 100% TLE

N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353

dp = [[[0]*(S+1) for j in range(N+1)] for i in range(N+1)]
dp[0][0][0] = 1
for i, a in enumerate(A, 1):
    for j in range(N+1):
        for s in range(S+1):
            dp[i][j][s] = dp[i-1][j][s]
            if s >= a:
                dp[i][j][s] = (dp[i][j][s] + dp[i-1][j-1][s-a] % MOD)


ans = 0
for j in range(N+1):
    ans += dp[-1][j][-1] * pow(2, N-j, MOD) % MOD
    ans %= MOD

print(ans)

### FIXED CODE ###

N, S = map(int, input().split())
MOD = 998244353
A = list(map(int, input().split()))

dp = [[0]*(S+1) for i in range(N+1)]
dp[0][0] = 1
for i, a in  enumerate(A, 1):
  for s in range(S+1):
    dp[i][s] = 2*dp[i-1][s]
    if a <= s:
      dp[i][s] += dp[i-1][s-a]
    dp[i][s] %= MOD

print(dp[-1][-1])
### BUGGY CODE ###

import heapq

N = int(input())
L = map(int, input().split(' '))

hq = []
for l in L:
    heapq.heappush(hq, l*(-1))

result = 0
while hq:
    a = heapq.heappop(hq)

    hq1 = []
    while hq:
        b = heapq.heappop(hq)

        hq2 = []
        while hq:
            c = heapq.heappop(hq)
            heapq.heappush(hq2, c)

            if a > b + c:
                result += 1

            else:
                break

        heapq.heappush(hq1, b)
        while hq2:
            heapq.heappush(hq, heapq.heappop(hq2))

    while hq1:
        heapq.heappush(hq, heapq.heappop(hq1))

print(result)


### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(lambda l: int(l)*(-1), input().split()))
L.sort()

result = 0
for i, a in enumerate(L[:-2:]):
    for ii, b in enumerate(L[i+1:-1:]):
        c_list = L[i+ii+2::]
        c_index = bisect_left(c_list, a-b)
        result += c_index

print(result)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
 
from collections import defaultdict
import heapq
import sys


        
def dijkstra(startvertex,V,graph):
    distances=[sys.maxsize]*V
    distances[startvertex]=0
    heap=[(0,startvertex)]
    while heap:
        current_distance,current_vertex=heapq.heappop(heap)
        if current_distance>distances[current_vertex]:
            continue
        for neighbor in range(len(graph[current_vertex])):
            if graph[current_vertex][neighbor]>0:
                distance=current_distance+graph[current_vertex][neighbor]
                
                
                if distance<distances[neighbor]:
                    distances[neighbor]=distance
                    heapq.heappush(heap,(distance,neighbor))
                    
    return distances
n=int(input())            
    
graph=[[0 for i in range(n)]for j in range(n)]
for i in range(n-1):
    a=[int(x) for x in input().split()]
    # print(a)
    graph[a[0]-1][a[1]-1]=a[2]
    graph[a[1]-1][a[0]-1]=a[2]

# print(graph)
w=[int(x) for x in input().split()]
m=dijkstra(w[1]-1,n,graph)
# print(m)
c=0
for i in range(w[0]):
    s=[int(x) for x in input().split()]
    # print(s)
    c=abs(m[s[0]-1])+abs(m[s[1]-1])
    print(c)

### FIXED CODE ###

N=int(input())
import sys
sys.setrecursionlimit(10**6)
T=[[] for _ in range(N)]
for i in range(N-1):
    a,b,c=map(int, input().split())
    T[a-1].append((b-1,c))
    T[b-1].append((a-1,c))

Q,K=map(int, input().split())
D=[-1]*N
D[K-1]=0
def dfs(start, nowd):
    to=T[start]
    for t in to:
        next_node,c=t
        if D[next_node]!=-1:
            continue
        nextd=nowd+c
        D[next_node]=nextd
        dfs(next_node, nextd)
dfs(K-1,0)
# print(D)
for i in range(Q):
    x,y=map(int, input().split())
    print(D[x-1]+D[y-1])