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

from heapq import heappush,heappop
def main():
    h,w=map(int,input().split())
    sx,sy=map(int,input().split())
    sx-=1
    sy-=1
    gx,gy=map(int,input().split())
    gx-=1
    gy-=1
    g=[list(input()) for _ in range(h)]
    v=[[0 for j in range(w)] for i in range(h)]
    v2=[[0 for j in range(w)] for i in range(h)]
    q=[]
    heappush(q,[0,sx+h*sy])
    while q:
        c,xy=heappop(q)
        x=xy%h
        y=xy//h
        if x==gx and y==gy:
            print(c)
            exit()
        if v[x][y]==1:
            continue
        v[x][y]=1
        for a in range(-2,3):
            for b in range(-2,3):
                if a==b==0:
                    continue
                if a*b==0 and abs(a+b)==1:
                    nx=x+a
                    ny=y+b
                    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                        heappush(q,[c,nx+h*ny])
                    continue
                nx=x+a
                ny=y+b
                if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0 and v2[nx][ny]==0:
                    heappush(q,[c+1,nx+h*ny])
                    v2[nx][ny]=1
    print(-1)
if __name__=='__main__':
    main()

### FIXED CODE ###

from collections import deque
def main():
    h,w=map(int,input().split())
    sx,sy=map(int,input().split())
    sx-=1
    sy-=1
    gx,gy=map(int,input().split())
    gx-=1
    gy-=1
    g=[tuple(input()) for _ in range(h)]
    v=[[0 for j in range(w)] for i in range(h)]
    q=deque([[sx,sy]])
    v[sx][sy]=1
    ans=0
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    while True:
        l=[]
        while q:
            x,y=q.popleft()
            l.append([x,y])
            if x==gx and y==gy:
                print(ans)
                exit()
            for a,b in k:
                nx=x+a
                ny=y+b
                if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                    q.append([nx,ny])
                    v[nx][ny]=1
        if len(l)==0:
            break
        for x,y in l:              
            for a in range(-2,3):
                for b in range(-2,3):
                    if a*b==0 and abs(a+b)<=1:
                        continue
                    nx=x+a
                    ny=y+b
                    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                        q.append([nx,ny])
                        v[nx][ny]=1
        ans+=1 
    print(-1)
if __name__=='__main__':
    main()
### BUGGY CODE ###

import bisect
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
	if s[i] == "R":
		r.append(i+1)
	elif s[i] == "G":
		g.append(i+1)
	else:
		b.append(i+1)
ans = 0
if len(r) == 0 or len(g) == 0 or len(b) == 0:
	print (0)
	exit()
for i in r:
	for j in g:
		ans += len(b)
		if i > j:
			k = j-abs(i-j)
			m = i+abs(i-j)
		else:
			k = j+abs(i-j)
			m = i-abs(i-j)
		if k <= b[-1] and k >= b[0]:
			x = bisect.bisect_left(b,k)
			if x >= 0 and x < len(b):
				if b[x] == k:
					ans -= 1
		if m <= b[-1] and m >= b[0]:
			x = bisect.bisect_left(b,m)
			if x >= 0 and x < len(b):
				if b[x] == m:
					ans -= 1
		l = (i+j)//2
		if abs(i-l) == abs(j-l):
			x = bisect.bisect_left(b,l)
			if x >= 0 and x < len(b):
				if b[x] == l:
					ans -= 1
print (ans)

### FIXED CODE ###

import bisect
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(n):
	if s[i] == "R":
		r.append(i+1)
	elif s[i] == "G":
		g.append(i+1)
	else:
		b.append(i+1)
ans = 0
if len(r) == 0 or len(g) == 0 or len(b) == 0:
	print (0)
	exit()
for i in r:
	for j in g:
		ans += len(b)
		if i > j:
			k = j-abs(i-j)
			m = i+abs(i-j)
		else:
			k = j+abs(i-j)
			m = i-abs(i-j)
		if k <= b[-1] and k >= b[0]:
			x = bisect.bisect_left(b,k)
			if x >= 0 and x < len(b):
				if b[x] == k:
					ans -= 1
		if m <= b[-1] and m >= b[0]:
			x = bisect.bisect_left(b,m)
			if x >= 0 and x < len(b):
				if b[x] == m:
					ans -= 1
		l = (i+j)//2
		if abs(i-l) == abs(j-l):
			x = bisect.bisect_left(b,l)
			if x >= 0 and x < len(b):
				if b[x] == l:
					ans -= 1
print (ans)
### BUGGY CODE ###

n, k = map(int, input().split())
As = list(map(int, input().split()))
 
 
def change(arr):
  newAs = [0] * n
  for i, a in enumerate(arr):
    for t in range(max(i - a, 0), min(i + a + 1, n)):
      newAs[t] += 1
  return newAs
 
 
for temp in range(min(k, 10**2)):
  As = change(As)
print(' '.join(map(str, As)))

### FIXED CODE ###

import math
from itertools import accumulate
n, k = map(int, input().split())
As = list(map(int, input().split()))
for i in range(min(41, k)):
  _As = [0]*(n+1)
  for j in range(n):
    l = max(0, j - As[j])
    r = min(n - 1, j + As[j])
    _As[l] += 1
    _As[r+1] -= 1
  As = list(accumulate(_As))[:-1]
print(' '.join([str(A) for A in As]))
### BUGGY CODE ###

N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
A = []
B = []
for i in range(N):
	A.append(L[i][0])
	B.append(L[i][1])
cost = 0
num = 0
while True:
	if num == M:
		break
	cost = cost + min(A)*min(B[A.index(min(A))], M - num)
	num = num + min(B[A.index(min(A))], M - num)
	B.pop(A.index(min(A)))
	A.remove(min(A))
print(cost)
exit()

### FIXED CODE ###

N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
L.sort()

A = []
B = []
for i in range(N):
	A.append(L[i][0])
	B.append(L[i][1])
num = 0
cost = 0
i = 0
while num < M:
	cost = cost + A[i]*min(B[i], M - num)
	num = num + min(B[i], M - num)
	i = i + 1

print(cost)
### BUGGY CODE ###

import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

cnt = 0

while cnt < n:


    arr=[]
    for i in range(0, n):
        
        if cnt != i:

            arr.append(int(arr_data[1][i]))

    
    print(sorted(arr)[(n//2)-1])        
    cnt += 1

### FIXED CODE ###

import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

val = (n-1) // 2

arr = list(map(int, arr_data[1]))

arr_sort = sorted(arr)

val1 = arr_sort[(n // 2)-1]
val2 = arr_sort[(n // 2)]

for v in arr:
    
    if v<=val1:
        
        print(val2)
        
    else:
        
        print(val1)
### BUGGY CODE ###

n, a = map(int, input().split(" "))
x = tuple(map(int, input().split(" ")))

x = [x_i-a for x_i in x]

count = 0
for i in range(1, 2**n):
	bin_str = bin(i)[2:].zfill(n)
	sum_num = 0
	for j, bin_c in enumerate(bin_str):
		if bin_c == "1":
			sum_num += x[j]
	if sum_num == 0:
		count += 1

print(count)

### FIXED CODE ###

from collections import Counter

N, A = map(int, input().split(" "))
X = list(map(int, input().split(" ")))

X = [x-A for x in X]

c = Counter([0])
for x in X:
    d = Counter()
    for k, v in c.items():
        d[k+x] += v
    c += d

print(c[0]-1)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        ans[v] *= ans[u]+1
    if marker==0:
      stack.pop()
    ans[v]%=M
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  while stack:
    v = stack.pop()
    cum1 = [1]*(len(edge[v])+1)
    cum2 = [1]*(len(edge[v])+1)
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        cum1[i+1] = cum1[i]*(p_value[v]+1)
      else:
        cum1[i+1] = cum1[i]*(ans[u]+1)
      cum1[i+1] %= M
    for i,u in enumerate(edge[v][::-1]):
      if u==parent[v]:
        cum2[-i-2] = cum2[-i-1]*(p_value[v]+1)
      else:
        cum2[-i-2] = cum2[-i-1]*(ans[u]+1)
      cum2[i+1]%=M
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = cum1[i]*cum2[i+1]%M
      ans[u] *= (p_value[u]+1)
      ans[u] %= M
      stack.append(u)
    ans[v] %= M
  return

ans = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

### FIXED CODE ###

import sys,os,io
input = sys.stdin.readline
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        ans[v] *= ans[u]+1
        ans[v] %=M
    if marker==0:
      stack.pop()
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  while stack:
    v = stack.pop()
    cum1 = [1]*(len(edge[v])+1)
    cum2 = [1]*(len(edge[v])+1)
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        cum1[i+1] = cum1[i]*(p_value[v]+1)%M
      else:
        cum1[i+1] = cum1[i]*(ans[u]+1)%M
    for i,u in enumerate(edge[v][::-1]):
      if u==parent[v]:
        cum2[-i-2] = cum2[-i-1]*(p_value[v]+1)%M
      else:
        cum2[-i-2] = cum2[-i-1]*(ans[u]+1)%M
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = cum1[i]*cum2[i+1]%M
      ans[u] *= (p_value[u]+1)
      ans[u] %= M
      stack.append(u)
    ans[v] %= M
  return

ans = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')
### BUGGY CODE ###

import numpy as np
n=int(input())
ll=list(map(int, input().split()))
ll=np.array(sorted(ll))

  
ans=0
for i in range(len(ll)-1):
  for j  in range(i+1,len(ll)):
    tmp=ll[j+1:]
    ans+=len(tmp[tmp<(ll[i]+ll[j])])
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
ll=list(map(int, input().split()))
ll=sorted(ll)

  
ans=0
for i in range(len(ll)-1):
  for j  in range(i+1,len(ll)):
    a,b=ll[i],ll[j]
    ans+=bisect.bisect_left(ll,a+b)-(j+1)
print(ans)
### BUGGY 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)]

queue = deque()

INF=10**12
cost = [[INF]*w for _ in range(h)]
cost[ch-1][cw-1]=0

dxdy = [[1,0],[-1,0],[0,1],[0,-1]]
warp = []
for m in range(-2,3):
    for n in range(-2,3):
        if [m,n] not in [[0,0],[1,0],[-1,0],[0,1],[0,-1]]:
            warp += [[m,n]]

queue.append([ch-1,cw-1,0])

while queue:
    x,y,d = queue.popleft()
    for dx,dy in dxdy:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d<cost[nx][ny]:
            cost[nx][ny]=d
            queue.append([nx,ny,d])
            #[print(*cost[l]) for l in range(h)]
            #print("---------------")

    for dx,dy in warp:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d+1<cost[nx][ny]:            
            cost[nx][ny]=d+1
            queue.append([nx,ny,d+1])
            #[print(*cost[l]) for l in range(h)]
            #print("---------------")


if cost[dh-1][dw-1]<INF:
    print(cost[dh-1][dw-1])
else:
    print(-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)]
INF=10**7

queue = deque()

cost = [[INF]*w for _ in range(h)]
cost[ch-1][cw-1]=0

dxdy = [[1,0],[-1,0],[0,1],[0,-1]]
warp = []
for m in range(-2,3):
    for n in range(-2,3):
        if [m,n] not in [[0,0],[1,0],[-1,0],[0,1],[0,-1]]:
            warp += [[m,n]]

queue.append([ch-1,cw-1,0])

while queue:
    x,y,d = queue.popleft()
    for dx,dy in dxdy:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d<cost[nx][ny]:
            cost[nx][ny]=d
            queue.appendleft([nx,ny,d])
            #[print(*cost[l]) for l in range(h)]
            #print("---------------")

    for dx,dy in warp:
        nx,ny = x+dx,y+dy
        if -1<nx<h and -1<ny<w and s[nx][ny]!="#" and d+1<cost[nx][ny]:            
            cost[nx][ny]=d+1
            queue.append([nx,ny,d+1])
            #[print(*cost[l]) for l in range(h)]
            #print("---------------")


if cost[dh-1][dw-1]<INF:
    print(cost[dh-1][dw-1])
else:
    print(-1)
### BUGGY CODE ###

a = []
a = input().split()
N = int(a[0])
M = int(a[1])

A = input().split()
A = [int(n) for n in A]
#print('input A', A)

for i in range(M) :
  A.sort(reverse = True)
#  print('sort A', A)
  A[0] = A[0] // 2 

#print('N', N)
#print('M', M)
#print('A', A)
print(sum(A))

### FIXED CODE ###

import heapq

a = []
a = input().split()
N = int(a[0])
M = int(a[1])
A = input().split()
A = [int(n) for n in A]

for i in range(N) :
  A[i] = -A[i]

heapq.heapify(A)

for i in range(M) :
  c = heapq.heappop(A)
  heapq.heappush(A, (c+1) // 2)

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

from itertools import permutations
n=int(input())
l=[int(i) for i in input().split()]

ans=0
for i,j,k in permutations(l,3):
    if i<j+k and j<i+k and k<i+j:
        ans+=1
print(ans//6)
        


### FIXED CODE ###

import bisect
n=int(input())
li=[int(i) for i in input().split()]
li.sort()

ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        a=li[i]
        b=li[j]
        c=bisect.bisect_left(li,a+b)
        ans+=c-j-1
                  
print(ans)
### BUGGY CODE ###

n = int(input())
paper = []
for _ in range(n):
    x = int(input())
    if x in paper:
        paper.remove(x)
    else:
        paper.append(x)
print(len(paper))

### FIXED CODE ###

n = int(input())
paper = {}
for _ in range(n):
    x = int(input())
    if x in paper:
        paper[x] += 1
    else:
        paper[x] = 1
count = 0
for i in paper.values():
    if i % 2 != 0: count += 1
print(count)
### BUGGY CODE ###

N=int(input())
S=input()
count=0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if (j-i)!=(k-j) and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                count+=1
print(count)           

### FIXED CODE ###

N=int(input())
S=input()
# N=int(Input[0][0])
# S=Input[1][0]
import math
count=0
counter={'R':0,'G':0,'B':0}
for i in S:
    counter[i]+=1
s=counter['R']*counter['G']*counter['B']
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<=N and (S[i-1]!=S[j-1] and S[i-1]!=S[k-1] and S[j-1]!=S[k-1]):
                count+=1
print(s-count)
### BUGGY CODE ###

H,N =[int(i) for i in input().split()]
AAA = []
BBB = []
for i in range(N):
    buff = [int(i) for i in input().split()]
    AAA.append(buff[0])
    BBB.append(buff[1])

#dp[i]は体力をi減らすまでに必要な魔力の最小値
dp = [10000000000 for i in range(H+5)]
dp[0] = 0
for i in range(H+5):
    for j in range(N):
        A = AAA[j]
        B = BBB[j]
        if i-A>=0:
            dp[i]=min(dp[i],dp[i-A]+B)
        else:
            dp[i]=min(dp[i],B)

#print(dp)
print(dp[H])


### FIXED CODE ###

H,N =[int(i) for i in input().split()]
AAA = []
BBB = []
for i in range(N):
    buff = [int(i) for i in input().split()]
    AAA.append(buff[0])
    BBB.append(buff[1])

#dp[i]は体力をi減らすまでに必要な魔力の最小値
dp = [10000000000 for i in range(H+5)]
dp[0] = 0
for i in range(H+5):
    for j in range(N):
        A = AAA[j]
        B = BBB[j]
        if i-A>=0:
            dp[i]=min(dp[i],dp[i-A]+B)
        else:
            dp[i]=min(dp[i],B)

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

from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

for i in range(n-1):
    for j in range(i+1, n):
        ans += (a[i] % MOD) * (a[j] % MOD)
        ans = ans % MOD

print(ans)

### FIXED CODE ###

from sys import stdin
input = stdin.readline

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

MOD = 1000000007
ans = 0

k = 0
s = [0] * n
for i in range(n-1, 0, -1):
    k += a[i] % MOD
    s[i] = k

for i in range(n-1):
    ans += a[i] * s[i+1]

ans = ans % MOD

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

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

op_cnt = N
Lis = list()
for i in range(2 ** op_cnt):
    op = [0] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = 1
    lis = list()
    for i,j in enumerate(op):
        lis.append(V[i] * j - C[i] * j)
    Lis.append(sum(lis))

print(max(Lis))

### FIXED CODE ###

N = int(input())
V = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
m = 0
for i in range(N):
  if (V[i]-C[i]) > 0:
    m = m + V[i]-C[i]
print(m)
### BUGGY CODE ###

K, S = list(map(int, input().split()))
count = 0
for x in range(K+1):
    for y in range(x, K+1):
        for z in range(y, K+1):
            if x + y + z == S:
                if x == y and y == z:
                    count += 1
                elif x == y or y == z or z == x:
                    count += 3
                else:
                    count += 6
                break
print(count)


### FIXED CODE ###

K, S = list(map(int, input().split()))
count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if z <= K and z >= 0:
            count += 1
print(count)
### BUGGY CODE ###

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

cnt=0
for i in range(N):
    cnt= cnt + sum([(L[i:][x]+L[i])==x for x in range(N-i)])
    
print(cnt)

### FIXED CODE ###

def main():
    N=int(input())
    L=list(map(int,input().split()))
    L_i,L_j=[],[]
    L_memo = [0]*N
    cnt=0
    for i, j in enumerate(L):
        if i+j<N:
            L_memo[i+j]+=1
        if i-j>0:
            cnt+=L_memo[i-j]        
    print(cnt)
main()
### BUGGY CODE ###

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

A = []
B = []
buff = [0 for i in range(N+1)]
buff2 = [0 for i in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        A.append(b)
        # buff[b] = 1
        buff[b] = 1
    if b == N:
        B.append(a)
        buff2[a] = 1

# print(buff)
# print(buff2)

seikai1 = []
for i in range(N+1):
    if buff[i] == 1:
        seikai1.append(i)

for i in range(N+1):
    if buff2[i] == 1:
        if i in seikai1:
            print('POSSIBLE')
            exit()
# for i in range(len(buff)):
#     for j in range(len(buff2)):
#         if buff[i] == 1 and buff2[j] == 1:
#             print('POSSIBLE')
#             exit()

print('IMPOSSIBLE')



### FIXED CODE ###

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

A = []
B = []
buff = [0 for i in range(N+1)]
buff2 = [0 for i in range(N+1)]

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        A.append(b)
        # buff[b] = 1
        buff[b] = 1
    if b == N:
        B.append(a)
        buff2[a] = 1

for i in range(N+1):
    if buff[i] == 1 and buff2[i] == 1:
        print('POSSIBLE')
        exit()



# print(buff)
# print(buff2)

# seikai1 = []
# for i in range(N+1):
#     if buff[i] == 1:
#         seikai1.append(i)

# for i in range(N+1):
#     if buff2[i] == 1:
#         if i in seikai1:
#             print('POSSIBLE')
#             exit()
# for i in range(len(buff)):
#     for j in range(len(buff2)):
#         if buff[i] == 1 and buff2[j] == 1:
#             print('POSSIBLE')
#             exit()

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

S = input()

res = S.count("BW")
is_keep_loop = res > 0
while(is_keep_loop):
    S = S.replace("BW","WB")
    tmp = S.count("BW")
    is_keep_loop =  tmp > 0
    res += tmp

print(res)

### FIXED CODE ###

S = input()

B_num = S.count("B")
W_num = S.count("W")

B_start = W_num # 一番左のBがいていいindex

res = 0
for i in range(B_start + 1):
    if i == len(S):
        break
    if S[i] == "B":
        res += B_start - i
        B_start += 1
        while(B_start < len(S) and S[B_start] == "B"):
            B_start += 1

print(res)
### BUGGY CODE ###

def f(x):
    result = 0
    for i in range(N):
        t = x // F[i]
        if t < A[i]:
            result += A[i] - t
    return result


N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

lo = 0
hi = A[-1] * F[0]
while lo < hi:
    mid = (lo+hi)//2
    if K - f(mid) < 0:
        lo = mid+1
    else:
        hi = mid
print(lo)


### FIXED CODE ###

def f(x, A, F):
    result = 0
    for i in range(N):
        t = x // F[i]
        if t < A[i]:
            result += A[i] - t
    return result


N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)

lo = 0
hi = A[-1] * F[0]
while lo < hi:
    mid = (lo+hi)//2
    if K - f(mid, A, F) < 0:
        lo = mid+1
    else:
        hi = mid
print(lo)
### BUGGY CODE ###

N = int(input())
a = int(input())
A = [a]
C = [a]

for _ in range(N-1):
    a = (int(input()))
    for i, c in enumerate(C):
        if c < a:
            C[i] = a
            break
    else:
        C.append(a)
print(len(C))




### FIXED CODE ###

from bisect import bisect_right, insort_right
N = int(input())
A = [int(input()) for _ in range(N)][::-1]
res = [A[0]]
for a in A[1:]:
    idx = bisect_right(res, a)
    if idx == len(res):
        res.append(a)
    else:
        if res[idx] == a:
            insort_right(res, a)   
        else:
            res[idx] = a
print(len(res))
### BUGGY CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a =list(map(int, input().split()))
    b = sum(a)
    res = 10000000000000000
    for i in range(n-1):
        s = sum(a[:i+1])
        t = b-s
        res = min(res, abs(s-t))
    print(res)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a =[0]+list(map(int, input().split()))
    b = list(accumulate(a))
    c = sum(a)
    res = 10000000000000000
    for i in range(1, n):
        s = b[i]
        t = c-s
        res = min(res, abs(s-t))
    print(res)


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

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

filled = [0]*(n+1)
ans = []
for i in range(n-1, -1, -1):
  if sum(filled[i:][::i+1]) % 2 != A[i]:
    filled[i] = 1
    ans.append(i+1)
print(len(ans))
print(' '.join(map(str, ans)))

### FIXED CODE ###

# from other person's code
n = int(input())
a = list(map(int, input().split()))
ls = [0]*(n+1)
ans = []
for i in reversed(list(range(n))):
    if sum(ls[::i+1][1:]) % 2 != a[i]:
        ls[i+1] = 1
        ans.append(i+1)
print(sum(ls))
if ans: print(' '.join(map(str, ans)))