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

t = input()
ans = 0
for i in range(len(t)):
    if t[i]=='P':
        if i+1 < len(t) and t[i+1]=='?':
            # t[i+1] = 'D'
            t = t[:i+1] + 'D' + t[i+2:]
            ans += 1
            # print('a')
        else:
            ans += 1
            # print('b')
        
    
    elif t[i]=='?':
        if i+1 < len(t)  and (t[i+1]=='D' or t[i+1]=='?'):
            # t[i] = 'P'
            t = t[:i] + 'P' + t[i+1:]
            ans += 1
            # print('c')
        else:
            # t[i] = 'D'
            t = t[:i] + 'D' + t[i+1:]
            ans += 1
            # print('d')

    elif t[i]=='D':
        ans += 1
        # print('e')

print(t)
# print(ans)

### FIXED CODE ###

t = input()
ans = 0
t = list(t)
for i in range(len(t)):
    if t[i]=='P':
        if i+1 < len(t) and t[i+1]=='?':
            t[i+1] = 'D'
            # t = t[:i+1] + 'D' + t[i+2:]
            ans += 1
            # print('a')
        else:
            ans += 1
            # print('b')
        
    
    elif t[i]=='?':
        if i+1 < len(t) and i > 0 and t[i-1] == 'P' and (t[i+1]=='D' or t[i+1]=='?'):
            t[i] = 'D'
            ans += 1
            # print('f')
        elif i+1 < len(t)  and (t[i+1]=='D' or t[i+1]=='?'):
            t[i] = 'P'
            # t = t[:i] + 'P' + t[i+1:]
            ans += 1
            # print('c')
        else:
            t[i] = 'D'
            # t = t[:i] + 'D' + t[i+1:]
            ans += 1
            # print('d')

    elif t[i]=='D':
        ans += 1
        # print('e')
p = ''
for i in t:
    p += i
print(p)
# print(ans)
### BUGGY CODE ###

from collections import deque
def main():
    n,m=map(int,input().split())
    g=[[] for i in range(n)]
    for i in range(m):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        g[a].append([b,c])
        g[b].append([a,-c])
    inf=10**10
    v=[inf]*n
    while max(v)==inf:
        s=v.index(inf)
        q=deque([s])
        v[s]=0
        while q:
            p=q.popleft()
            for i in g[p]:
                if v[i[0]]==inf:
                    v[i[0]]=v[p]+i[1]
                    q.append(i[0])
                else:
                    if v[i[0]]!=v[p]+i[1]:
                        return 'No'
    return 'Yes'
                            
  
print(main())


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 5+1)


def dfs(p):
    for edge in G[p]:
        if X[edge[0]] is not None:
            if X[edge[0]] - X[p] != edge[1]:
                print('No')
                exit()
        else:
            X[edge[0]] = X[p] + edge[1]
            dfs(edge[0])


N, M = map(int, input().split())
G = [[] for _ in range(N)]

for i in range(M):
    L, R, D = map(int, input().split())
    L -= 1
    R -= 1
    G[L].append((R, D))
    G[R].append((L, -D))

X = [None] * N
for i in range(N):
    if X[i] is None:
        X[i] = 0
        dfs(i)

print('Yes')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, k = LI()
    g = [[] for i in range(n+1)]
    for i in range(n-1):
        a, b = LI()
        g[a].append(b)
        g[b].append(a)

    s = 1
    Q = [s]
    ans = k
    Qappend = Q.append
    searched = [0 for i in range(n+1)]
    searched[s] = 1
    v = Q.pop()
    cand = k - 1
    for i in g[v]:
        if searched[i] == 1:
            continue
        searched[i] = 1
        ans *= cand
        cand -= 1
        Qappend(i)
        ans = ans % MOD
    cand = k - 2
    while len(Q) != 0:
        for i in g[v]:
            if searched[i] == 1:
                continue
            searched[i] = 1
            ans *= cand
            cand -= 1
            Qappend(i)
        ans = ans % MOD
    print(ans % MOD)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF=10**9+7
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, k = LI()
    graph=[[] for i in range(n)]
    for i in range(n-1):
        a,b=LI()
        graph[a-1].append(b-1)
        graph[b-1].append(a-1)
    ans=1
    check=[False]*n
    stack=[0]
    ans=1
    while len(stack)>0:
        x=stack.pop()
        check[x]=True
        count=0
        for i in graph[x]:
            if not check[i]:
                count+=1
                stack.append(i)
        if x==0:
            temp=1
            for i in range(count):
                temp=temp*(k-1-i)%INF
            ans=ans*temp%INF
        else:
            temp=1
            for i in range(count):
                temp=temp*(k-2-i)%INF
            ans=ans*temp%INF
    print((ans*k)%INF)


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

N=int(input())
l=10**9+7
nums=list(map(int,input().split()))
k=len(str(bin(max(nums))))-2
mat=[]
for each in nums:
    num=str(bin(each))[2:].zfill(k)
    mat.append(list(num))

mat=list(zip(*mat))
ans=0

for i in range(k):
    b=mat[i].count("1")
    ans+=b*(N-b)*pow(2,(k-i-1),l)
print(ans%l)

### FIXED CODE ###

mod=10**9+7
N=int(input())
str_a = ''.join(['{:060b}'.format(a) for a in map(int, input().split())])

ans=0
for i in range(60):
    ones=str_a[59-i::60].count("1")
    ans+= pow( 2, i ,mod)* ones *(N-ones)
print(ans%mod)
### BUGGY CODE ###

#!python3

import sys

from bisect import bisect, insort_left

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    S = list(input())
    Q = int(input())

    c0 = ord('a')
    S1 = [[] for i in range(26)]
    for i, c1 in enumerate(S):
        ci = ord(c1) - c0
        S1[ci].append(i)

    ans = []
    for cmd, i, j in (line.split() for line in sys.stdin):
        i = int(i) - 1
        if cmd == "1":
            c1 = ord(S[i]) - c0
            s1 = S1[c1]
            s1.remove(i)
            S[i] = j
            c1 = ord(j) - c0
            insort_left(S1[c1], i)
        elif cmd == "2":
            j = int(j) - 1
            num = 0

            for s1 in S1:
                ls = len(s1)
                k = bisect(s1, i-1, 0, ls)

                if k == ls:
                    continue
                if i <= s1[k] <= j:
                    num += 1

            ans.append(num)

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys

from bisect import bisect, insort_left

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    S = list(input())
    Q = int(input())

    c0 = ord('a')
    S1 = [[] for i in range(26)]
    for i, c1 in enumerate(S):
        ci = ord(c1) - c0
        S1[ci].append(i)

    ans = []
    for cmd, i, j in (line.split() for line in sys.stdin):
        i = int(i) - 1
        if cmd == "1":
            if S[i] == j:
                continue

            c1 = ord(S[i]) - c0
            s1 = S1[c1]
            s1.pop(bisect(s1, i)-1)
            S[i] = j
            c1 = ord(j) - c0
            insort_left(S1[c1], i)
        elif cmd == "2":
            j = int(j) - 1
            num = 0

            for s1 in S1:
                ls = len(s1)
                k = bisect(s1, i-1, 0, ls)

                if k == ls:
                    continue
                if i <= s1[k] <= j:
                    num += 1

            ans.append(num)

    print(*ans, sep="\n")

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

import copy
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 1
for i in range(len(a)):
  cnt = 1
  b = copy.deepcopy(a)
  rm = a[i]
  b.remove(rm)
  cnt += b.count(rm-1)+b.count(rm+1)
  ans = max(ans, cnt)
print(ans)

### FIXED CODE ###

N = int(input())
a = [int(x) for x in input().split()]
memo = [0]*(10**5+2)
ans = 1
for i in range(N):
  memo[a[i]] += 1
  memo[a[i]+1] += 1
  memo[a[i]-1] += 1
print(max(memo))
### BUGGY CODE ###

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

B = [[A[i],(i+1)] for i in range(N)]
B.sort()
ans=''
for i in range(N-1):
  ans = ans + str(B[i][1])+' '
ans = ans + str(B[N-1][1])
print(ans)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
B=[0]*N
for i in range(N):
  B[A[i]-1]=i+1
print(*B)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

"""
それぞれの隣接2列ごとに、可能な摩擦の最小値を実現する → 小問題に分割。
"""

H,W = map(int,input().split())
C = np.array([list(input().rstrip()) for _ in range(H)])

equal = np.empty((H,H,W-1),dtype=np.bool)
for n in range(W-1):
    equal[:,:,n] = (C[:,n][:,None] == C[:,n+1][None,:])
dp_1 = np.zeros((H+H+1,H+H+1,W-1),dtype=np.int64)
L = np.arange(1,H+1)
R = np.arange(1,H+1)
dp_1[R[None,:]-L[:,None]+H,R[None,:]+L[:,None],:] = equal
np.cumsum(dp_1,out=dp_1,axis=1)

INF = 10**18
# R-L+H -> min cost
dp = np.full((H+H+1,W-1),INF,dtype=np.int64)
dp[H] = 0
for n in range(1,H+H+1):
    # n個目を置く
    prev = dp
    dp = np.full((H+H+1,W-1),INF,dtype=np.int64)
    dp[1:,:] = np.minimum(dp[1:,:],prev[:-1,:])
    dp[:-1,:] = np.minimum(dp[:-1,:],prev[1:,:])
    dp += dp_1[:,n,:]

answer = dp[H].sum()
print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

"""
それぞれの隣接2列ごとに、可能な摩擦の最小値を実現する → 小問題に分割。
"""

buffer = sys.stdin.buffer
H,W = map(int,buffer.readline().split())
C = np.frombuffer(buffer.read(),dtype='S1').reshape(H,-1)[:,:W].T

dp_1 = np.zeros((W-1,H+H+1,H+1),dtype=np.int64)
for r in range(H):
    dp_1[:,r+2:r+H+2,r+1] = (C[:-1] == C[1:,r][:,None])

INF = 10**18
# R-L+H -> min cost
dp = np.full((W-1,H+1),INF,dtype=np.int64)
dp[:,0] = 0
for n in range(1,H+H+1):
    if n >= 2:
        dp_1[:,n,1:] += dp_1[:,n-2,:-1]
    # n個目を置く
    prev = dp
    dp = np.full((W-1,H+1),INF,dtype=np.int64)
    dp[:,1:] = np.minimum(dp[:,1:],prev[:,:-1])
    dp[:,:] = np.minimum(dp[:,:],prev[:,:])
    dp += dp_1[:,n,:]
answer = dp[:,H].sum()
print(answer)
### BUGGY CODE ###

n,m=map(int,input().split())
item=list(map(int,input().split()))
while 1:
    if m==0:break
    else:
        add=item.index(max(item))
        item[add]=item[add]//2
        m -=1

print(sum(item))

### FIXED CODE ###

import heapq
n,m=map(int,input().split())
item=list(map(lambda x: -int(x),input().split()))
heapq.heapify(item)
for i in range(m):
    a=-heapq.heappop(item)
    a //=2
    heapq.heappush(item,-a)

print(-sum(item))
### BUGGY CODE ###

S=input()

ans = 0
for i in range(len(S)):
    for j in range(i+4,len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            ans+=1
            j+3

print(ans)



### FIXED CODE ###

from collections import defaultdict
 
 
def solve2(s):
    ans = 0
    for i, c in enumerate(s):
        if c in '02468':
            ans += i + 1
    return ans
 
 
def solve5(s):
    ans = 0
    for i, c in enumerate(s):
        if c in '05':
            ans += i + 1
    return ans
 
 
def solve_other(s, p):
    reminders = defaultdict(lambda: 0)
    tmp = 0
    mul = 1
    for c in s[::-1]:
        c = int(c)
        tmp = (tmp + c * mul) % p
        mul = mul * 10 % p
        reminders[tmp] += 1
    reminders[0] += 1
    ans = 0
    for r, cnt in reminders.items():
        ans += cnt * (cnt - 1) // 2
    return ans
 
 

s = input()
n = len(s)
p = 2019


if p == 2:
    print(solve2(s))
elif p == 5:
    print(solve5(s))
else:
    print(solve_other(s, p))
### BUGGY CODE ###

n=int(input())
s=list(map(int,input().split()))
for i in range(n):
  print(s.count(i+1))


### FIXED CODE ###

n=int(input())
s=list(map(int,input().split()))
k=[0]*n
for i in s:
  k[i-1]+=1
for i in k:
  print(i)
### BUGGY CODE ###

from collections import deque
import copy

def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]


    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append([y,x-1])
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append([y,x+1])
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append([y-1,x])
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append([y+1,x])

        if nque:
            que = copy.copy(nque)
        else:
            break

    print(count - 1)

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque
import copy

def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]


    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))

        if nque:
            que = copy.copy(nque)
        else:
            break

    print(count - 1)

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

L1 = input().split(" ")
L2 = input().split(" ")
tickets = int(L1[1])
L2int = [int(s) for s in L2]

for t in range(tickets):
    M = max(L2int)
    L2int[L2int.index(M)] = M//2
print(sum(L2int))

### FIXED CODE ###

import heapq
 
L1 = input().split(" ")
L2 = input().split(" ")
tickets = int(L1[1])
L2int = [-int(s) for s in L2]
 
heapq.heapify(L2int)
 
for t in range(tickets):
    heapq.heappush(L2int,-(-heapq.heappop(L2int)//2))
print(-sum(L2int))
### BUGGY CODE ###

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

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


A.sort()
for _ in range(M):
    A[N-1] = A[N-1] // 2
    A.sort()

print(sum(A))  




### FIXED CODE ###

import heapq

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

A = [int(i)*-1 for i in input().split()]
heapq.heapify(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  heapq.heappush(A,(max//2)*-1)





print(sum(A)*-1)
### BUGGY CODE ###

N, W = [int(i) for i in input().split(' ')]
w = []
v = []
for i in range(N):
    new_w, new_v = [int(i) for i in input().split(' ')]
    w.append(new_w)
    v.append(new_v)
    
dp = [[-1 for j in range(W+1)] for i in range(N)]
for j in range(W+1):
    if w[0]<=j:
        dp[0][j] = v[0]
    else:
        dp[0][j] = 0

def rec(i, j):
    if not dp[i][j] == -1:
        return dp[i][j]
    if w[i]<=j:
        dp[i][j] = max(rec(i-1, j), rec(i-1, j-w[i])+v[i])
        #print(i, j, rec(i-1, j), rec(i-1, j-w[i])+v[i])
        return dp[i][j]
    else:
        dp[i][j] = rec(i-1, j)
        return dp[i][j]

print(rec(N-1,W))

### FIXED CODE ###

import copy
N, W = [int(i) for i in input().split(' ')]
dic = {}
dic_num = {}
dic4calc  = {}

for i in range(N):
    new_w, new_v = [int(i) for i in input().split(' ')]
    if new_w in dic:
        dic[new_w].append(new_v)
    else:
        dic[new_w] = [new_v]
        
w = sorted(list(dic.keys()))
for wi in w:
    dic[wi].sort(reverse=True)
    dic_num[wi] = len(dic[wi])
    dic4calc[wi] = 0

cond = []
def rec(i, rest, dic4calc):
    if rest<w[i]:
        cond.append(dic4calc)
        return

    if i+1<len(w):
        new_dic4calc = copy.deepcopy(dic4calc)
        rec(i+1, rest, new_dic4calc)
    if not dic_num[w[i]]-dic4calc[w[i]]==0:
        new_dic4calc = copy.deepcopy(dic4calc)
        new_dic4calc[w[i]] += 1
        rec(i, rest-w[i], new_dic4calc)
    if i+1>=len(w):
        cond.append(dic4calc)
        return

rec(0, W, dic4calc)
ans = 0
for c in cond:
    total = 0
    for wi in w:
        total += sum(dic[wi][:c[wi]])
    if ans < total:
        ans = total
        
print(ans)
### BUGGY CODE ###

#n=int(input())
#n,m=map(int,input().split())
#a=[int(x) for _ in input().split()]

s=input()
q=int(input())
for i in range(q):
    t=list(map(str,input().split()))
    if t[0]=='1':
        s=s[::-1]
    else:
        if t[1]=='1':
            s=t[2]+s
        else:
            s=s+t[2]
    t.clear
print(s)

### FIXED CODE ###

from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))
### BUGGY CODE ###

import itertools
import collections


n = int(input())
c = list([collections.Counter(input()) for _ in range(n)])

summ = 0
for c1, c2 in itertools.combinations(c, 2):
    summ += c1 == c2
print(summ)

### FIXED CODE ###

import math
import collections


def comb(n, r):
    mf = math.factorial
    return mf(n) // (mf(n - r) * mf(r))


n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]
c = collections.Counter(s)
print(sum(comb(a, 2) for a in c.values() if a > 1))
### BUGGY CODE ###

mod = 10 ** 9 + 7


def pow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b % 2 == 0:
        return (pow(a, b // 2, mod) ** 2) % mod
    else:
        return (a * pow(a, b // 2, mod) ** 2) % mod


def inv(x, mod):
    return pow(x, mod - 2, mod)


MAX = 2 * 10 ** 6 + 3
l = [1] * MAX
for i in range(1, MAX):
    l[i] = (l[i - 1] * i) % mod


def f(r, c):
    return (l[r + c] * inv(l[r], mod) * inv(l[c], mod)) % mod


def g(r, c):
    if r < 0 or c < 0:
        return 0
    ans = 0
    for i in range(r + 1):
        ans += f(i + 1, c)
    return ans % mod


r1, c1, r2, c2 = map(int, input().split())
print(((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod + mod) % mod)


### FIXED CODE ###

mod = 10 ** 9 + 7


def pow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b % 2 == 0:
        return (pow(a, b // 2, mod) ** 2) % mod
    else:
        return (a * pow(a, b // 2, mod) ** 2) % mod


def inv(x, mod):
    return pow(x, mod - 2, mod)


MAX = 2 * 10 ** 6 + 3
l = [1] * MAX
for i in range(1, MAX):
    l[i] = (l[i - 1] * i) % mod


def f(r, c):
    return (l[r + c] * inv(l[r], mod) * inv(l[c], mod)) % mod


def g(r, c):
    if r < 0 or c < 0:
        return 0
    ans = f(r+1, c+1) - 1 + mod
    return ans % mod


r1, c1, r2, c2 = map(int, input().split())
print(((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod + mod) % mod)
### BUGGY CODE ###

import sys
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a//gcd(a,b)*b

def main():
    sys.setrecursionlimit(4100000)
    input = sys.stdin.readline
    n=int(input())
    a=[int(i) for i in input().split()]
    L=a[0]
    for i in a:
        if L%i!=0:
            L=lcm(L,i)
    ans=0
    for i in a:
        ans=(ans+L//i)%(10**9+7)
    print(ans)

if __name__=="__main__":
    main()

### FIXED CODE ###

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

n=int(input())
a=[int(i) for i in input().split()]
L=a[0]
for i in a:
    L=lcm(L,i)
ans=0
for i in a:
    ans+=L//i
print(ans%(10**9+7))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n-1):
  ans+=a[i]*sum(a[i+1:])
  if ans>(10**9+7):
    ans=ans%(10**9+7)
                
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
s=sum(a)
ans=0
for i in range(n-1):
  s-=a[i]
  ans+=a[i]*s
  if ans>(10**9+7):
    ans=ans%(10**9+7)
print(ans)
### BUGGY CODE ###

import bisect
import numpy as np
N, M, Q = map(int, input().split())
trains = np.array([list(map(int, input().split())) for i in range(M)])
queries =np.array([list(map(int, input().split())) for i in range(Q)])

A  =np.zeros([N, N])#A[i][j] = (i + 1) -> (j+1)なる列車の本数
for train in trains:
    li, ri = train
    A[li - 1, ri - 1] += 1
dp = np.zeros([N, N])

def ans(left, right):
    if dp[left, right] > 0:
        return dp[left, right]
    elif left > right:
        return 0
    elif left == right:
        dp[left, right] = A[left, right]
        return dp[left, right]
    else:
        dp[left, right] = ans(left, right-1) + ans(left + 1, right) + A[left, right] - ans(left + 1, right - 1)
        return dp[left, right]

for q in range(Q):
    pi, qi = queries[q]
    print(int(ans(pi - 1, qi - 1)))


### FIXED CODE ###

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for i in range(M)]
queries = [list(map(int, input().split())) for i in range(Q)]

A  =[[0] * N for _ in range(N)] #A[i][j] = (i + 1) -> (j+1)なる列車の本数
for train in trains:
    li, ri = train
    A[li - 1][ri - 1] += 1

dp = [[0] * N for __ in range(N)]
for i in range(N - 1, -1, -1):
    for j in range(i, N):
        if i == j:
            dp[i][j] = A[i][j]
        else:
            dp[i][j] = dp[i][j - 1] + dp[i + 1][j] + A[i][j] - dp[i + 1][j - 1]
for q in range(Q):
    pi, qi = queries[q]
    print(dp[pi - 1][ qi - 1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,last,turn) in memo:
        return memo[(n,last,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,last,turn)]=ret
    return ret


print func(N,Y,0)

### FIXED CODE ###

N,Z,W=map(int,raw_input().split())
a=[]
a=map(int,raw_input().split())

if len(a)!=1:
	print max ( abs(a[-1]-W), abs(a[-2]-a[-1]) )
else:
	print abs(a[0]-W)
### BUGGY CODE ###

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

cnt = 0
liuse = [1]
place = 1
while True:
  place = li[place-1]
  liuse.append(place)
  cnt += 1
  if place == 2:
    print(cnt)
    exit()
  if len(liuse) > len(set(liuse)):
    print(-1)
    exit()

### FIXED CODE ###

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

liuse = [0]*n
liuse[0] = 1
for i in range(1,n):
  liuse[i] = li[liuse[i-1]-1]
if 2 in liuse:
  print(liuse.index(2))
else:
  print(-1)
### BUGGY CODE ###

from sys import stdin

def main():
    nums = [int(n) for n in stdin]

    primes = list(filter(is_prime, nums))
    print(len(primes))

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

    if 2 == n:
        return True

    if 0 == n % 2:
        return False

    for i in range(3, n, 2):
        if 0 == n % i:
            return False

    return True

if __name__ == '__main__':
    main()

### FIXED CODE ###

from math import sqrt

def is_prime(x):
    if x == 2:
        return 1

    if x % 2 == 0:
        return 0

    i = 3
    while i <= int(x/i):
        if x % i == 0:
            return 0
        i += 2

    return 1

def main():
    n = int(input())

    count = 0

    for _ in range(n):
        count += is_prime(int(input()))

    print(count)

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

lim = 1e18
n = int(input());
nums = list(map(int,str(input()).split(" ")))
ans = 1
for num in nums:
    ans *= num
if ans > lim:
    print(-1)
else:
    print(int(ans))


### FIXED CODE ###

def main():
    lim = 1e18
    n = int(input())
    nums = list(map(int,str(input()).split(" ")))
    if 0 in nums:
        print(0)
        return
    ans = 1
    for num in nums:
        ans *= num
        if ans > lim:
            print(-1)
            return
    print(ans)
    return

main()
### BUGGY CODE ###

N = int(input())
sum=0
while N:
    sum=(sum+N%10)%9
    N//=10
if sum%9==0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N=list(str(input()))
sum=0
for i in range(len(N)):
    sum=(sum+int(N[i]))%9
if sum%9==0:
    print("Yes")
else:
    print("No")