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

def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]

    N = int(input())
    S = list(input())

    if S[0]!='B' or S[-1]!='B':
        print(0)
        exit()

    mod = 10**9 + 7
    cnt_l = 1
    cnt_r = 0
    pre = 'B'
    pre_d = 1 #1がleft
    ans = 1

    for i in range(1,N*2):
        s = S[i]
        pre = S[i-1]
        if pre==s:
            if pre_d:
                pre_d = 0
                ans *= cnt_l - cnt_r #ここまでに出てきたLeftの総数 - ここまでに出てきたrightの総数
                cnt_r += 1
            else:
                pre_d = 1
                cnt_l += 1
        else:
            if pre_d:
                cnt_l += 1
            else:
                ans *= cnt_l - cnt_r #ここまでに出てきたLeftの総数 - ここまでに出てきたrightの総数
                cnt_r += 1

    for i in range(1,N+1):
        ans *= i
        ans %= mod
    if cnt_l!=N:
        print(0)
        exit()

    print(ans)

if __name__=='__main__':
    main()

### FIXED CODE ###

import math
n = int(input())
S = input()
 
RL = [None]*2*n
 
for i in range(2*n):
    if i % 2 == 0:
        if S[i] == 'B':
            RL[i] = 'L'
        else:
            RL[i] = 'R'
 
    else:
        if S[i] == 'B':
            RL[i] = 'R'
        else:
            RL[i] = 'L'
 
if S[0] == 'W' or S[-1] == 'W':
    print(0)
    exit()
 
left = 0
count = 1
mod = 10**9 + 7
 
for check in RL:
    if check == 'L':
        left += 1
    else:
        count = count * left % mod
        left -= 1
 
    if left < 0:
        print(0)
        exit()
 
count = count * math.factorial(n) % mod
 
if left != 0:
    print(0)
else:
    print(count)
### BUGGY CODE ###

x,y = map(int,input().split())
count = 1
while(1):
    if count*x % y != 0:
        print(count*x)
        break
    if count+x > 10**18:
        print("-1")
        break

### FIXED CODE ###

x,y = map(int,input().split())
if x % y == 0:
    print("-1")
else:
    print(x)
### BUGGY CODE ###

#整数の入力
N = int(input())
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

ans = 0
for i in range(N):
  ans = A_list.count(i+1)
  print(ans)


### FIXED CODE ###

#整数の入力
N = int(input())
#スペース区切りの整数の入力リスト
A_list = list(map(int, input().split()))

ans = 0
  
  
ans_list = [0]*N
  
for i in range(len(A_list)):
  #ans = A_list.count(i+1)
  ans_list[A_list[i]-1]+=1


for i in range(len(ans_list)):
  print(ans_list[i])
### BUGGY CODE ###

from fractions import gcd
m=10**9+7
n=int(input())
L=list(map(int,input().split()))
g=L[0]
for i in range(n-1):
    g=(g*L[i+1])//gcd(g,L[i+1])
r=0
for i in range(n):
    r+=g//L[i]%m
print(r%m)

### FIXED CODE ###

from collections import defaultdict

n=int(input())
A=list(map(int,input().split()))
MOD=10**9+7
L=defaultdict(int)

def soinsu(n):
	l=defaultdict(int)
	for j in range(2,int(n**0.5)+1):
		while n%j==0:
			l[j]+=1
			n//=j
	if l=={}:
			l[n]+=1
	else:
		if n!=1:
			l[n]+=1
	for k,v in l.items():
		L[k]=max(L[k],v)

for i in range(n):
	soinsu(A[i])

LM=1
for k,v in L.items():
	LM*=k**v
	LM%=MOD

r=0
for i in range(n):
	r+=LM*pow(A[i],MOD-2,MOD)
	r%=MOD
print(r)
### BUGGY CODE ###

def func(n):
    cnt = 0
    for x in range(1, 33):
        if(x**2+3+2*x > n):
            break
        for y in range(x, 33):
            if(x**2+y**2+x*y+x+y+1 > n):
                break
            for z in range(y, 33):
                if(x**2+y**2+z**2+x*y+y*z+z*x == n):
                    if(x == y == z):
                        cnt += 1
                    elif(x != y and y != z and z != x):
                        cnt += 6
                    else:
                        cnt += 3
                    break
                elif(x**2+y**2+z**2+x*y+y*z+z*x > n):
                    break
        
    return cnt

N = int(input())
    
for i in range(1, N+1):
    print(func(i))

### FIXED CODE ###

def func(n):
    cnt = 0
    a = int(n**0.5)
    for x in range(1, a+1):
        for y in range(x, a+1):
            z = y
            while(x**2+y**2+z**2+x*y+y*z+z*x <= n):
                if(x**2+y**2+z**2+x*y+y*z+z*x == n):
                    if(x == y == z):
                        cnt += 1
                    elif(x != y and y != z and z != x):
                        cnt += 6
                    else:
                        cnt += 3    
                    break
                z += 1
    return cnt

N = int(input())
    
for i in range(1, N+1):
    print(func(i))
### BUGGY CODE ###

from collections import deque
N = int(input())
A = [int(n) for n in input().split()]
d = deque(A)
for i in range(1, N+1):
    print(d.count(i))


### FIXED CODE ###

from sys import stdin
N = int(input())
A = [0]*2 + [int(n) for n in stdin.readline().split()]
ans = [0]+[0]*N
for i in range(2, N+1):
    ans[A[i]] += 1
for i in range(1, N+1):
    print(ans[i])
### BUGGY CODE ###

D, G = map(int, input().split())
pc = [[i + 1] + [int(x) for x in input().split()] for i in range(D)]

import math
m = {}
def f(cur, n, left):
    if left <= 0:
        return n
    def g(cur, n, left):
        if cur in m: return m[cur]
        r = m[cur] = f(cur, n, left)
        return r
    ret = 10**9
    for x in pc:
        i, p, c = x
        if i in cur: continue
        if i*100*p > left:
            h = math.ceil(left / (i*100))
            ret = min(ret, n + h)
        else:
            if n + p >= ret: continue
            cur.add(i)
            h = f(cur, n + p, max(0, left - i*100*p - c))
            cur.remove(i)
            ret = min(ret, h)
    return ret

print(f(set(), 0, G))

### FIXED CODE ###

D, G = map(int, input().split())
pc = [[i + 1] + [int(x) for x in input().split()] for i in range(D)]

import math
m = {}
def f(cur, n, left):
    if left <= 0:
        return n
    def g(cur, n, left):
        if cur in m: return m[cur]
        r = m[cur] = f(cur, n, left)
        return r
    ret = 10**9
    for x in pc:
        i, p, c = x
        if (1 << i) & cur: continue
        ip = i*100*p
        if ip > left:
            h = math.ceil(left / (i*100))
            ret = min(ret, n + h)
        else:
            if n + p >= ret: continue
            h = g(cur | (1 << i), n + p, left - ip - c)
            ret = min(ret, h)
    return ret

print(f(0, 0, G))
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
a.sort
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        ans = -1
        exit

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
if a[0] == 0:
    ans = 0
    print(ans)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()

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

N = int(input())
S = input()

from collections import defaultdict
d = defaultdict(list)

for ix, c in enumerate(S):
    d[c].append(ix+1)

ans = len(d["B"]) * len(d["G"]) * len(d["R"])

for i in range(1, N+1):
    ci = S[i-1]
    for j in range(i+1, N+1):
        cj = S[j-1]

        if ci == cj:
            continue

        k = 2 * j - i
        if k > j and k <= N:
            ck = S[k-1]
            if ci != ck and cj != ck:
                ans -= 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()

from collections import defaultdict
# d = defaultdict(list)
d = defaultdict(int)

for ix, c in enumerate(S):
    # d[c].append(ix+1)
    d[c] += 1

# ans = len(d["B"]) * len(d["G"]) * len(d["R"])
ans = d["R"] * d["G"] * d["B"]

for i in range(1, N+1):
    ci = S[i-1]
    for j in range(i+1, N+1):
        cj = S[j-1]

        if ci == cj:
            continue

        k = j + j - i
        if k <= N:
            ck = S[k-1]
            if ci != ck and cj != ck:
                ans -= 1
        else:
            break
print(ans)
### BUGGY CODE ###

import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
s = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    for k in range(1, k+1):
      s += gcd(i, j, k)
print(s)

### FIXED CODE ###

import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
l = list(range(1, k+1))                                                
s = 0

for i in itertools.product(l, repeat=3):
  s += gcd(*i)
print(s)
### BUGGY CODE ###

import bisect
import copy

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
A2 = copy.deepcopy(A[N-M:])

for _ in range(M):
  tmp_a = int(A2[-1]/2)
  del A2[-1]
  A2.insert(bisect.bisect_left(A2,tmp_a),tmp_a)
print(sum(A[:N-M])+sum(A2))

### FIXED CODE ###

import heapq

N,M = map(int,input().split())
A = []
for a in map(int,input().split()):
  heapq.heappush(A,-a)

cnt = 0
while cnt < M:
  a = heapq.heappop(A)
  heapq.heappush(A,-((-a)//2))
  cnt += 1
print(-sum(A))
### BUGGY CODE ###

# ABC 152 C

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

res = 0

for i in range(N):
    if P[i] <= min(P[:i+1]):
        res += 1
    else:
        continue

print(res)

### FIXED CODE ###

# ABC 152 C

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

res = 0
minP = 10 ** 9

for i in range(N):
    if P[i] <= minP:
        res += 1
        minP = P[i]
    else:
        continue

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

from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10 ** 7)
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q=map(int,readline().split())
stx = [[int(x) for x in readline().split()] for _ in range(n)]
event=[]
stop=set()
for s,t,x in stx:
    event.append([s-x,1,x])
    event.append([t-x,-1,x])
event.sort()
d=[int(readline()) for _ in range(q)]

k=0
for i in range(q):
    while k<2*n and event[k][0]<=d[i]:
        if event[k][1]==1: stop.add(event[k][2])
        else: stop.remove(event[k][2])
        k+=1
    print(min(stop) if stop!=set() else -1)


### FIXED CODE ###

def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    event=[]
    for _ in range(n):
        s,t,x=map(int,input().split())
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(input()),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()
### BUGGY CODE ###

# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]

# dp[w]: 容量wのナップザックの価値の総和の最大値
dp = [0] * (W + 1)
for weight, value in L:
    for w in range(W + 1)[::-1]:
        if w - weight < 0:
            continue
        dp[w] = max(dp[w], dp[w - weight] + value)

print(dp[W])


### FIXED CODE ###

# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]

# dp[w]: 容量wのナップザックの価値の総和の最大値
dp = [0] * (W + 1)
for weight, value in L:
    for w in range(W + 1)[::-1]:
        if w - weight < 0:
            continue
        dp[w] = max(dp[w], dp[w - weight] + value)

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

N=int(input())
a=list(map(int,input().split()))
A=[0]*N
B=[]
count=0
for i in range(N)[::-1]:
    asum=0
    for j in range(i,N):
        if (j+1)%(i+1)==0:
            asum=asum+A[j]
    if asum%2==a[i]:
        A[i]=0
    else:
        A[i]=1
        B.append(i+1)
        count=count+1
print(count)
if count!=0:
    print(*B)

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
A=[0]*N
B=[]
for i in range(N//2,N):
    if a[i]==1:
        A[i]=1
        B.append(i+1)
for i in range(N//2)[::-1]:
    asum=0 
    x=i+1
    for j in range(i,N,x):
        asum=asum+A[j]
    if asum%2!=a[i]:
        A[i]=1
        B.append(i+1)
count=sum(A)
print(count)
if count!=0:
    print(*B)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
ans = 1
while ans > 0:
    ans = M // N
    if M % ans == 0 and M / ans >= N:
        break
    N += 1
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().strip().split())
ans = 1
if N == 1:
    print(M)
    exit()

for n in range(2, int(M ** 0.5) +1):
    if M % n == 0:
        if n < N and M // n < N:
            continue
        elif n >= N and M // n < N:
            ans = max(ans, M // n)
        elif n < N and M // n >= N:
            ans = max(ans, n)
        else:
            ans = max(ans, n, M // n)

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

n = int(input())

words = []

for i in range(n):
    words.append(input())

words_s = sorted(list(set(words)))

most = []

max_count = 0

for i in words_s:
    a = words.count(i)
    if a > max_count:
        max_count = a
        most = []
        most.append(i)
    elif a == max_count:
        most.append(i)

for i in range(len(most)):
    print(most[i])

### FIXED CODE ###

n = int(input())

words = [input() for _ in range(n)]

d = {}

for i in range(n):
    if words[i] not in d:
        d[words[i]] = 1
    else:
        d[words[i]] += 1

m = max(d.values())
ANS = []

for keys in d.keys():
    if d[keys] == m:
        ANS.append(keys)

ANS = sorted(ANS)

for i in ANS:
    print(i)
### BUGGY CODE ###

import math

k = int(input())
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1, k+1):
            total += math.gcd(math.gcd(i,j), math.gcd(i,l))
print(total)


### FIXED CODE ###

import math

k = int(input())
total = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        sub_gcd = math.gcd(i,j)
        for l in range(1, k+1):
            total += math.gcd(sub_gcd, l)
print(total)
### BUGGY CODE ###

import collections

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

visited = [[-float("inf")]*w for _ in range(h)]
q = collections.deque([])

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            q.appendleft([i, j])
            visited[i][j] = 0

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

while len(q):
    cy, cx = q.pop()
    for i in range(4):
        x = cx + dx[i]
        y = cy + dy[i]

        if 0 <= x < w and 0 <= y < h and visited[y][x] == -float("inf"):
            visited[y][x] = visited[cy][cx] + 1
            q.appendleft([y, x])

ans = -1
for i in range(h):
    for j in range(w):
        ans = max(ans, visited[i][j])
print(ans)


### FIXED CODE ###

from subprocess import call
call (('pypy3', '-c', """
from collections import deque

def main():
    h, w = map(int, input().split())
    A = [list(input()) for _ in range(h)]
    d = [[10**9] * w for _ in range(h)]
    que = deque([])
    
    for i in range(h):
        for j in range(w):
           if A[i][j] == "#":
               que.append([i, j])
               d[i][j] = 0
           else:
               d[i][j] = 10 ** 9
            
    while que:
        x, y = que.popleft()
        dx = [1, 0, -1, 0]
        dy = [0, 1, 0, -1]
        for i in range(4): 
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < h and 0 <= ny < w and d[nx][ny] == 10**9:
                d[nx][ny] = d[x][y] + 1
                que.append([nx, ny])
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, d[i][j])
    print(ans)
    
    return
    
main()

"""))
### BUGGY CODE ###

n,k=map(int,input().split())
mod=998244353
r=[0]*k
l=[0]*k
for _ in range(k):
  l_,r_=map(int,input().split())
  l[_]=l_
  r[_]=r_
dp=[0]*n
dp[0]=1
dpsum=[0]*n
dpsum[0]=1
for i in range(1,n):
  for j in range(k):
    li=i-r[j]
    ri=i-l[j]
    if ri>=0:
      li=max(li,0)
      dp[i]+=dpsum[ri]-dpsum[li-1]
  dpsum[i]=dpsum[i-1]+dp[i]
print(dp[n-1]%mod)

### FIXED CODE ###

n,k=map(int,input().split())
mod=998244353
l=[0]*n
r=[0]*n
for i in range(k):
  l[i],r[i]=map(int,input().split())
dp=[0]*(n+10)
dp[0]=1
sumdp=[0]*(n+10)
sumdp[1]=1
for i in range(1,n):
  for j in range(k):
    li=max(0,i-r[j])
    ri=max(0,i-l[j]+1)
    dp[i]+=sumdp[ri]-sumdp[li]
  sumdp[i+1]=(sumdp[i]+dp[i])%mod
print(dp[n-1]%mod)
### BUGGY CODE ###

d = {"Male" : 1, "Female" : 2, "Vacant" : 0}

def check(l, r, a, b):
	if (a == b):
		return ((r - l + 1) % 2 == 1)
	else:
		return ((r - l + 1) % 2 == 0)

def get(k):
	print(k - 1)
	return d[input()]

def main():
	n = int(input())
	left = get(1)
	if (left == 0): return
	right = get(n)
	if (right == 0): return

	l, r = 1, n
	while (l + 2 < r):
		m = (l + r) // 2
		med = get(m)
		if (med == 0): return
		if (check(l, m, left, med)):
			right, r = med, m
		else:
			left, l = med, m
	get(l + 1)

main()

### FIXED CODE ###

d = {"Male" : 1, "Female" : 2, "Vacant" : 0}

def check(l, r, a, b):
	if (a != b):
		return ((r - l + 1) % 2 == 1)
	else:
		return ((r - l + 1) % 2 == 0)

def get(k):
	print(k - 1)
	return d[input()]

def main():
	n = int(input())
	left = get(1)
	if (left == 0): return
	right = get(n)
	if (right == 0): return

	l, r = 1, n
	while (l + 2 < r):
		m = (l + r) // 2
		med = get(m)
		if (med == 0): return
		if (check(l, m, left, med)):
			right, r = med, m
		else:
			left, l = med, m
	get(l + 1)

main()
### BUGGY CODE ###

# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
minus = 0
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        tmp = heapq.heappop(A)
        if c > tmp:
            heapq.heappush(A, c)
        else:
            heapq.heappush(A, tmp)
print(sum(A))

### FIXED CODE ###

# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
minus = 0
l = []
for i in range(M):
    b, c = map(int, input().split())
    l.append([b, c])
l.sort(key=lambda x: x[1], reverse=True)
A.sort(reverse=False)
idx = 0
i = 0
ans = 0
while i < N and idx < M:
    if l[idx][0] == 0:
        idx += 1
    if idx >= M:
        ans += A[i]
        i += 1
        continue
    if A[i] < l[idx][1]:
        ans += l[idx][1]
        l[idx][0] -= 1
        i += 1
    else:
        ans += A[i]
        i += 1
    # print("ans =", ans)
for j in range(i, N):
    ans += A[j]
print(ans)
### BUGGY CODE ###

from functools import reduce

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

# def calc(A, i):

values = [
    str(reduce(lambda x, y: x ^ y, map(lambda v: v[1], filter(lambda v: v[0] != i, enumerate(A)))))
    # calc(A, i)
    for i in range(len(A))
]
print(" ".join(values))

### FIXED CODE ###

from functools import reduce

N = int(input().strip())
A = [int(x) for x in input().strip().split(" ")]
xor = reduce(lambda x, y: x ^ y, A)

print(" ".join([
    str(xor ^ a)
    for a in A
]))
### BUGGY CODE ###

from sys import stdin
from itertools import accumulate

def solve():
    file_input = stdin
     
    N = int(file_input.readline())
    img = tuple(tuple(map(int, line.split())) for line in file_input)
    
    acc_row = tuple(tuple(accumulate(line)) + (0,) for line in img)
    acc_col = tuple(tuple(accumulate(line)) + (0,) for line in zip(*img))
    
    ans = 0
    for i, tpl_1 in enumerate(zip(img, acc_row)):
        img_i, acc_row_i = tpl_1
        for j, tpl_2 in enumerate(zip(img[i:], acc_row[i:]), start=i):
            img_j, acc_row_j = tpl_2
            
            if acc_row_i[j] - acc_row_i[i - 1] > ans:
                ans = acc_row_i[j] - acc_row_i[i - 1]
                
            if i == j:
                continue
            
            col = acc_col[0]
            col_max = col[j] - col[i - 1]
            
            for acc_col_k, img_i_k, img_j_k in zip(acc_col[1:], img_i[1:], img_j[1:]):
                col = acc_col_k[j] - acc_col_k[i - 1]
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + img_i_k + img_j_k
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()


### FIXED CODE ###

from sys import stdin
from itertools import accumulate

def solve():
    file_input = stdin
    
    N = int(file_input.readline())
    G = tuple(tuple(map(int, line.split())) for line in file_input)
    G1 = tuple(t[1:] for t in G)
    
    # accumulated rows
    ar = ((0,) + tuple(accumulate(line)) for line in G)
    
    # accumulated columns
    ac = ((0,) + tuple(accumulate(line)) for line in zip(*G))
    ac_1 = next(ac)
    ac = tuple(zip(*ac))
    
    ans = 0
    for i, t1 in enumerate(zip(G1, ar, ac, ac_1)):
        G_i, ar_i, ac_i, ac_1i = t1
        ar_ii = ar_i[i]
        for j, t2 in enumerate(zip(G1[i:], ar_i[i+1:], ac[i+1:], ac_1[i+1:]), start=i):
            G_j, ar_ij, ac_j, ac_1j = t2
            single_row = ar_ij - ar_ii
            if single_row > ans:
                ans = single_row
                
            if i == j:
                continue
            
            col_max = ac_1j - ac_1i
            
            for ac_jk, ac_ik, G_ik, G_jk in zip(ac_j, ac_i, G_i, G_j):
                col = ac_jk - ac_ik
                
                if col_max > 0:
                    c_ans = col_max + col
                    if c_ans > ans:
                        ans = c_ans
                else:
                    if col > ans:
                        ans = col
                
                t_col_max = col_max + G_ik + G_jk
                if t_col_max > col:
                    col_max = t_col_max
                else:
                    col_max = col
    print(ans)

solve()
### BUGGY CODE ###

S = input()

count = 0

while '01' in S or '10' in S:
    if '01' in S:
        count += S.count('01')
        S = S.replace('01', '')
    if '10' in S:
        count += S.count('10')
        S = S.replace('10', '')

print(count * 2)


### FIXED CODE ###

S = input()

count_0 = S.count('0')
count_1 = S.count('1')

print(min(count_0, count_1) * 2)
### BUGGY CODE ###

r, g, b, n = map(int, input().split())
ans = 0

for i in range(n // r + 1):
  for j in range(n // g + 1):
    if (n - (i * r) - (j * g) )% b == 0 and 0 <= (n - (i * r) - (j * g) )//b<= n//b :
      ans += 1

      
print(ans)

### FIXED CODE ###

r, g, b, n = map(int, input().split())
ans = 0

for i in range(n // r + 1):
  for j in range(n // g + 1):
    if (n - (i * r) - (j * g) )% b == 0 and 0 <= (n - (i * r) - (j * g) )//b<= n//b :
      ans += 1

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

import heapq
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
    print(a[0])
    exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
    d = max(math.floor(aa / mean_a)-1, 1)
    q.append((-aa/d, d))
    k -= (d-1)
heapq.heapify(q)

for _ in range(k):
    aa, n = heapq.heappop(q)
    heapq.heappush(q, (aa*n/(n+1), n+1))

ans, _ = heapq.heappop(q)
print(math.ceil(-ans))


### FIXED CODE ###

import heapq
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
if k == 0:
    print(a[0])
    exit(0)
mean_a = sum(a) / k
q = []
for aa in a:
    d = max(math.floor(aa / mean_a), 1)
    q.append((-aa/d, d))
    k -= (d-1)
heapq.heapify(q)

for _ in range(k):
    aa, n = heapq.heappop(q)
    heapq.heappush(q, (aa*n/(n+1), n+1))

ans, _ = heapq.heappop(q)
print(math.ceil(-ans))
### BUGGY CODE ###

N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
common = set(range(LR[0][0], LR[0][1]+1))
for lr in LR:
    common = common & set(range(lr[0], lr[1]+1))
print(len(common))    

### FIXED CODE ###

import numpy as np
N, M = map(int, input().split())
LR = np.array([list(map(int, input().split())) for _ in range(M)])
lmax, rmin = LR.max(axis=0)[0], LR.min(axis=0)[1]
print(max(0, rmin-lmax+1))