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

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
from functools import lru_cache
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]


N = I()
A = LI()
t = [0, 0, 0]
for a in A:
    t[a-1] += 1
A, B, C = t

dp = [[[0]*(N+1) for i in range(N+1)] for j in range(N+1)]

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if (i==0) and (j==0) and (k==0):
                continue
            dp[i][j][k] += N/(i+j+k)
            d = dp[i][j][k]
            if (i<N):
                dp[i+1][j][k] += (i+1)*d/(i+1+j+k)
            if (i>0) and (j<N):
                dp[i-1][j+1][k] += (j+1)*d/(i+j+k)
            if (j>0) and (k<N):
                dp[i][j-1][k+1] += (k+1)*d/(i+j+k)

print(dp[A][B][C])


### FIXED CODE ###

import sys

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

def main():
    N = I()
    a = LI()
    t = [0, 0, 0]
    for ai in a:
        t[ai-1] += 1
    A, B, C = t
    E = B+C

    dp = [[0 if (i+j==0) else N/(i+j) for j in range(E+1)] for i in range(N+1)]

    for k in range(C+1):
        for i in range(N+1):
            dp[i][E] = 0 if (i+E+k==0) else N/(i+E+k)
        for j in range(E+1):
            for i in range(N+1):
                z = i+j+k
                if (not z):
                    continue
                d = dp[i][j]
                if (i<N):
                    dp[i+1][j] += (i+1)*d/(z+1)
                if (i>0) and (j<E):
                    dp[i-1][j+1] += (j+1)*d/z
                if (j>0) and (k<C):
                    dp[i][j-1] = (k+1)*d/z + N/z

    print(dp[A][B])

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

from collections import deque
import sys
input = sys.stdin.readline


def bfs(table, i, j):
    dq = deque()
    seen = []
    if table[i][j] == "#":
        return -1
    h = len(table)
    w = len(table[0])
    ans = 0
    dq.append((i, j, 0))  # x,y,distance
    while dq:
        x, y, dis = dq.popleft()
        ans = max(ans, dis)
        seen.append((x, y))
        if x > 0 and (x - 1, y) not in seen and table[x - 1][y] != "#":
            dq.append((x - 1, y, dis + 1))
        if x < h - 1 and (x + 1, y) not in seen and table[x + 1][y] != "#":
            dq.append((x + 1, y, dis + 1))
        if y > 0 and (x, y - 1) not in seen and table[x][y - 1] != "#":
            dq.append((x, y - 1, dis + 1))
        if y < w - 1 and (x, y + 1) not in seen and table[x][y + 1] != "#":
            dq.append((x, y + 1, dis + 1))
    return ans


def main():
    h, w = [int(i) for i in input().strip().split()]
    grid = [input().strip() for _ in range(h)]
    ans = -1
    for i in range(h):
        for j in range(w):
            if grid[i][j] == ".":
                max_path = bfs(grid, i, j)
                ans = max(ans, max_path)

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque
 
def main():
    H,W=map(int,input().split())
    S=[]
    for i in range(H):
        s=input()
        S.append(s)
 
    G=[]
    for i in range(H):
        for j in range(W):
            tmp=[]
            if S[i][j]=="#":
                G.append(tmp)
                continue
            if i-1>=0:
                if S[i-1][j]==".":
                    tmp.append((i-1)*W+j)
            if i+1<=H-1:
                if S[i+1][j]==".":
                    tmp.append((i+1)*W+j)
            if j-1>=0:
                if S[i][j-1]==".":
                    tmp.append(i*W+j-1)
            if j+1<=W-1:
                if S[i][j+1]==".":
                    tmp.append(i*W+j+1)
            G.append(tmp)
 
    res=0
 
    for start in range(H*W):
        dist = 0
        v = [-1 for _ in range(H * W)]
        que=deque([])
        que.append(start)
        v[start]=dist
        while len(que)>0:
            next_index=que.popleft()
            next=G[next_index]
            for i in next:
                if v[i]==-1:
                    que.append(i)
                    v[i]=v[next_index]+1
 
        if max(v)>=res:
            res=max(v)
 
    print(res)
 
 
if __name__=="__main__":
    main()
### BUGGY CODE ###

#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


def main():
    n, k = map(int, input().split())

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        for j in range(len(dp[0] + 1)):
            dp[h][j] = dp[h - 1][dp[h - 1][j]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()


### FIXED CODE ###

#!/usr/bin/env python3

import sys
import numpy as np


def main():
    n, k = map(int, sys.stdin.buffer.readline().split())

    warps = list(map(int, sys.stdin.buffer.readline().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        dp[h] = dp[h - 1][dp[h - 1]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()
### BUGGY CODE ###

# ABC 118 D

def resolve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

    dp = [0] * (N+1)
    for i in range(1, N+1):
        for a in A:
            if i - costs[a] < 0:
                continue
            dp[i] = max(dp[i-costs[a]] + 1, dp[i])

    ans = ""
    remain = dp[N]
    match = N

    minCosts = 10
    for a in A:
        minCosts = min(minCosts, costs[a])

    while match > 0:
        for a in A:
            if match - costs[a] < 0 or 1<= match - costs[a] < minCosts:
                continue

            if dp[match-costs[a]] == remain-1:
                ans += str(a)
                match -= costs[a]
                remain -= 1
                break

    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

# ABC 118 D

def resolve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

    dp = [-1] * (N+1)
    dp[0] = 0
    for i in range(1, N+1):
        for a in A:
            if i - costs[a] < 0:
                continue
            dp[i] = max(dp[i-costs[a]] + 1, dp[i])

    ans = ""
    remain = dp[N]
    match = N

    minCosts = 10
    for a in A:
        minCosts = min(minCosts, costs[a])

    while match > 0:
        for a in A:
            if match - costs[a] < 0 or 1<= match - costs[a] < minCosts:
                continue

            if dp[match-costs[a]] == remain-1:
                ans += str(a)
                match -= costs[a]
                remain -= 1
                break

    print(ans)


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

N,C=map(int,input().split())
List=[[int(i) for i in input().split()] for i in range(N)]
Channel=[[]]*C
for i in range(N):
  Channel_kari=list(Channel[List[i][2]-1])
  Channel_kari.append(i)
  Channel[List[i][2]-1]=list(Channel_kari)
Time=[]
for c in range(C):
  T_c=[0]*(10**5)
  for i in Channel[c]:
    T_c[List[i][0]-1:List[i][1]]=[1]*(List[i][1]-List[i][0]+1)
  Time.append(T_c)  
Times_sum=[]
T=0
for t in range(10**5):
  for c in range(C):
    T+=Time[c][t]
  Times_sum.append(T)
  T=0
print(max(Times_sum))

### FIXED CODE ###

N,C=map(int,input().split())
Time=[[0]*(10**5+1) for c in range(C)]
for i in range(N):
  s,t,c=map(int,input().split())  
  Time[c-1][s-1:t] = [1]*(t-s+1)
Times=max(map(sum,zip(*Time)))
print(Times)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
  a.append(int(input())-1)
i=0
seen=[]
out=0
if 1 not in a:
  out=-1
  i=1
while i!=1:
  out+=1
  i=a[i]
  if i in seen:
    out=-1
    break
  seen.append(i)
print(out)


### FIXED CODE ###

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

out=0
kai=0
while i!=1:
  kai+=1
  out+=1
  i=a[i]
  if kai>n:
    out=-1
    break

print(out)
### BUGGY CODE ###

INF = 10**18

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

lt = [-INF for _ in range(K + 1)]
rt = [-INF for _ in range(K + 1)]

j = -1
for i in range(1, K + 1):
    while True:
        j += 1
        if S[j] == 'o' and j - lt[i - 1] > C:
            lt[i] = j
            break

j = -1
for i in range(1, K + 1):
    while True:
        j += 1
        if S[::-1][j] == 'o' and j - rt[i - 1] > C:
            rt[i] = j
            break

lt = lt[1:]
rt = rt[1:]
rt = [N - x - 1 for x in rt][::-1]

res = []

for i in range(K):
    if lt[i] == rt[i]:
        res.append(lt[i] + 1)

print('\n'.join(map(str, res)))

### FIXED CODE ###

INF = 10**18

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

lt = [-INF for _ in range(K + 1)]
rt = [-INF for _ in range(K + 1)]

j = -1
for i in range(1, K + 1):
    while True:
        j += 1
        if S[j] == 'o' and j - lt[i - 1] > C:
            lt[i] = j
            break

j = -1
for i in range(1, K + 1):
    while True:
        j += 1
        if S[-1 - j] == 'o' and j - rt[i - 1] > C:
            rt[i] = j
            break

lt = lt[1:]
rt = rt[1:]
rt = [N - x - 1 for x in rt]
rt = rt[::-1]

res = []

for i in range(K):
    if lt[i] == rt[i]:
        res.append(lt[i] + 1)

print('\n'.join(map(str, res)))
### BUGGY CODE ###

n,m,r=map(int,input().split())
road=list(map(int,input().split()))
cost=[[float("inf")]*n for i in range(n)]
for i in range(n):
    cost[i][i]=0
for i in range(m):
    
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    cost[a][b]=c
    cost[b][a]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
import itertools
ans=float("inf")
for i in itertools.permutations(road):
    tmp=0
    for j in range(len(i)-1):
        tmp+=cost[i[j]-1][i[j+1]-1]
    if tmp<ans:
        ans=tmp
print(ans)

### FIXED CODE ###

n,m,r=map(int,input().split())
road=list(map(int,input().split()))
cost=[[float("inf")]*n for i in range(n)]
for i in range(n):
    cost[i][i]=0
for i in range(m):
    
    a,b,c=map(int,input().split())
    a,b=a-1,b-1
    cost[a][b]=c
    cost[b][a]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j])
import itertools
ans=float("inf")
for i in itertools.permutations(road):
    tmp=0
    for j in range(len(i)-1):
        tmp+=cost[i[j]-1][i[j+1]-1]
    if tmp<ans:
        ans=tmp
print(ans)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
from bisect import bisect_left
ans = 0
for i in range(N):
    a = A[i]
    indb = bisect_left(B,a+1)
    if indb == N:
        continue
    for j in range(indb,N):
        b = B[j]
        indc = bisect_left(C,b+1)
        ans += N-indc
print(ans)
  

### FIXED CODE ###

import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
from bisect import bisect_left
ans = 0
for i in range(N):
    b = B[i]
    inda = bisect_left(A,b)
    indc = bisect_left(C,b+1)
    ans += (N-indc)*inda
print(ans)
### BUGGY CODE ###

import numpy as np
import math as m

def main(**kwargs):
    mod = 10 ** 9 + 7
    facts = [m.factorial(i) % mod for i in range(n+1)]
 
    r = int((2 ** n - 1 - facts[n] / facts[n-a] / facts[a] - facts[n] / facts[n-b] / facts[b]) % mod)
    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, a, b = cin

    cout = main(n=n, a=a, b=b)
    print(cout)

### FIXED CODE ###

import numpy as np
import math as m

def main(**kwargs):
    mod = 10 ** 9 + 7
    r = repeatSquare(2, n, mod) - 1
    r -= factMod(n, n - a + 1, mod) * repeatSquare(factMod(a, 1, mod), mod - 2, mod)
    r -= factMod(n, n - b + 1, mod) * repeatSquare(factMod(b, 1, mod), mod - 2, mod)
    r %= mod
    return r

def repeatSquare(n, p, m):
    if p == 0:
        return 1

    if p % 2 == 0:
        tmp = repeatSquare(n, p/2, m) % m
        return tmp * tmp % m

    return n * repeatSquare(n, p-1, m) % m

def factMod(n, r, m):
    res = n

    while n > r:
        n -= 1
        res *= n
        res %= m

    return res

if __name__ == "__main__":
    
    cin = np.array(input().split(" ")).astype("int")
    n, a, b = cin

    cout = main(n=n, a=a, b=b)
    print(cout)
### BUGGY CODE ###

from functools import reduce
from operator import mul

MOD = 1000000007


def combination(n, r):
  r = min(n - r, r)
  if r == 0:
    return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1, r + 1))

  return over // under


def main():
  N, M, K = [int(i) for i in input().strip().split(' ')]
  c = combination(N * M - 2, K - 2) % MOD
  NNC = N * N % MOD
  MMC = M * M % MOD

  total = 0

  for i in range(M):
    total = (total + (M - i) * i * NNC) % MOD
  for i in range(N):
    total = (total + (N - i) * i * MMC) % MOD

  print(total * c % MOD)


main()

### FIXED CODE ###

def mfactorial(n: int, mod: int) -> int:
  cache = mfactorial.__cache if hasattr(mfactorial, '__cache') else [1, 1]
  n_len = len(cache)
  n_new = n - n_len + 1
  if n_new > 0:
    cache = cache + ([0] * n_new)
    for i in range(n_len, n + 1):
      cache[i] = cache[i - 1] * i % mod
    mfactorial.__cache = cache

  return mfactorial.__cache[n]


def cmb(n, r, mod):
  result = mfactorial(n, mod)
  result *= pow(mfactorial(r, mod), mod - 2, mod) % mod
  result %= mod
  result *= pow(mfactorial(n - r, mod), mod - 2, mod) % mod
  result %= mod

  return result


def main():
  MOD = 10 ** 9 + 7

  N, M, K = [int(i) for i in input().strip().split(' ')]
  c = cmb(N * M - 2, K - 2, MOD)

  X = 0
  Y = 0
  for i in range(M):
    X += (M - i) * i
  for i in range(N):
    Y += (N - i) * i

  total = (X * (N ** 2) + Y * (M ** 2)) % MOD * c % MOD
  print(total)


main()
### BUGGY CODE ###

n=int(input())
S=[input() for _ in range(n)]
S_set = set(S)
setl = sorted(S_set)
cnt=0
ans=[]

for s in S_set:
    cnt1 = S.count(s)
    if cnt < cnt1:
        ans.clear()
        ans.append(s)
        cnt = cnt1
    elif cnt == cnt1:
        ans.append(s)

ans.sort()

for a in ans:
    print(a)

### FIXED CODE ###

n=int(input())

cnt={}
ans=[]

for i in range(n):
    s=input()
    if s in cnt.keys():
        cnt[s] += 1
    else:
        cnt[s] = 1

m=max(cnt.values())
key = sorted(cnt.keys())

for a in key:
    if cnt[a] == m:
        print(a)
### BUGGY CODE ###

import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
count = 0
for i in a:
  for j in range(bisect.bisect_right(b, i), n):
    count += n - bisect.bisect_right(c, b[j])

print(count)

### FIXED CODE ###

import bisect
from itertools import accumulate
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0
b_to_c = [0]*n
for i in range(n):
  b_to_c[i] = n - bisect.bisect_right(C, B[i])
Q = list(accumulate(b_to_c[::-1]))[::-1]
  
for i in A:
  t = bisect.bisect_right(B, i)
  if t < n:
    ans += Q[t]
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(len(bin(a[i]))-2):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=b[i]*(n-b[i])*2**i
print(c%(10**9+7))


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)
### BUGGY CODE ###

import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**10

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, n):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)


### FIXED CODE ###

import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**12

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, int(math.sqrt(n))+1):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)
### BUGGY CODE ###

import bisect


def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    while t:
        candidates = bisect.bisect_left(t, t[0] + k)
        # candidates = len([tj for tj in t if tj <= t[0] + k])
        num = min(c, candidates)
        t = t[num:]
        ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 1
    limit = t[0] + k
    bus = 0
    for i in range(n):
        bus += 1
        if t[i] > limit or bus > c:
            limit = t[i] + k
            ans += 1
            bus = 1
    print(ans)


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

import re


S = input()
L = len(S)

while True:
    T = S[:]
    S = re.sub('10', '', S)
    S = re.sub('01', '', S)
    if S == T:
        break

print(L - len(S))


### FIXED CODE ###

S = input()

print(min(S.count('0'), S.count('1')) * 2)
### BUGGY CODE ###

S = input()

max_S = 10**9 + 7

N_Q = S.count("?")
N_C = S.count("C")

t_A = 0
t_Q = 0
if(S[0:1] == "C"):
    t_C = N_C - 1
else:
    t_C = N_C

S_list = [{"bA": t_A, "bQ": t_Q, "aC": t_C, "aQ": N_Q - t_Q}]
for i in range(1, len(S)):
    if(S[i - 1:i] == "A"):
        t_A += 1
    elif(S[i - 1:i] == "?"):
        t_Q += 1

    ba_dic = {}
    ba_dic["bA"] = t_A
    ba_dic["bQ"] = t_Q
    if(S[i:i + 1] == "?"):
        ba_dic["aQ"] = N_Q - t_Q - 1
    else:
        ba_dic["aQ"] = N_Q - t_Q
    if(S[i:i + 1] == "C"):
        t_C -= 1
    ba_dic["aC"] = t_C

    S_list.append(ba_dic)

ans = 0
for i in range(len(S)):
    if(S[i:i + 1] == "A" or S[i:i + 1] == "C"):
        continue

    bA = S_list[i]["bA"]
    bQ = S_list[i]["bQ"]
    aC = S_list[i]["aC"]
    aQ = S_list[i]["aQ"]

    Q_0 = int(3**(bQ + aQ))
    if(Q_0 == 1):
        Q_1 = 0
        Q_2 = 0
    elif(Q_0 == 3):
        Q_1 = 1
        Q_2 = 0
    else:
        Q_1 = Q_0 // 3
        Q_2 = Q_1 // 3
    ans += Q_0 * bA * aC + bQ * aQ * Q_2 + Q_1 * (bA * aQ + bQ * aC)
    ans = ans % max_S

print(ans)

### FIXED CODE ###

S = input()

d = [0, 0, 0, 1]

max_ans = 10**9 + 7

for c in reversed(S):
    # print(c, d)
    m = [c == "A", c == "B", c == "C", c == "?"]
    if(m[3] is True):
        tmp = 3
    else:
        tmp = 1

    for j in range(3):
        d[j] = (tmp * d[j] + int(m[j] or m[3]) * d[j + 1]) % max_ans
    d[3] = (tmp * d[3]) % max_ans

print(d[0])
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)


N, Q = map(int, input().split())
G = defaultdict(set)
X = defaultdict(int)
P = defaultdict(int)

for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    X[p] += x


def dfs(p, x, parent):

    P[p] += x + X[p]
    for node in G[p]:
        if node == parent:
            continue
        dfs(node, x + X[p], p)


dfs(0, 0, -1)

print(' '.join([str(p) for p in P.values()]))


### FIXED CODE ###

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion

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

v = [[] for i in range(N)]
score = [0]*N

def dfs(cur,par):
  for chi in v[cur]:
    if chi == par:
      continue
    score[chi] += score[cur]
    dfs(chi, cur)
      
for i in range(N-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  v[a].append(b)
  v[b].append(a)

for j in range(Q):
  p, x = map(int, input().split())
  score[p-1] += x

dfs(0,-1)
score_int=[str(a) for a in score]
output= ' '.join(score_int)
print(output)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[]

for i in range(N):
  B.append(A.index(i+1)+1)

print(" ".join(map(str,B)))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
B = [0]*N

for i in range(N):
  B[A[i]-1] = i+1
  
print(" ".join(map(str,B)))