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


a=int(input())
b=str(input())
sum=0
c=b
d=b
i=0
for s in b:
    if s=="R":
        if a>=i:
            for n in range(i,a):
                if c[n]=="G":
                    j=n-i
                    if a>=n:
                        for m in range(n,a):
                            if c[m]=="B":
                                k=m-n
                                if k!=j:
                                    sum+=1
    if s=="R":
        if a>=i:
            for n in range(i,a):
                if c[n]=="B":
                    j=n-i
                    if a>=n:
                        for m in range(n,a):
                            if c[m]=="G":
                                k=m-n
                                if k!=j:
                                    sum+=1

    if s=="G":
        if a>=i:
            for n in range(i,a):
                if c[n]=="R":
                    j=n-i
                    if a>=n:
                        for m in range(n,a):
                            if c[m]=="B":
                                k=m-n
                                if k!=j:
                                    sum+=1
    if s=="G":
        if a>=i:
            for n in range(i,a):
                if c[n]=="B":
                    j=n-i
                    if a>=n:
                        for m in range(n,a):
                            if c[m]=="R":
                                k=m-n
                                if k!=j:
                                    sum+=1

    if s=="B":
        if a>=i:
            for n in range(i,a):
                if c[n]=="R":
                    j=n-i
                    if a>=n:
                        for m in range(n,a):
                            if c[m]=="G":
                                k=m-n
                                if k!=j:
                                    sum+=1
    if s=="B":
        if a>=i:
            for n in range(i,a):
                if c[n]=="G":
                    j=n-i
                    if a>=n:
                        for m in range(n,a):
                            if c[m]=="R":
                                k=m-n
                                if k!=j:
                                    sum+=1


    i+=1
print(sum)


### FIXED CODE ###

a=int(input())
b=str(input())
sum=0

riron_sum=b.count('R')*b.count('G')*b.count('B')

for i in range(0,a):
    for n in range(0,a+1):
        j = i+n
        k = j+n
        #print(j)
        #print(k)
        if k>=a:
        	break

        if b[i]!=b[j] and b[j]!=b[k] and b[k]!=b[i]:
                riron_sum-=1

print(riron_sum)
### BUGGY CODE ###

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

root = [[] for i in range(n)]
for _ in range(m):
    a, b = (int(x) for x in input().split())
    root[b-1].append(a-1)
    root[a-1].append(b-1) 

stack=[0]
check = [-1]*n
check[0] = 0

while len(stack)>0:
    v = stack.pop(0)
    for i in root[v]:
        if check[i] == -1:
            check[i]=v+1
            stack.append(i)


print('Yes')
for i in range(1,n):
    print(check[i])
    

### FIXED CODE ###

N, M = map(int, input().split())
root = [[] for _ in range(N+1)]
 
for i in range(M):
    a, b = map(int, input().split())
    root[a].append(b)
    root[b].append(a)
 
ans = [10**9] * (N+1)
ans[0] = 0
ans[1] = 0
 
from collections import deque
q = deque([1])
 
while q:
    p = q.popleft()
    for i in root[p]:
        if ans[i] == 10**9:
            ans[i] = p
            q.append(i)
 
if 10**9 in set(ans):
    print('No')
else:
    print('Yes')
    for i in range(2, N+1):
        print(ans[i])
### BUGGY CODE ###

def main():
  n=int(input())
  a=[int(input()) for _ in [0]*n]
  print(len([i for i in a if a.count(i)%2==1]))
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  n=int(input())
  a=sorted([int(input()) for _ in [0]*n])
  a.append(0)
  a=tuple(a)
  cnt,x,ans=0,a[0],0
  for i in a:
    if x==i:
      cnt+=1
    else:
      ans+=1 if cnt%2==1 else 0
      cnt,x=1,i
  print(ans)
if __name__=='__main__':
  main()
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
for i in range(n):
    if max(a) > a[i]:
        print(max(a))
    else:
        if a.count(a[i]) > 1:
            print(a[i])
        else:
            print(b[-2])


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])
### BUGGY CODE ###

def main():
    from sys import stdin
    input = stdin.readline
    mod = 10**9+7
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]
    pow2 = [1]
    for i in range(200000):
        pow2.append(pow2[-1]*2 % mod)

    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]
    root = 0
    d = [-1]*n
    d[root] = 0
    q = [root]
    cnt = 0
    while q:
        cnt += 1
        qq = []
        while q:
            i = q.pop()
            for j in g[i]:
                if d[j] == -1:
                    d[j] = cnt
                    qq.append(j)
        q = qq
    g2 = g
    g = [[] for _ in [0]*n]
    for i in range(n):
        di = d[i]
        g[i] = [j for j in g2[i] if di <= d[j]]

    dd = sorted([(j, i) for i, j in enumerate(d)])[::-1]
    dd = [j for i, j in dd]

    dp = [(0, 0, 1) for _ in [0]*n]
    for i in dd:
        if g:
            n = 1
            for j in g[i]:
                if j != i:
                    n += dp[j][2]
            x, y = pow(2, n-1, mod)-1, 0
            for j in g[i]:
                if j != i:
                    xj, yj, nj = dp[j]
                    p1, p2 = pow2[n-nj], pow2[nj]
                    x += xj*p1+yj*(p1-1)-p2+1
                    y += yj+p2-1
            dp[i] = (x % mod, y % mod, n)

    x = dp[0][0]
    y = pow(2, dp[0][2], mod)
    print(x*pow(y, mod-2, mod) % mod)


main()


### FIXED CODE ###

def main():
    from sys import stdin
    input = stdin.readline
    mod = 10**9+7
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]
    pow2 = [1]
    for i in range(200000):
        pow2.append(pow2[-1]*2 % mod)

    g = [set() for _ in [0]*n]
    [g[a-1].add(b-1) for a, b in ab]
    [g[b-1].add(a-1) for a, b in ab]
    root = 0
    d = [-1]*n
    d[root] = 0
    q = [root]
    cnt = 0
    while q:
        cnt += 1
        qq = []
        while q:
            i = q.pop()
            for j in g[i]:
                if d[j] == -1:
                    d[j] = cnt
                    qq.append(j)
        q = qq

    for i in range(n):
        di = d[i]
        remove_list = []
        for j in g[i]:
            if di > d[j]:
                remove_list.append(j)
        for j in remove_list:
            g[i].remove(j)
    dd = sorted([(j, i) for i, j in enumerate(d)])[::-1]
    dd = [j for i, j in dd]

    dp = [(0, 0, 1) for _ in [0]*n]
    for i in dd:
        if g:
            n = 1
            for j in g[i]:
                if j != i:
                    n += dp[j][2]
            x, y = pow(2, n-1, mod)-1, 0
            for j in g[i]:
                if j != i:
                    xj, yj, nj = dp[j]
                    p1, p2 = pow2[n-nj], pow2[nj]
                    x += xj*p1+yj*(p1-1)-p2+1
                    y += yj+p2-1
            dp[i] = (x % mod, y % mod, n)

    x = dp[0][0]
    y = pow(2, dp[0][2], mod)
    print(x*pow(y, mod-2, mod) % mod)


main()
### BUGGY CODE ###

n = int(input())
v = list(map(int, input().split()))
v1 = v[::2]
v2 = v[1::2]

cnt = [[0] * 2 for _ in range(4)]
for i in set(v1):
    tmp = v1.count(i)
    if cnt[0][0] <= tmp:
        cnt[0], cnt[1] = [tmp, i], cnt[0]
for i in set(v2):
    tmp = v2.count(i)
    if cnt[2][0] <= tmp:
        cnt[2], cnt[3] = [tmp, i], cnt[2]

if cnt[0][1] != cnt[2][1]:
    print(n - cnt[0][0] - cnt[2][0])
else:
    print(min(n - cnt[0][0] - cnt[3][0], n - cnt[1][0] - cnt[2][0]))

### FIXED CODE ###

from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = sorted(Counter(v[::2]).items(), key=lambda x: x[1], reverse=True)
v2 = sorted(Counter(v[1::2]).items(), key=lambda x: x[1], reverse=True)
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))
### BUGGY CODE ###

from collections import deque
s=deque(input())
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    s.reverse()
  else:
    if t[1]=='1':
      s.appendleft(t[2])
    else:
      s.append(t[2])
print(''.join(s))

### FIXED CODE ###

from collections import deque
s=deque(input())
f=False
for _ in range(int(input())):
  t=list(input().split())
  if t[0]=='1':
    if f is False:
      f = True
    else:
      f = False
  else:
    if t[1]=='1':
      if f is False:
      	s.appendleft(t[2])
      else:
        s.append(t[2])
    else:
      if f is False:
      	s.append(t[2])
      else:
        s.appendleft(t[2])
x=''.join(map(str,s))
if f is False:
	print(x)
else:
  print(x[::-1])
### BUGGY CODE ###

s = input()
q = int(input())
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        s = s[::-1]
    else:
        if query[1] == '1':
            s = query[2] + s
        else:
            s = s + query[2]
print(s)


### FIXED CODE ###

from collections import deque

is_reverse = False
s = deque(input())
q = int(input())
for _ in range(q):
    query = input().split()
    if query[0] == '1':
        is_reverse = not is_reverse
    else:
        if (not is_reverse and query[1] == '1') or (is_reverse and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
print(''.join(s)[::-1]) if is_reverse else print(''.join(s))
### BUGGY CODE ###

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""
dp、無理な組み合わせを引く、追加された黒マスの数は決まっている
各マスのdp
下から来たものと左から来たものをdpで保持
下から来たものは次だけ制約あり
dp = [下から、左から]
"""
MOD = 998244353
A, B, C, D = lr()  # Cは縦
dp = [[[0, 0] for _ in range(D+1)] for _ in range(C+1)]   # 1-indexed
dp[A][B] = [0, 1]
for i in range(A, C+1):
    for j in range(B, D+1):
        # iが縦
        if i == A and j == B:
            continue
        if i > A:
            dp[i][j][0] = sum(dp[i-1][j]) * j
        if j > B:
            dp[i][j][1] = dp[i][j-1][0] + dp[i][j-1][1] * i
        dp[i][j][0] %= MOD
        dp[i][j][1] %= MOD

answer = sum(dp[C][D])
print(answer%MOD)



### FIXED CODE ###

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""
各マスのdp
下から来たものと左から来たものを足す
その後、重なっているところを引く
"""
MOD = 998244353
A, B, C, D = lr()  # Cは縦
dp = [[0] * (D+1) for _ in range(C+1)]   # 1-indexed
dp[A][B] = 1
for i in range(A, C+1):
    for j in range(B, D+1):
        # iが縦
        if i > A:
            dp[i][j] += dp[i-1][j] * j
        if j > B:
            dp[i][j] += dp[i][j-1] * i
        if i > A and j > B:
            dp[i][j] -= dp[i-1][j-1] * (i-1) * (j-1)
        dp[i][j] %= MOD

answer = dp[C][D]
print(answer%MOD)
### BUGGY CODE ###

a, b, k = map(int, input().split())
for i in range(a, b + 1):
    if i <= a + (k - 1):
        print(i)
    elif i >= b - (k - 1):
        print(i)


### FIXED CODE ###

a, b, k = map(int, input().split())
for i in range(a, min(b, a+k-1)+1):
    print(i)
for i in range(max(b-k+1, a+k), b+1):
    print(i)
### BUGGY CODE ###

def main():
  n = int(input())
  a = tuple(map(int ,input().split()))
  ans = 0
  for x in range(min(a)-1, max(a)+2):
    cnt = 0
    for i in range(n):
      if abs(x-a[i]) <= 1:
        cnt += 1
    ans = max(ans, cnt)

  print(ans)
if __name__ == '__main__':
  main()

### FIXED CODE ###

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

  ans = [0]*(10**6)
  for x in a:
    ans[x-1] += 1
    ans[x] += 1
    ans[x+1] += 1
  print(max(ans))
if __name__ == '__main__':
  main()
### BUGGY CODE ###

from itertools import permutations
n,m = map(int,input().split())
lrx = [list(map(int,input().split())) for i in range(m)]
lrx.sort(key = lambda x:x[1])
mod = 10**9+7
dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)]
dp[0][0][0] = 1
for l,r,t in lrx:
  if t != 1:
    for g in range(l):
      for b in range(max(1,g)):
        dp[r][g][b] = -1
  if t != 2:
    for g in range(l,r):
      for b in range(l):
        dp[r][g][b] = -1
  if t != 3:
    for g in range(l,r):
      for b in range(l,g):
        dp[r][g][b] = -1

for r in range(n):
  for g in range(max(1,r)):
    for b in range(max(1,g)):
      v = dp[r][g][b]
      if v == -1:
        continue
      if dp[r+1][g][b] >= 0:
        dp[r+1][g][b] += v
        dp[r+1][g][b] %= mod
      if dp[r+1][r][b] >= 0:
        dp[r+1][r][b] += v
        dp[r+1][r][b] %= mod
      if dp[r+1][r][g] >= 0:
        dp[r+1][r][g] += v
        dp[r+1][r][g] %= mod
ans = 0
for i in range(n):
  for j in range(max(1,i)):
    if dp[n][i][j] >= 0:
      ans += dp[n][i][j]
      ans %= mod
print(ans%mod)


### FIXED CODE ###

from itertools import permutations
n,m = map(int,input().split())
lrx = [list(map(int,input().split())) for i in range(m)]
lrx.sort(key = lambda x:x[1])
mod = 10**9+7
dp = [[[0 for b in range(max(1,g))] for g in range(max(1,r))] for r in range(n+1)]
dp[0][0][0] = 1
for l,r,t in lrx:
  if t != 1:
    for g in range(l):
      for b in range(max(1,g)):
        dp[r][g][b] = -1
  if t != 2:
    for g in range(l,r):
      for b in range(l):
        dp[r][g][b] = -1
  if t != 3:
    for g in range(l,r):
      for b in range(l,g):
        dp[r][g][b] = -1

for r in range(n):
  for g in range(max(1,r)):
    for b in range(max(1,g)):
      v = dp[r][g][b]
      if v == -1:
        continue
      if dp[r+1][g][b] >= 0:
        dp[r+1][g][b] += v
        dp[r+1][g][b] %= mod
      if dp[r+1][r][b] >= 0:
        dp[r+1][r][b] += v
        dp[r+1][r][b] %= mod
      if dp[r+1][r][g] >= 0:
        dp[r+1][r][g] += v
        dp[r+1][r][g] %= mod
ans = 0
for i in range(n):
  for j in range(max(1,i)):
    if dp[n][i][j] >= 0:
      ans += dp[n][i][j]
      ans %= mod
print(ans%mod)
### BUGGY CODE ###

N=int(input())
l=list(map(int,input().split()))
num=0
ans=0
for i in range(N-1):
  ans+=l[i]*sum(l[i+1:N])%1000000007
print(ans%1000000007)

### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
ans=0
i=0
S=sum(l)
while i<len(l)-1:
  S=S-l[i]
  ans+=l[i]*S
  i+=1
print(ans%1000000007)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
for i in range(N): A[i] = format(A[i], "#b") #ここで全て二進数に変換
#print(A)

sum = 0
c1 = [0]*60
for i in range(N):
    for j in range(60):
        #print(i,j,A[i][-(j+1)])
        if A[i][-(j+1)] == "0": #str型であることに注意！
            continue
        elif A[i][-(j+1)] == "1":
            c1[j] += 1
        else:
            break

#print("c1 =",c1)
for i in range(60):
    print
    sum += (c1[i] * (N-c1[i])) << i
    sum %= mod
 
print(sum%mod)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
xorsum = 0
for i in range(60):
  c1 = sum([1 for a in A if (a >> i) & 1]) #
  xorsum += (c1*(N-c1)*(1<<i))
  xorsum = xorsum%mod
print(xorsum%mod)
### BUGGY CODE ###

# import numpy as np
from collections import deque

H,W=map(int,input().split())
CH,CW=map(int,input().split())
DH,DW=map(int,input().split())

S=[input() for _ in range(H)]
# 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む
S = ['##{}##'.format(row) for row in S]
S.insert(0, '##{}##'.format('#' * W))
S.insert(0, '##{}##'.format('#' * W))
S.append('##{}##'.format('#' * W))
S.append('##{}##'.format('#' * W))

# print(S)

MAX_COST = 10 ** 9
Cost=[ [ MAX_COST for _ in range(W+2)] for _ in range(H+2)]
# Cost = np.full((H,W),MAX_COST)

# print(S)

ans = -1

deq = deque()

deq.append((CH+1,CW+1,0))
Cost[CH+1][CW+1] = 0;

# used = set()
five_five = [ (i,j) for i in range(-2,3,1) for j in range(-2,3,1) ]
ffCosts = {}
for i,j in five_five:
	# print(i,j)
	if (j == 0 and (i==1 or i==-1)) or (i==0 and (j==1 or j==-1)):
		ffCosts[(i,j)] = 0
	else:
		ffCosts[(i,j)] = 1
# print(five_five)

while 0 < len(deq):
	h,w,c=deq.popleft()
	# print(h,w,c)
	for i,j in five_five:
		# print(i,j)
		if S[h+i][w+j] == '.':
			cAdd = ffCosts[(i,j)]
			if c + cAdd < Cost[h+i][w+j]:
				Cost[h+i][w+j] = c + cAdd
				if (h+i,w+j,Cost[h+i][w+j]) not in deq:
					if cAdd == 0:
						deq.appendleft((h+i,w+j,Cost[h+i][w+j]))
					else:
						deq.append((h+i,w+j,Cost[h+i][w+j]))


# print(Cost)

if Cost[DH+1][DW+1] == MAX_COST:
	print(-1)
else:
	print(Cost[DH+1][DW+1])

### FIXED CODE ###

from collections import deque

H,W=map(int,input().split())
CH,CW=map(int,input().split())
DH,DW=map(int,input().split())

S=[list(input()) for _ in range(H)]
MAX_COST = 10 ** 9
Cost=[ [ MAX_COST for _ in range(W)] for _ in range(H)]

# print(S)

ans = -1

deq = deque()

deq.append((CH-1,CW-1,0))
Cost[CH-1][CW-1] = 0;

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

# used = set()

while 0 < len(deq):
	h,w,c=deq.popleft()
	# print(h,w,c)
	for i,j in walk:
		if 0 <= h+i and h+i < H and 0 <= w+j and w+j < W:
			if S[h+i][w+j] == '.' and c < Cost[h+i][w+j]:
				Cost[h+i][w+j] = c
				# print("updl ", i,j,h+i,w+j,c)
				deq.appendleft((h+i,w+j,Cost[h+i][w+j]))
	for i in range(-2,3,1):
		for j in range(-2,3,1):
			# print(i,j)
			if 0 <= h+i and h+i < H and 0 <= w+j and w+j < W:
				if S[h+i][w+j] == '.':
					if c + 1 < Cost[h+i][w+j]:
						Cost[h+i][w+j] = c + 1
						deq.append((h+i,w+j,Cost[h+i][w+j]))
						# print("updr ", h+i,w+j,Cost[h+i][w+j])

if Cost[DH-1][DW-1] == MAX_COST:
	print(-1)
else:
	print(Cost[DH-1][DW-1])
### BUGGY CODE ###

n=int(input())

a=list(map(int,input().split()))
ans = 1
th = 10**18

for i in a:
    ans *= i
if ans <= th:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

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

aa=sorted(a)
th=10**18
ans=1

for i in range(len(aa)):
    if aa[i]==0:
        print(0)
        break
    ans*=aa[i]
    if ans>th:
        print(-1)
        break
    if i==len(aa)-1:
        print(ans)
### BUGGY CODE ###

l = input().split()
n1 = l[0]
n0 = l[1]
n = l[2]
k = l[3]

list = []

for i in range(int(n1)):
    list.append(1)

for i in range(int(n0)):
    list.append(0)

for i in range(int(n)):
    list.append(-1)

ans = 0

for i in range(int(k)):
    ans += int(list[i])

print(ans)

### FIXED CODE ###

l = input().split()
n1 = int(l[0])
n0 = int(l[1])
n = int(l[2])
k = int(l[3])

ans = 0

if k >= n1:
    ans += n1

else:
    ans += k

k -= n1

k -= n0

if k > 0:
    ans -= k

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

n, k, *a = map(int, open(0).read().split())
g = [0] * (k + 1)
for i in range(min(a), k + 1):
	s = set(g[i - x] for x in a if i >= x)
	r = 0
	while r in s:
		r += 1
	g[i] = r
print("First" if g[-1] else "Second")

### FIXED CODE ###

n, k, *a = map(int, open(0).read().split())
g = [0] * (k + 1)
for i in range(min(a), k + 1):
	s = set(g[i - x] for x in a if i >= x)
	r = 0
	while r in s:
		r += 1
	g[i] = r
print("First" if g[-1] else "Second")
### BUGGY CODE ###

import time
start = time.time()

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

if n==1:
  print(p)
else:
  ans=1
  for i in range(1,100000000):
    tmp=i**n
    if (p>=tmp) and (p%tmp == 0):
     ans=i
    if(p<tmp):
      break
    now = time.time()
    if(now-start>1.9):
      break
  print(ans)


### FIXED CODE ###

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

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

kekka=factorize(p)

ans=1
for i in range(len(kekka)):
    ans=ans* kekka[i][0] ** (kekka[i][1]//n)
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    x.append(b)
  elif b==n:
    y.append(a)

ans="IMPOSSIBLE"

for i in range(len(y)):
  if y[i] in x:
    ans="POSSIBLE"

print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
data=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    data[b-1]+=1
    if data[b-1]==2:
      print('POSSIBLE')
      exit()
  if b==n:
    data[a-1]+=1
    if data[a-1]==2:
      print('POSSIBLE')
      exit()

print('IMPOSSIBLE')
### BUGGY CODE ###

from collections import defaultdict

n, k, l = map(int, input().split())

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

#	def find(self, x):
#		while self.table[x] >= 0:
#			x = self.table[x]
#		return x

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]


	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
		return

road = UnionFind(n)
train = UnionFind(n)

for _ in range(k):
	a, b = map(int, input().split())
	road.union(a - 1, b - 1)

for _ in range(l):
	a, b = map(int, input().split())
	train.union(a - 1, b - 1)

road_root = []
for i in range(n):
	num = road.find(i)
	road_root.append(num)

train_root = []
for i in range(n):
	num = train.find(i)
	train_root.append(num)

count = defaultdict(int)
for i in range(n):
	count[road_root[i] * (10 ** 6) +  train_root[i]] += 1

ans = []
for i in range(n):
	ans.append(count[road_root[i] * (10 ** 6) +  train_root[i]])

print(*ans)


### FIXED CODE ###

from collections import defaultdict

n, k, l = map(int, input().split())

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

#	def find(self, x):
#		while self.table[x] >= 0:
#			x = self.table[x]
#		return x

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]


	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
		return

road = UnionFind(n)
train = UnionFind(n)

for _ in range(k):
	a, b = map(int, input().split())
	road.union(a - 1, b - 1)

for _ in range(l):
	a, b = map(int, input().split())
	train.union(a - 1, b - 1)

road_root = []
for i in range(n):
	num = road.find(i)
	road_root.append(num)

train_root = []
for i in range(n):
	num = train.find(i)
	train_root.append(num)

count = defaultdict(int)
for i in range(n):
	count[road_root[i] * (10 ** 6) +  train_root[i]] += 1

ans = []
for i in range(n):
	ans.append(count[road_root[i] * (10 ** 6) +  train_root[i]])

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

N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    while a[i] + a[i+1] > x:
        a[i+1]-=1
        cnt+=1
print(cnt)


### FIXED CODE ###

N, x = map(int, input().split())
a = [0] + list(map(int, input().split()))
cnt = 0
for i in range(N):
    if a[i]+a[i+1]>x:
        tmp = a[i]+a[i+1]-x
        a[i+1] -= tmp
        cnt+=tmp
print(cnt)