Harryxun/stf_run huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
max_a = 20 ** 2
MOD = 10 ** 9 + 7

ru = [0] * (n + 1)
for i in range(n):
    ru[i + 1] = ru[i] ^ a[i]


if ru[-1] != 0:
    # 0, ru[-1], 0, ru[-1], 0, ..., ru[-1]
    dp = [0] * (max_a)
    dp[0] = 1
    tot_ex0 = 0
    for i in range(n):
        if i == n - 1:
            print(dp[0])
            exit()
        if ru[i + 1] == 0:
            dp[0] += tot_ex0
            dp[0] %= MOD
        elif ru[i + 1] == ru[-1]:
            dp[ru[i + 1]] += dp[0]
            dp[ru[i + 1]] %= MOD
            tot_ex0 += dp[0]
            tot_ex0 %= MOD
else:
    # 0, x, 0, x, 0, x, ..., 0 (x != 0)
    dp = [0] * max_a
    dq = [1] * max_a
    set_evaled = [0] * max_a
    times = 0
    ans = 0
    for i in range(n):
        if i == n - 1:
            ans = sum(dp)
            break
        elif ru[i + 1] == 0:
            # これを遅延評価する
            # for j in range(max_a):
            #     dq[j] += dp[j]
            times += 1
        else:
            dq[ru[i + 1]] += (times - set_evaled[ru[i + 1]]) * dp[ru[i + 1]]
            dq[ru[i + 1]] %= MOD
            set_evaled[ru[i + 1]] = times
            dp[ru[i + 1]] += dq[ru[i + 1]]
            dp[ru[i + 1]] %= MOD
    # 0, 0, 0, 0, 0, 0, ..., 0
    cnt_0 = sum([1 for i in range(n) if ru[i + 1] == 0])
    ans = (ans + pow(2, cnt_0 - 1, MOD)) % MOD
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
max_a = 2 ** 20
MOD = 10 ** 9 + 7

ru = [0] * (n + 1)
for i in range(n):
    ru[i + 1] = ru[i] ^ a[i]


if ru[-1] != 0:
    # 0, ru[-1], 0, ru[-1], 0, ..., ru[-1]
    dp = [0] * (max_a)
    dp[0] = 1
    tot_ex0 = 0
    for i in range(n):
        if i == n - 1:
            print(dp[0])
            exit()
        if ru[i + 1] == 0:
            dp[0] += tot_ex0
            dp[0] %= MOD
        elif ru[i + 1] == ru[-1]:
            dp[ru[i + 1]] += dp[0]
            dp[ru[i + 1]] %= MOD
            tot_ex0 += dp[0]
            tot_ex0 %= MOD
else:
    # 0, x, 0, x, 0, x, ..., 0 (x != 0)
    dp = [0] * max_a
    dq = [1] * max_a
    set_evaled = [0] * max_a
    times = 0
    ans = 0
    for i in range(n):
        if i == n - 1:
            ans = sum(dp)
            break
        elif ru[i + 1] == 0:
            # これを遅延評価する
            # for j in range(max_a):
            #     dq[j] += dp[j]
            times += 1
        else:
            dq[ru[i + 1]] += (times - set_evaled[ru[i + 1]]) * dp[ru[i + 1]]
            dq[ru[i + 1]] %= MOD
            set_evaled[ru[i + 1]] = times
            dp[ru[i + 1]] += dq[ru[i + 1]]
            dp[ru[i + 1]] %= MOD
    # 0, 0, 0, 0, 0, 0, ..., 0
    cnt_0 = sum([1 for i in range(n) if ru[i + 1] == 0])
    ans = (ans + pow(2, cnt_0 - 1, MOD)) % MOD
    print(ans)
input();*a,=map(int,input().split());print(sum(a[a[i]-1]==i+1for i in range(len(a)))>>1)

### FIXED CODE ###

s=input()
print(s[:4]+' '+s[4:])
a=int(input())
s=int(input())
if a >= 3200:
    print(s)
else:
    print('red')

### FIXED CODE ###

a=int(input())
s=input()
if a >= 3200:
    print(s)
else:
    print('red')
from collections import deque

s=input()
sd=deque(s)
d=deque()
while(len(sd)>0):
  crr = sd.popleft()
  if(len(d)<1):
    d.append(crr)
    continue
    if(len(d)>=1 and d[-1]!=crr):
      d.pop()
      else:
        d.append(crr)
print(len(s)-len(d))

### FIXED CODE ###

from collections import deque
 
s=input()
sd=deque(s)
d=deque()
while(len(sd)>0):
  crr = sd.popleft()
  if(len(d)<1):
    d.append(crr)
    continue
  if(len(d)>=1 and d[-1]!=crr):
    d.pop()
  else:
    d.append(crr)
print(len(s)-len(d))
a, b, c, d = map(int, input().split())
end = min((a + b),(c + d))
start max(a,c)
r = max(0, end - start)
print(r)


### FIXED CODE ###

a, b, c, d = map(int, input().split())

start = max(a, c)
end = min(b, d)

r = max(0, end - start)
print(int(r))
a,b = map(int,input().split())
print "error" if a+b >=10 else print(a+b)

### FIXED CODE ###

a,b = map(int,input().split())
print ("error") if a+b >=10 else print(a+b)
mport numpy as np
import math

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

d = np.sqrt((B*math.cos(6*M)-A*math.cos(30*H+M/2))**2+ (B*math.sin(6*M)-A*math.sin(30*H+M/2))**2)
print(d)

### FIXED CODE ###

import numpy as np
import math


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

d = np.sqrt((B*math.cos(math.radians(6*M))-A*math.cos(math.radians(30*H+M/2)))**2+(B*math.sin(math.radians(6*M))-A*math.sin(math.radians(30*H+M/2)))**2)
print(d)
from collections import deque
n,m,k = map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
la = deque(la)
lb = deque(lb)
inf = float("inf")
dp = [[-inf]*(k+1) for _ in range(n+m+1)]
for j in range(k+1):
    dp[0][j] = 0
for i in range(n+m):
    if la != deque([]) and lb != deque([]):
        if la[0] <= lb[0]:
            s = la.popleft()
        else:
            s = lb.popleft()
    elif la != deque([]) and lb == deque([]):
        s = la.popleft()
    elif la == deque([]) and lb != deque([]):
        s = lb.popleft()
    elif la == deque([]) and lb == deque([]):
        break
    for l in range(k+1):
        if l-s >=0:
            dp[i+1][l] = max(dp[i][l],dp[i][l-s]+1)
        else:
            dp[i+1][l] = dp[i][l]
a = 0
for p in range(n+m+1):
    if a < max(dp[p]):
        a = max(dp[p])
print(a)        

### FIXED CODE ###

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    if la[i] + a[i] > k:
        break
    la.append(la[i]+a[i])
for j in range(m):
    if lb[j] + b[j] > k:
        break
    lb.append(lb[j]+b[j])
now = len(lb)-1
for l in range(len(la)):
    cnt = l
    q = now
    while la[l] + lb[q] > k:
        q -= 1
    now = q
    cnt += q
    if cnt > mx:
        mx = cnt
print(mx)
import sys
n,m = map(int,input().split())
a = []
for i in range(m):
    a.append(int(input()))
fib = [1,1]
for i in range(n):
    fib.append((fib[i]+fib[i+1])%1000000007)
if m == 0:
	print(fib[n])
    sys.exit()
answer = fib[a[0]-1]
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        answer = 0
    else:
        answer = answer * fib[a[i+1]-a[i]-2] % 1000000007
answer = answer * fib[n-a[m-1]-1] % 1000000007
print(answer)

### FIXED CODE ###

p,q,r = map(int, input().split())
print(min(p+q,q+r,r+p))
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
    
for i in range(101):
    for j in range(101):
        x,y,h = xyh[0]
        H = h + abs(x-i) + abs(y-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xyh = [None]*n
for i in range(n):
    x,y,h = map(int, input().split())
    xyh[i] = (x,y,h)
ans = []
bx,by,bh = max(xyh, key=lambda p: p[2])
for i in range(101):
    for j in range(101):
        H = bh + abs(bx-i) + abs(by-j)
        bad = False
        for x,y,h in xyh:
            if max(0, H - abs(x-i) - abs(y-j))!=h:
                bad = True
                break
        if bad:
            pass
        else:
            ans = (i,j,H)
            break
    if not bad:
        break
print(" ".join(map(str, ans)))
s = int(input())
while s >0:
  if s%7 == 0:
    print('Yes')
    break
  s -= 4
    
if s<0:
  print('No')

### FIXED CODE ###

N,K = map(int,input().split())
if N%K == 0:
  print(0)
  
else:
  print(1)
n, m = int(input())

S = set(range(1, m+1))

for i in range(n):
  K, *a = map(int, input().split())
  S = S & set(A)

print(len(S))

### FIXED CODE ###

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

S = set(range(1, m + 1))

for i in range(n):
    K, *a = map(int, input().split())
    S = S & set(a)

print(len(S))
n = list(str(input()))
k = int(input())
for i in range(n):
  if n[i] != "1":
    print(n[i])
    exit()
print("1")

### FIXED CODE ###

n = list(str(input()))
k = int(input())
for i in range(min(k,len(n))):
  if n[i] != "1":
    print(n[i])
    exit()
print("1")
n = input()
ans = 0

for i in range(1, n+1):
  if i%3!=0 and i%5!=0:
    ans += i
    
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0

for i in range(1, n+1):
  if i%3!=0 and i%5!=0:
    ans += i
    
print(ans)
n = int(input())
l = [list(list(input())) for _ in range(n)]

x = []
for i in range(len(l[0])):
    if (l[0][i] in l[1]) and (l[0][i] in l[2]):
        x.append(l[0][i])
        l[1].remove(l[0][i])
        l[2].remove(l[0][i])

print(''.join(sorted(x)))

### FIXED CODE ###

n = int(input())
l = [list(list(input())) for _ in range(n)]

l = sorted(l, key = len)

x = []
for i in range(len(l[0])):
    y = 0
    for j in range(n):
        if l[0][i] in l[j]:
            y +=1
            if y == n:
                x.append(l[0][i])
                for k in range(1, n):
                    l[k].remove(l[0][i])

print(''.join(sorted(x)))
def main():
  n, m = map(int, input().split())
  data = [[int(e) for e in input().split()] for _ in range(n)]
  d1 = {}
  for i in range(n):
    a, b = data[i]
    if a not in d1:
      d1[a] = []
    d1[a].appned(b)
  result = 0
  d2 = {}
  for i in range(1, m + 1):
    if i in d1:
      for j not in d1[i]:
        if j in d2:
          d2[j] = 0
        d2[j] += 1
    if len(d2.keys()) == 0:
      continue
    maxb = max(d2.keys())
    result += maxb
    if d2[maxb] == 1:
      del d2[maxb]
main()


### FIXED CODE ###

n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)
def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0]*(n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def sum(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s

    N,Q = map(int,input().split())
    bit = BIT(N)
    C = list(map(int,input().split()))
    query = []
    for i in range(Q):
        l,r = map(int,input().split())
        query.append([l,r,i])
    query.sort(key=lambda x: x[1])
    ans = []
    #良い玉のindexを1-indexで管理する
    colorMemo = [0]*(N+1)
    i = 1
    for _ in range(Q):
        l,r,j = query[j]
        #良い玉の情報を更新する
        while i <= r:
            c = C[i-1]
            if colorMemo[c]:
                bit.add(colorMemo[c],-1)
            bit.add(i,1)
            colorMemo[c] = i
            i += 1
        ans.append([j,bit.sum(r)-bit.sum(l-1)])

    ans.sort()
    for a in ans:
        print(a)
main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    class BIT:
        def __init__(self,n):
            self.tree = [0]*(n+1)
            self.size = n
        
        def add(self,i,x):
            while i <= self.size:
                self.tree[i] += x
                i += i&-i
        
        def sum(self,i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i&-i
            return s

    N,Q = map(int,input().split())
    bit = BIT(N)
    C = list(map(int,input().split()))
    query = []
    for i in range(Q):
        l,r = map(int,input().split())
        query.append([l,r,i])
    query.sort(key=lambda x: x[1])
    ans = [0]*Q
    #良い玉のindexを1-indexで管理する
    colorMemo = [0]*(N+1)
    cur = 1
    for q in query:
        l,r,j = q
        #良い玉の情報を更新する
        for i in range(cur,r+1):
            c = C[i-1]
            if colorMemo[c]:
                bit.add(colorMemo[c],-1)
            bit.add(i,1)
            colorMemo[c] = i
        cur = r + 1
        ans[j]=bit.sum(r)-bit.sum(l-1)

    print(*ans, sep="\n")
main()
a,b=map(int,input().split())
print(int(a*b))

### FIXED CODE ###

import math
a,b=input().split()
b=b[0]+b[2:]
print(int(a)*int(b)//100)
imort sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**10]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])



### FIXED CODE ###

import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i-j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[n-1])
n=int(input())  #数値入力 「N」だけの入力のとき
#n=11
#l=len(str(n))
if l ==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(9+n-99)
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+n-9999)
elif l==6:
    print(9+900+90000)
    

### FIXED CODE ###

n=int(input())  #数値入力 「N」だけの入力のとき
#n=11
l=len(str(n))
if l ==1:
    print(n)
elif l==2:
    print(9)
elif l==3:
    print(9+n-99)
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+n-9999)
elif l==6:
    print(9+900+90000)
a = {"1":9,"9":1}
z = input()
m = ""
for i in z:
  m += a[i]

print(m)

### FIXED CODE ###

a = {"1":"9","9":"1"}
z = input()
m = ""
for i in z:
  m += a[i]

print(m)
n, m = map(int, input().split())
d = {i+1 : [] for i  in range(n)}
for _ in range(m):
    u, v = map(int, input().split())
    d[u].append(v)
s, t = map(int, input().split())
q = [s]
visited = set([s])
def calc(c):
    global visited
    if len(q) == 0:
        return -1
    for i, v in enumerate(q[:]):
        q.pop(i)
        es = [e3 for e1 in d[v] for e2 in d[e1] for e3 in d[e2] if not e3 in visited]
        if t in es:
            return c
        else:
            visited |= set(es)
            q.extend(es)
    return calc(c + 1)
print(calc(1))


### FIXED CODE ###

n, m = map(int, input().split())
d = {i+1 : [] for i  in range(n)}
for _ in range(m):
    u, v = map(int, input().split())
    d[u].append(v)

visited1 = [False for i in range(n+1)]
visited2 = [False for i in range(n+1)]
visited3 = [False for i in range(n+1)]

s, t = map(int, input().split())
q = set([s])
c = 1
def solve():
    global visited1, visited2,visited3,  c, q
    while True:
        q2 = list(q)
        q = set([])
        for v in q2:
            for e1 in d[v]:
                if visited1[e1]:
                    continue
                visited1[e1] = True
                for e2 in d[e1]:
                    if visited2[e2]:
                        continue
                    visited2[e2] = True
                    for e3 in d[e2]:
                        if visited3[e3]:
                            continue
                        visited3[e3] = True
                        if e3 == t:
                            return c
                        else:
                            q.add(e3)
        if not len(q):
            return -1
        c += 1
print(solve())
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = sorted(map(int, readline().split()))

def main(A):
    N = len(A)
    if A[0] == A[-1]:
        raise
        x = A[0]
        return x == N - 1 or 2 * x <= N
    if A[0] + 1 != A[-1]:
        return False
    a, b = A[0], A[-1]
    full = b
    unique = sum(x == a for x in A)
    return N - unique >= 2 * a

print('Yes' if main(A) else 'No')

### FIXED CODE ###

import sys
input = sys.stdin.readline

from collections import Counter

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

x = min(A)
y = max(A)

if x == y:
    # 全員がnon-uniqueな色 or 全員がuniqueな色
    bl = (x <= N//2) or (x == N-1)
elif y != x + 1:
    bl = False
else:
    a = A.count(x)
    b = A.count(y)
    # a人：unique color
    # b人：non-unique color
    # b人でc種類あるとする
    c = y - a
    bl = (1 <= c <= b//2)

answer = 'Yes' if bl else 'No'
print(answer)
a,b,c = map(int, input().split())
if a + b + 4*a*b < c:
  print("Yes")
else:
  print("No)

### FIXED CODE ###

a,b,c = map(int, input().split())
d = c-a-b
if d > 0 and d**2 > 4*a*b:
  print("Yes")
else:
  print("No")
#一時間以上かかった
#一つだけTLE
#そっから30ぷん

from scipy.special import comb
n,m=[int(i) for i in input().split()]
a1=[int(input()) for i in range(m)]
a1.append(n+1)
c1=1
a2=0
for i in range(m+1):
    a3=a1[i]-1-a2
    c2=0
    for j in range(0,a3//2+1):
        c2+=comb(a3-j,j,exact=True)
    c1=(c1*c2)%(1000000007)
    a2=a1[i]+1
    if c1==0:
        break



print(c1)


### FIXED CODE ###

#フィボナッチ数列か…
#c問題も解けないのか…
#典型問題なんだろうな
#踏めない段の分は除いて考えれば良い
n,m=input().split()
n,m=int(n),int(m)
ax=[1]*(n+1)
for i in range(m):
    ax[int(input())]=0
bx=[1,1]
for i in range(2,n+1):
    if ax[i-1]==1:
        f1=bx[i-1]
    else:
        f1=0
    if ax[i-2]==1:
        f2=bx[i-2]
    else:
        f2=0
    bx.append((f1+f2)%(10**9+7))

print(bx[n])
s = str(input())
k = int(input())
if k <= len(s):
    if s[:k] == ["1"]*k:
        ans = "1"
    else:
        ans = s[:k].replace("1", "")[0]
else:
    ans = s.replace("1", "")[0]
print(ans)

### FIXED CODE ###

s = str(input())
k = int(input())
ans = None
for i in range(k):
    if s[i] != "1":
        ans = s[i]
        break
if ans != None:
    print(ans)
else:
    print("1")
n = input()
li = list(str(n))
li = list(map(int, li))
sn = sum(li)
if ( n % sn ): print("Yes")
else: print("No")

### FIXED CODE ###

n = int(input())
li = list(str(n))
li_ = [int(i) for i in li]
allSum = sum(li_)
if not n % allSum: print("Yes")
else: print("No")
import sys
input = sys.stdin().readline()

N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    print(A.index(i+1) +1, end =' ')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
  ans[a[i]-1] = i +1
for i in range(n):
  print(ans[i])
n = int(input())
l = [int(i) for i in input().split()]

if max(l) < sum(l) - max(l) :
    print("Yes")
else:
    print("no")

### FIXED CODE ###

t, x = map(int, input().split())
print(t / x)
def calc_parents(N, adj_nodes, root=0):
    parents = [-1 for _ in range(N)]
    frontier = [root]
    parents[root] = root
    while len(frontier) > 0:
        node = frontier.pop()
        for child in adj_nodes[node]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = node
    return parents


def sum_counts(N, parents, counter_roots):
    counter = [0 for _ in range(N)]
    for node in range(N):
        current_node = node
        parent_node = parents[current_node]
        s = counter_roots[current_node]
        while current_node != parent_node:
            current_node = parent_node
            parent_node = parents[current_node]
            s += counter_roots[current_node]
        counter[node] += s
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    parents = calc_parents(N, adj_nodes)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    counter = sum_counts(N, parents, counter_roots)
    print(' '.join(map(str, counter)))


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import defaultdict


def sum_counter(N, adj_nodes, counter_roots, root=0):
    parents = [-1 for _ in range(N)]
    counter = [0 for _ in range(N)]
    frontier = [root]
    counter[root] += counter_roots[root]
    parents[root] = root
    while len(frontier) > 0:
        parent = frontier.pop()
        for child in adj_nodes[parent]:
            if parents[child] >= 0:
                continue
            frontier.append(child)
            parents[child] = parent
            counter[child] += counter[parent] + counter_roots[child]
    return counter


def main():
    N, Q = list(map(int, input().split(' ')))
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    counter_roots = [0 for _ in range(N)]
    for _ in range(Q):
        p, x = list(map(int, input().split(' ')))
        p -= 1
        counter_roots[p] += x
    c = sum_counter(N, adj_nodes, counter_roots)
    print(' '.join(map(str, c)))


if __name__ == '__main__':
    main()
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i = i + 1
            a[i], a[j] = a[j], a[i]
    a[i+1], a[r] = a[r], a[i+1]
    return i+1

n = int(input())
a = list(map(int, input().split()))
m = partition(a, 0, n-1)
a[m] = "[%s]"%(a[m])
print(" ".join(a))

### FIXED CODE ###

def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i = i + 1
            a[i], a[j] = a[j], a[i]
    a[i+1], a[r] = a[r], a[i+1]
    return i+1

n = int(input())
a = list(map(int, input().split()))
m = partition(a, 0, n-1)
a = list(map(str, a))
a[m] = "[%s]"%(a[m])
print(" ".join(a))
def visit(u):
    global visit_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        if (color[v] == WHITE):
            visit(v)
    color[u] = BLACK
    f[u] = t
    t += 1

n = int(input())
M = [[False for i in range(n)] for i in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]):
        M[tmp[0]-1][tmp[i+2]-1] = 1

WHITE = 0
GRAY = 1
BLACK = 2
color, d, f = [WHITE for i in range(n)]
t = 1
for u in range(n):
    if (color[u] == WHITE):
        visit(u)
for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ")

### FIXED CODE ###

def dfs(u):
    global dfs_color, d, f, t
    color[u] = GRAY
    d[u] += t
    t += 1
    for v in range(n):
        if (M[u][v] == 0):
            continue
        else:
            if (color[v] == WHITE):
               dfs(v)
    color[u] = BLACK
    f[u] = t
    t += 1

n = int(input())
M = [[False for i in range(n)] for j in range(n)]
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(tmp[1]):
        M[tmp[0]-1][tmp[j+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for i in range(n)]
d = [0 for i in range(n)]
f = [0 for i in range(n)]
t = 1

for u in range(n):
    if (color[u] == WHITE):
        dfs(u)
for u in range(n):
    print(str(u+1), str(d[u]), str(f[u]), sep = " ")