#
import collections, atexit, math, sys, bisect

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        print(*args, **kwargs, file=sys.stderr)
    dprint('debug mode')
except Exception:
    def dprint(*args, **kwargs):
        pass

inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit

N, = getIntList()
#print(N)
S = input()

X, Y = getIntList()

dd = ( (0,1), (0,-1), (-1,0), (1,0))
pp = 'UDLR'
zz = {}
for i in range(4):
    zz[ pp[i]] = dd[i]

if abs(X) + abs(Y) >N:
    print(-1)
    return

if abs(X+Y-N)%2==1:
    print(-1)
    return

fromLeft = [None for i in range(N)]
fromRight = fromLeft.copy()

x0 = 0
y0 = 0
for i in range(N):
    x = S[i]
    fromLeft[i] = (x0,y0)
    g = zz[x]
    x0+= g[0]
    y0+= g[1]

if x0==X and y0==Y:
    print(0)
    return

x0 = 0
y0 = 0
for i in range(N-1,-1,-1):
    x = S[i]
    fromRight[i] = (x0,y0)
    g = zz[x]
    x0+= g[0]
    y0+= g[1]

up = N
down = 0
dprint(fromLeft)
dprint(fromRight)
while down+1<up:
    mid = (up+down)//2
    dprint('mid', mid)
    ok = False
    for i in range(N-mid + 1):
        tx = fromLeft[i][0] + fromRight[i+mid-1][0]
        ty = fromLeft[i][1] + fromRight[i+mid-1][1]
        gg = abs(X-tx) + abs(Y- ty)
        if gg <= mid:
            ok = True
            break
    if ok:
        up = mid
    else:
        down = mid

print(up)


def doable(n,x,y,m, prefixLR, prefixUD):
	for i in range(n-m+1):
		j = i + m - 1
		dx = prefixLR[i] + prefixLR[-1] - prefixLR[j+1]
		dy = prefixUD[i] + prefixUD[-1] - prefixUD[j+1]
		if abs(x - dx) + abs(y - dy) <= m:
			return True
	return False

def main():
	n = int(input())
	s = list(input().strip())
	x,y = map(int, input().strip().split())

	k = abs(x) + abs(y)
	if k > n or k % 2 != n % 2:
		print(-1)
		return

	prefixLR = [0] * (n + 1)
	prefixUD = [0] * (n + 1)

	for i in range(n):
		prefixLR[i+1] = prefixLR[i]
		prefixUD[i+1] = prefixUD[i]
		if s[i] == 'L':
			prefixLR[i+1] -= 1
		elif s[i] == 'R':
			prefixLR[i+1] += 1
		elif s[i] == 'D':
			prefixUD[i+1] -= 1
		else:
			prefixUD[i+1] += 1

	left = 0
	right = n

	while left < right:
		mid = left + (right - left) // 2
		if doable(n,x,y,mid, prefixLR, prefixUD):
			right = mid
		else:
			left = mid + 1

	print(left)

def __starting_point():
	main()
__starting_point()


n = int(input())
s = input()
p,q = input().split()
if p[0] == '-':
    x = -1*int(p[1:])
else:
    x = int(p)
if q[0] == '-':
    y = -1*int(q[1:])
else:
    y = int(q)
cur = [0,0]
if(abs(x)+abs(y) > n):
    print(-1)
elif((x+y)%2 != n%2):
    print(-1)
else:
    end = n
    for i in range(n):
        if s[i] == "R":
            cur[0] += 1
        if s[i] == "L":
            cur[0] -= 1
        if s[i] == "U":
            cur[1] += 1
        if s[i] == "D":
            cur[1] -= 1
        if(abs(x-cur[0])+abs(y-cur[1]) >= n-i):
            end = i
            break
    if end == n:
        print(0)
    else:
        m = [0]*(end+1)
        start = n
        for i in range(end,-1,-1):
            if s[i] == "R":
                cur[0] -= 1
            if s[i] == "L":
                cur[0] += 1
            if s[i] == "U":
                cur[1] -= 1
            if s[i] == "D":
                cur[1] += 1
            while(abs(x-cur[0])+abs(y-cur[1]) <= start-i):
                start -= 1
                if s[start] == "R":
                    x -= 1
                if s[start] == "L":
                    x += 1
                if s[start] == "U":
                    y -= 1
                if s[start] == "D":
                    y += 1
            m[i] = start-i+1
        minn = n
        for i in m:
            minn = min(minn,i)
        print(minn)


def valid(step, tx, ty, nx, ny, s, d):
    fx = 0
    fy = 0
    for i in range(len(s)):
        # insert
        c = s[i]
        fx += d[c][0]
        fy += d[c][1]
        if i >= step:
            # remove
            c = s[i-step]
            fx -= d[c][0]
            fy -= d[c][1]
        if i >= step-1:
            diff = abs(nx-fx-tx) + abs(ny-fy-ty)
            if diff <= step and (step - diff) % 2 == 0:
                return True
    return False

def main():
    d = {
        "U": (0, 1),
        "D": (0, -1),
        "L": (-1, 0),
        "R": (1, 0)
    }
    nx = 0
    ny = 0

    n = int(input())
    s = input()
    tx, ty = [int(x) for x in input().split(" ")]

    diff = abs(tx) + abs(ty)
    if diff > len(s) or (diff-len(s)) % 2 == 1:
        print(-1)
        return

    for c in s:
        nx += d[c][0]
        ny += d[c][1]
    if (nx, ny) == (tx, ty):
        print(0)
        return
    l = 0
    r = len(s)
    ans = r

    while l < r:
        m = (l+r)//2
        if valid(m, tx, ty, nx, ny, s, d):
            ans = m
            r = m
        else:
            l = m+1
    print(ans)

def __starting_point():
    main()

__starting_point()


n=int(input())
s=list(input())
a,b = list(map(int, input().split()))
L=s.count('L')
U=s.count('U')
R=s.count('R')
D=s.count('D')
x=0
y=0
xmin=0
ymin=0
minn=2*n
while x+y<2*n:
    if abs(a-(R-L))+abs(b-(U-D))>y-x and y!=n:
        i=s[y]
        if i=='L':
            L-=1
        elif i=='R':
            R-=1
        elif i=='D':
            D-=1
        elif i=='U':
            U-=1
        y+=1
    elif abs(a-(R-L))+abs(b-(U-D))<=y-x or y==n:
        if y-x<minn and abs(a-(R-L))+abs(b-(U-D))<=y-x:
            minn=y-x
        i=s[x]
        if i=='L':
            L+=1
        elif i=='R':
            R+=1
        elif i=='D':
            D+=1
        elif i=='U':
            U+=1
        x+=1

if abs(a)+abs(b)>len(s):
    print(-1)
elif (len(s)-(abs(a)+abs(b)))%2!=0:
    print(-1)
else:
    print(minn)


import sys

n=int(input())
S=input()
x,y=list(map(int,input().split()))

if abs(x)+abs(y)>n or (abs(x)+abs(y))%2!=n%2:
    print(-1)
    return

now=[0,0]
LISTL=[(0,0)]
for s in S:
    if s=="R":
        now[0]+=1
    elif s=="L":
        now[0]-=1
    elif s=="U":
        now[1]+=1
    else:
        now[1]-=1

    LISTL.append((now[0],now[1]))

LISTR=[(0,0)]
now=[0,0]
for s in S[::-1]:
    if s=="R":
        now[0]+=1
    elif s=="L":
        now[0]-=1
    elif s=="U":
        now[1]+=1
    else:
        now[1]-=1

    LISTR.append((now[0],now[1]))

def su(a,b,x,y):
    return abs(x-(a[0]+b[0]))+abs(y-(a[1]+b[1]))

ANS=0
for i in range(n+1):
    for j in range(max(0,ANS-i),n+1):
        if su(LISTR[i],LISTL[j],x,y)<=n-i-j:
            #print(i,j)
            if ANS<i+j:
                ANS=i+j

        else:
            break

print(n-ANS)


n = int(input())
dx = [0 for i in range(n + 1)]
dy = [0 for i in range(n + 1)]
for i, ch in enumerate(input()):
    dx[i + 1] = dx[i]
    dy[i + 1] = dy[i]
    if ch == 'U':
        dy[i + 1] += 1
    elif ch == 'D':
        dy[i + 1] -= 1
    elif ch == 'R':
        dx[i + 1] += 1
    else:
        assert ch == 'L'
        dx[i + 1] -= 1
x, y = list(map(int, input().split()))
def canChange(left, right):
    dx1 = dx[left]
    dy1 = dy[left]
    dx3 = dx[-1] - dx[right]
    dy3 = dy[-1] - dy[right]
    dx2 = x - dx1 - dx3
    dy2 = y - dy1 - dy3
    length = right - left
    free = length - (abs(dx2) + abs(dy2))
    return free >= 0 and free % 2 == 0
result = n + 1
ptr = n + 1
for i in reversed(list(range(n))):
    while ptr - 1 >= i and canChange(i, ptr - 1):
        ptr -= 1
        result = min(result, ptr - i)
if ptr == n + 1:
    print(-1)
else:
    print(result)


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

s=list(input())
x,y=list(map(int,input().split()))

it=[0,0,0,0]

for i in range(len(s)):
    if s[i]=='U':
        s[i]=0
    elif s[i]=='R':
        s[i]=1
    elif s[i]=='D':
        s[i]=2
    else:
        s[i]=3
    it[s[i]]+=1

def distance(x,y,xx,yy):
    return abs(x-xx)+abs(y-yy)

def yes(steps,ost,x,y):
    xx=steps[1]-steps[3]
    yy=steps[0]-steps[2]
    return distance(x,y,xx,yy)<=ost

ans=0

if distance(x,y,0,0)>n or (x+y+n)%2==1:
    print(-1)
elif yes(it,0,x,y):
    print(0)
else:
    i=-1
    cur_ans=0
    max_ans=0

    steps=[0,0,0,0]

    while yes(steps,n-cur_ans,x,y):
        i+=1
        steps[s[i]]+=1
        cur_ans+=1

    steps[s[i]]-=1
    i-=1
    cur_ans-=1
    max_ans=cur_ans

    j=n
    ok=True

    while j>0 and ok:
        j=j-1
        steps[s[j]]+=1
        cur_ans+=1

        while i>=0 and not yes(steps,n-cur_ans,x,y):
            steps[s[i]]-=1
            i-=1
            cur_ans-=1

        if yes(steps,n-cur_ans,x,y) and cur_ans>max_ans:
            max_ans=cur_ans
        ok=(i>=0) or yes(steps,n-cur_ans,x,y)

    print(n-max_ans)


import sys
fin = sys.stdin.readline

n = int(fin())
commands = list(fin())[:-1]
x, y = [int(elem) for elem in fin().split(' ')]

move_map = {'L': (-1, 0), 'R': (1, 0), 'U': (0, 1), 'D': (0, -1)}

if (x + y) % 2 != n % 2:
    print(-1)
    return

cuml_coord = [None] * n
cuml_x, cuml_y = 0, 0
for i, command in enumerate(commands):
    dx, dy = move_map[command]
    cuml_x += dx
    cuml_y += dy
    cuml_coord[i] = (cuml_x, cuml_y)

left, right = 0, 0
min_len = 2**32 - 1
org_x, org_y = cuml_coord[-1]
if org_x == x and org_y == y:
    min_len = 0

while right <= n - 1:
    if left == 0:
        left_cuml = 0, 0
    else:
        left_cuml = cuml_coord[left - 1]
    right_cuml = cuml_coord[right]
    movable_x, movable_y = right_cuml[0] - left_cuml[0], \
                           right_cuml[1] - left_cuml[1]
    fixed_x, fixed_y = org_x - movable_x, org_y - movable_y
    sub_length = right - left + 1
    # print(fixed_x, fixed_y, left, right)
    # print(x - fixed_x, y - fixed_y)
    if (abs(x - fixed_x) + abs(y - fixed_y)) <= sub_length \
    and (abs(x - fixed_x) + abs(y - fixed_y)) % 2 == sub_length % 2:
        min_len = min(min_len, sub_length)
        if left != right:
            left += 1
        else:
            right += 1
    else:
        right += 1
if min_len == 2**32 - 1:
    print(-1)
else:
    print(min_len)


import math as ma
import sys
from decimal import Decimal as dec
from itertools import permutations

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

def num():
	return map(int , sys.stdin.readline().split())

def nu():
	return int(sys.stdin.readline())

def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x

n=nu()
s=input()
x,y=num()
uu=[0]*n
rr=[0]*n
pu=[]
pr=[]
for i in range(n):
	if(s[i]=="U"):
		uu[i]=1
	if(s[i]=="D"):
		uu[i] = -1
	if(s[i]=="R"):
		rr[i]=1
	if(s[i]=="L"):
		rr[i]=-1

pu.append(uu[0])
pr.append(rr[0])
for i in range(1,n):
	pu.append(pu[i-1]+uu[i])
for i in range(1,n):
	pr.append(pr[i-1]+rr[i])
pu=[0]+pu
pr=[0]+pr
zu=pu[len(pu)-1]
zr=pr[len(pr)-1]
if((abs(x-zr)+abs(y-zu))==0):
	print(0)
	return
if((abs(x)+abs(y))%2!=n%2 or (abs(x)+abs(y))>n):
	print(-1)
	return

lo=1
hi=n
while(lo<=hi):
	mid=(lo+hi)//2
	fl=False
	for i in range(0,n-mid+1):
		lu=zu-pu[i+mid]+pu[i]
		lr=zr-pr[i+mid]+pr[i]
		if((abs(x-lr)+abs(y-lu))<=mid):
			fl=True
			break
	if(fl==True):
		hi=mid-1
	else:
		lo=mid+1
print(lo)


n = int(input().strip())
s = str(input().strip())
x,y = list(map(int,input().strip().split()))
sumx = []
sumy = []

sx = 0
sy = 0
sumx.append(sx)
sumy.append(sy)
for i in s:
    if(i=='U'):
        sy+=1
    elif(i=='D'):
        sy-=1
    elif(i=='R'):
        sx+=1
    elif(i=='L'):
        sx-=1
    sumx.append(sx)
    sumy.append(sy)

#print("sxy",sx, sy)

def check(mid):
    i=0
    while(i+mid<=n):
        dx = sumx[i+mid]-sumx[i]
        dy = sumy[i+mid]-sumy[i]
        cx = sx-dx
        cy = sy-dy
        #print("cxy",cx,cy)
        gdx = x-cx
        gdy = y-cy
        t=abs(gdx)+abs(gdy)
        #print("t",t)
        if(t%2==mid%2 and t<=mid):
            return True
        i+=1
    return False

hi = n
lo = 0
mid=(hi+lo)//2
while(hi-lo>1):
    mid=(hi+lo)//2
    #print("mid", mid)
    if(check(mid)):
        hi=mid
    else:
        lo=mid
#print(lo)
if(check(lo)):
    print(lo)
elif(check(mid)):
    print(mid)
elif(check(hi)):
    print(hi)
else:
    print(-1)


def check(x, y, fx, fy, num_moves):
	if ((abs(fx - x) +  abs(fy - y))-num_moves) <= 0 and ((abs(fx - x) +  abs(fy - y))-num_moves)%2  == 0:
		return True
	return False

N = int(input())
mm =  {'U':0,'D':1,'L':2,'R':3}

dpmat = [[0] for i in range(4)]

ops =  str(input())

for op in ops:
	dpmat[0].append(dpmat[0][-1])
	dpmat[1].append(dpmat[1][-1])
	dpmat[2].append(dpmat[2][-1])
	dpmat[3].append(dpmat[3][-1])

	dpmat[mm[op]][-1] = dpmat[mm[op]][-1]+1

fpos = list(map(int,input().split()))
if N < fpos[0]+fpos[1]:
	print("-1")
else :
	x,y = 0,0

	ans = 10e10

	while y <= N and x <= y:
		if y == 0 and x == 0:
			num_moves = 0
			xr = dpmat[3][N]
			xl = dpmat[2][N]
			yu = dpmat[0][N]
			yd = dpmat[1][N]
		else:
			num_moves = y-x+1
			xr = dpmat[3][x-1] +  dpmat[3][N] - dpmat[3][y]
			xl = dpmat[2][x-1] +  dpmat[2][N] - dpmat[2][y]
			yu = dpmat[0][x-1] +  dpmat[0][N] - dpmat[0][y]
			yd = dpmat[1][x-1] +  dpmat[1][N] - dpmat[1][y]

		if check(xr-xl, yu-yd, fpos[0], fpos[1], num_moves) == True:
			x += 1
			ans = min(ans, num_moves)
		else:
			if x==0:
				x += 1
			y += 1
	if ans == 10e10:
		print("-1")
	else:
		print(max(0,ans))


3
from collections import Counter

def readint():
    return int(input())

def readline():
    return [int(c) for c in input().split()]

def update(pos, mv, d):
    if mv == 'U':
        pos[1] += d
    elif mv == 'D':
        pos[1] -= d
    elif mv == 'L':
        pos[0] -= d
    elif mv == 'R':
        pos[0] += d

def can(u, v, length):
    d = abs(u[0] - v[0]) + abs(u[1] - v[1])
    if d % 2 != length % 2:
        return False
    return length >= d

def ok(length, n, x, y, s):
    pos = [0, 0]
    for i in range(length, n):
        update(pos, s[i], 1)

    l, r = 0, length
    while True:
        if can(pos, [x, y], length):
            return True
        if r == n:
            break
        update(pos, s[l], 1)
        l += 1
        update(pos, s[r], -1)
        r += 1

    return False

def main():
    n = readint()
    s = input()
    x, y = readline()

    if not ok(n, n, x, y, s):
        print(-1)
        return

    l, r = -1, n
    while r - l > 1:
        mid = (l + r) // 2
        if ok(mid, n, x, y, s):
            r = mid
        else:
            l = mid

    print(r)

def __starting_point():
    main()

"""
#include <bits/stdc++.h>

using namespace std;

const int N = int(1e5) + 9;

string s;
int n;
int x, y;

void upd(pair<int, int> &pos, char mv, int d){
	if(mv == 'U')
		pos.second += d;
	if(mv == 'D')
		pos.second -= d;
	if(mv == 'L')
		pos.first -= d;
	if(mv == 'R')
		pos.first += d;
}

bool can(pair<int, int> u, pair<int, int> v, int len){
	int d = abs(u.first - v.first) + abs(u.second - v.second);
	if(d % 2 != len % 2) return false;
	return len >= d;
}

bool ok(int len){
	pair<int, int> pos = make_pair(0, 0);
	for(int i = len; i < n; ++i)
		upd(pos, s[i], 1);

	int l = 0, r = len;
	while(true){
		if(can(pos, make_pair(x, y), len))
			return true;

		if(r == n) break;
		upd(pos, s[l++], 1);
		upd(pos, s[r++], -1);
	}

	return false;
}

int main() {
	//freopen("input.txt", "r", stdin);

	cin >> n;
	cin >> s;
	cin >> x >> y;

	if(!ok(n)){
		puts("-1");
		return 0;
	}

	int l = -1, r = n;
	while(r - l > 1){
		int mid = (l + r) / 2;
		if(ok(mid)) r = mid;
		else l = mid;
	}

	cout << r << endl;
    return 0;
}
"""

__starting_point()


d = {
	'U': (0, 1),
	'D': (0, -1),
	'L': (-1, 0),
	'R': (1, 0)
}

def compute_delta(s, head_idx, tail_idx):
	x = y = 0
	for i in range(head_idx, tail_idx):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	return x, y

def compute_rest(s, n, head_idx, tail_idx):
	x = y = 0
	for i in range(0, head_idx):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	for i in range(tail_idx, n):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	return x, y

n = int(input())
s = input()
x_d, y_d = list(map(int, input().split()))
# n = 5
# s = 'RURUU'
# x_d, y_d = -2, 3
x_t, y_t = compute_delta(s, 0, n)

# if x_d == x_t and y_d == y_t:
#    print(0)

l, r = 0, n
current_sol = -1
while l <= r:
	# print(l, r)
	local_len = (r + l) // 2

	x_l, y_l = compute_rest(s, n, 0, local_len)
	# print('local_len: ', local_len)
	is_possible = False
	diff = abs(x_d - x_l) + abs(y_d - y_l)
	if diff <= local_len and (diff + local_len) % 2 == 0:
		is_possible = True
	# print('\t', x_l, y_l, abs(x_d - x_l), abs(y_d - y_l), local_len, is_possible)
	for i in range(local_len, n):
		if is_possible:
			break
		d_old, d_new = d[s[i]], d[s[i - local_len]]
		x_l, y_l = x_l - d_old[0] + d_new[0], y_l - d_old[1] + d_new[1]
		# print('\t', x_l, y_l, abs(x_d - x_l), abs(y_d - y_l), local_len)
		diff = abs(x_d - x_l) + abs(y_d - y_l)
		if diff <= local_len and (diff + local_len) % 2 == 0:
			is_possible = True
	# print(l, r, local_len, current_sol, is_possible)
	if is_possible:
		current_sol = local_len
		r = local_len - 1
	else:
		l = local_len + 1
print(current_sol)


d = {
	'U': (0, 1),
	'D': (0, -1),
	'L': (-1, 0),
	'R': (1, 0)
}

def compute_delta(s, head_idx, tail_idx):
	x = y = 0
	for i in range(head_idx, tail_idx):
		x, y = x + d[s[i]][0], y + d[s[i]][1]
	return [x, y]

n = int(input())
s = input()
dsc = list(map(int, input().split()))
total = compute_delta(s, 0, n)

l, r = 0, n
current_sol = -1
while l <= r:
	local_len = (r + l) // 2
	initial_diff = compute_delta(s, 0, local_len)
	local = [total[0] - initial_diff[0], total[1] - initial_diff[1]]
	is_possible = False
	diff = abs(dsc[0] - local[0]) + abs(dsc[1] - local[1])
	if diff <= local_len and (diff + local_len) % 2 == 0:
		is_possible = True
	for i in range(local_len, n):
		if is_possible:
			break
		d_old, d_new = d[s[i]], d[s[i - local_len]]
		local = [local[0] - d_old[0] + d_new[0], local[1] - d_old[1] + d_new[1]]
		diff = abs(dsc[0] - local[0]) + abs(dsc[1] - local[1])
		if diff <= local_len and (diff + local_len) % 2 == 0:
			is_possible = True
	if is_possible:
		current_sol = local_len
		r = local_len - 1
	else:
		l = local_len + 1
print(current_sol)


# -*- coding: utf-8 -*-

"""
created by shhuan at 2018/11/3 11:30

search for minimum steps, consider binary search

"""

N = int(input())
ops = [x for x in input()]

X, Y = list(map(int, input().split()))

dd = abs(X) + abs(Y)
lops = len(ops)
# if dd > lops or (lops - dd) % 2 != 0:
#     print(-1)
#     return

[ll, lr, lu, ld, rl, rr, ru, rd] = [[0 for _ in range(lops + 2)] for _ in range(8)]

l, r, u, d = 0, 0, 0, 0
for i in range(lops):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    ll[i+1] = l
    lr[i+1] = r
    ld[i+1] = d
    lu[i+1] = u

l, r, u, d = 0, 0, 0, 0
for i in range(lops-1, -1, -1):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    rl[i] = l
    rr[i] = r
    rd[i] = d
    ru[i] = u

def check(lsub):
    for i in range(lops-lsub+1):
        # j-i+1 == lsub, j < lops => i+lsub-1 <lops => i < lops-lsub+1
        j = i + lsub - 1

        # l, r, u, d of lops [0, i-1], ll[i]={'L' of 0,...,i-1}
        l0, r0, u0, d0 = ll[i], lr[i], lu[i], ld[i]

        # l, r, u, d of ops [j+1, N-1], rr[j]={'R' of lops-1,...,j}
        l1, r1, u1, d1 = rl[j+1], rr[j+1], ru[j+1], rd[j+1]

        x = (r0+r1) - (l0+l1)
        y = (u0+u1) - (d0+d1)

        dx = abs(X-x)
        dy = abs(Y-y)

        if dx + dy <= lsub and (lsub-dx-dy) % 2 == 0:
            return True

    return False

sl, sr = 0, lops + 1
while sl < sr:
    m = (sl + sr) // 2
    if check(m):
        sr = m
    else:
        sl = m + 1

sl = -1 if sl > lops else sl
print(sl)


# -*- coding: utf-8 -*-

"""
created by shhuan at 2018/11/3 11:30

search for minimum steps, consider binary search

"""

N = int(input())
ops = [x for x in input()]

X, Y = list(map(int, input().split()))

dd = abs(X) + abs(Y)
lops = len(ops)
if dd > lops or (lops - dd) % 2 != 0:
    print(-1)
    return

[ll, lr, lu, ld, rl, rr, ru, rd] = [[0 for _ in range(lops + 2)] for _ in range(8)]

l, r, u, d = 0, 0, 0, 0
for i in range(lops):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    ll[i+1] = l
    lr[i+1] = r
    ld[i+1] = d
    lu[i+1] = u

l, r, u, d = 0, 0, 0, 0
for i in range(lops-1, -1, -1):
    op = ops[i]
    if op == 'L':
        l += 1
    elif op == 'R':
        r += 1
    elif op == 'U':
        u += 1
    else:
        d += 1
    rl[i] = l
    rr[i] = r
    rd[i] = d
    ru[i] = u

def check(lsub):
    for i in range(lops-lsub+1):
        # j-i+1 == lsub, j < lops => i+lsub-1 <lops => i < lops-lsub+1
        j = i + lsub - 1

        # l, r, u, d of lops [0, i-1], ll[i]={'L' of 0,...,i-1}
        l0, r0, u0, d0 = ll[i], lr[i], lu[i], ld[i]

        # l, r, u, d of ops [j+1, N-1], rr[j]={'R' of lops-1,...,j}
        l1, r1, u1, d1 = rl[j+1], rr[j+1], ru[j+1], rd[j+1]

        x = (r0+r1) - (l0+l1)
        y = (u0+u1) - (d0+d1)

        dx = abs(X-x)
        dy = abs(Y-y)

        if dx + dy <= lsub and (lsub-dx-dy) % 2 == 0:
            return True

    return False

sl, sr = 0, lops + 1
while sl < sr:
    m = (sl + sr) // 2
    if check(m):
        sr = m
    else:
        sl = m + 1

sl = -1 if sl > lops else sl
print(sl)


n = int(input())
dirs = input()
goal = list(map(int, input().split(' ')))

def can(start, end, steps):
    dist = abs(start[0] - end[0]) + abs(start[1] - end[1])
    return dist <= steps and (steps - dist) % 2 == 0

if not can((0, 0), goal, n):
    print(-1)
    return

diffs = {
    'U': (0, 1),
    'D': (0, -1),
    'L': (-1, 0),
    'R': (1, 0),
}

pos = [(0, 0)] + [None] * n
for i, dir in enumerate(dirs):
    old_pos = pos[i]
    diff = diffs[dir]
    pos[i+1] = (old_pos[0] + diff[0], old_pos[1] + diff[1])

final_pos = pos[n]

# best (minimum) segment to override to get to the solution
best = (abs(final_pos[0] - goal[0]) + abs(final_pos[1] - goal[1])) // 2

if best == 0:
    print(0)
    return

start = 0
end = best

current_best = float('inf')

while end <= n:
    # exclude segment and check if can reach without
    cur_pos = (
        pos[start][0] + final_pos[0] - pos[end][0],
        pos[start][1] + final_pos[1] - pos[end][1],
    )

    if can(cur_pos, goal, end - start):
        current_best = min(current_best, end - start)
        if current_best == best:
            break
        start += 1
    else:
        end += 1

print(current_best)

# min_steps = abs(goal[0]) + abs(goal[1])
# if min_steps > n or (min_steps - n) % 2 != 0:
#     print(-1)
#     return

# cur_pos = [0, 0]
# for dir in dirs:
#     if dir == 'U':
#         cur_pos[1] += 1
#     if dir == 'D':
#         cur_pos[1] -= 1
#     if dir == 'L':
#         cur_pos[0] -= 1
#     if dir == 'R':
#         cur_pos[0] += 1

# pos_diff = [goal[0] - cur_pos[0], goal[1] - cur_pos[1]]

# vertical = abs(pos_diff[1]) > abs(pos_diff[0])
# up = pos_diff[1] > 0
# right = pos_diff[0] > 0
# replacement_steps = (abs(pos_diff[0]) + abs(pos_diff[1])) // 2
# diagonal_walk = replacement_steps - \
#     abs(abs(pos_diff[1]) - abs(pos_diff[0])) // 2

# start, end = 0, 0
# covered = {'U': 0, 'D': 0, 'L': 0, 'R': 0}
# while end < n:
#     new_dir = dirs[end]
#     covered[new_dir] += 1
#     remaining = covered.copy()
#     end += 1

#     if vertical:
#         if up:
#             pass
#         else:
#             pass
#     else:
#         if right:
#             pass
#         else:
#             pass


#!/usr/bin/env python3

import itertools

def solve(L, n, px, py, x, y):
    for i in range(n):
        j = i + L
        if j > n:
            break
        dx = px[i] + px[-1] - px[j] - x
        dy = py[i] + py[-1] - py[j] - y
        if abs(dx) + abs(dy) <= L:
            return True
    return False

def main(args):
    n = int(input())
    d = input()
    x, y = list(map(int, input().split()))
    py = [0] + [1 if c == 'U' else (-1 if c == 'D' else 0) for c in d]
    px = [0] + [1 if c == 'R' else (-1 if c == 'L' else 0) for c in d]
    if abs(x+ y)%2 != n%2:
        print(-1)
        return 0
    py = list(itertools.accumulate(py))
    px = list(itertools.accumulate(px))
    if px[-1] == x and py[-1] == y:
        print(0)
        return 0
    if abs(x) + abs(y) > n:
        print(-1)
        return 0
    left = 0
    right = n
    while left + 1 < right:
        mid = (left + right) // 2
        if solve(mid, n, px, py, x, y):
            left, right = left, mid
        else:
            left, right = mid, right
    print(right)
    return 0

def __starting_point():
    import sys
    return(main(sys.argv))

__starting_point()


def go(pos,k):
    if 'U'==k:
        pos[1]+=1
    elif 'D'==k:
        pos[1]-=1
    elif 'L'==k:
        pos[0]-=1
    else:
        pos[0]+=1
    return pos

def relapos(a,b):           #返回b的坐标减a的坐标
    c=[b[0]-a[0],b[1]-a[1]]
    return c

def stdis(a,b):
    return abs(b[1]-a[1])+abs(b[0]-a[0])

n=int(input())
s=input()
x,y=[int(i) for i in input().split()]
poss=[[0,0]]             #第n次操作后的位置
pos=[0,0]
for i in range(0,n):
    poss.append(tuple(go(pos,s[i])))
if abs(x)+abs(y)>n or abs(n-x-y)%2!=0:
    print(-1)
else:
    lpos=poss[-1]
    dd=stdis(lpos,[x,y])
    if dd==0:
        print(0)
    else:
        q1=(dd-1)//2
        q2=n
        j=True
        lpos1=[0,0]
        while q2-q1!=1:
            q=(q2+q1)//2
            for k1 in range(n-q+1):
                r=relapos(poss[k1],poss[k1+q])
                lpos1[0]=lpos[0]-r[0]
                lpos1[1]=lpos[1]-r[1]
                if stdis(lpos1,[x,y])<=q:
                    q2=q
                    break
            else:
                q1=q
        print(q2)


n = int(input())
subtract = lambda t1, t2: (t1[0] - t2[0], t1[1] - t2[1])
add = lambda t1, t2: (t1[0] + t2[0], t1[1] + t2[1])
def conv(ch):
	if ch == 'L':
		return (-1, 0)
	elif ch == 'R':
		return (1, 0)
	elif ch == 'U':
		return (0, 1)
	elif ch == 'D':
		return (0, -1)

ops = [conv(ch) for ch in input()]
x, y = list(map(int, input().split()))
lsum = [ops[0]] * n
for i in range(1, n):
	lsum[i] = add(lsum[i - 1], ops[i])
rsum = [ops[n - 1]] * n
i = n - 2
while i >= 0:
	rsum[i] = add(rsum[i + 1], ops[i])
	i = i - 1

def check(L):

	for i in range(0, n - L + 1):
		moves = (x, y)
		if i > 0:
			moves = subtract(moves, lsum[i - 1])
		if i + L < n:
			moves = subtract(moves, rsum[i + L])
		turns = abs(moves[0]) + abs(moves[1])
		if (turns <= L and (L - turns) % 2 == 0):
			return True;
	return False;

if abs(x) + abs(y) > n or (abs(x) + abs(y) - n) % 2 != 0:
	print((-1));
else:
	st, en = 0, n
	while st < en:
		md = (st + en) // 2
		if check(md):
			en = md
		else:
			st = md + 1
	print(st)


def check(length: int):
    nonlocal n, x, y, cur, hor, ver
    hor = 0
    ver = 0
    for i in range(length, n):
        upd(i)
    for i in range(n - length + 1):
        if abs(x - hor) + abs(y - ver) <= length:
            return True
        if i + length < n:
            upd(i)
            minus_upd(i + length)
    return False

def upd(pos: int):
    nonlocal s, ver, hor
    if s[pos] == 'U':
        ver += 1
    elif s[pos] == 'D':
        ver -= 1
    elif s[pos] == 'R':
        hor += 1
    else:
        hor -= 1

def minus_upd(pos: int):
    nonlocal s, ver, hor
    if s[pos] == 'U':
        ver -= 1
    elif s[pos] == 'D':
        ver += 1
    elif s[pos] == 'R':
        hor -= 1
    else:
        hor += 1

n = int(input())
s = list(input())
x, y = map(int, input().split())
if (x + y) % 2 != n % 2 or abs(x) + abs(y) > n:
    print(-1)
    return

ver = 0
hor = 0
cur = 0
for i in range(n):
    upd(i)

left = -1
r = n
while r - left > 1:
    length = (r + left) // 2
    if check(length):
        r = length
    else:
        left = length

print(r)


n=int(input())
a=input()
x,y=map(int,input().split())
locs=[(0,0)]
for i in range(n):
    if a[i]=="U":
        locs.append((locs[-1][0],locs[-1][1]+1))
    elif a[i]=="D":
        locs.append((locs[-1][0],locs[-1][1]-1))
    elif a[i]=="R":
        locs.append((locs[-1][0]+1,locs[-1][1]))
    else:
        locs.append((locs[-1][0]-1,locs[-1][1]))
if abs(x)+abs(y)>n or (x+y-n)%2==1:
    print(-1)
elif locs[-1]==(x,y):
    print(0)
else:
    a=0
    b=0
    best=n
    end=locs[-1]
    while True:
        c,d=locs[a][0]+end[0]-locs[b][0],locs[a][1]+end[1]-locs[b][1]
        if abs(c-x)+abs(d-y)<=b-a:
            best=min(best,b-a)
            a+=1
        else:
            b+=1
            if b>n:
                print(best)
                break


import functools

n = int(input())
dct = {'U': (0, 1), 'D': (0, -1), 'L': (-1, 0), 'R': (1, 0)}
moves_list = list([dct[x] for x in [*input()]])
dest_x, dest_y = list(map(int, input().split()))

def add_vectors(a, b):
    return a[0] + b[0], a[1] + b[1]

def subtract_vectors(a, b):
    return a[0] - b[0], a[1] - b[1]

total = functools.reduce(add_vectors, moves_list)

def czy(dl) -> bool:
    sumo = total
    for v in moves_list[:dl]:
        sumo = subtract_vectors(sumo, v)
    for i in range(1, n - dl + 2):
        (dx, dy) = list(map(abs, subtract_vectors((dest_x, dest_y), sumo)))
        if dx + dy <= dl and (dx + dy) % 2 == dl % 2:
            return True
        if i + dl - 1 >= n:
            break
        sumo = subtract_vectors(sumo, moves_list[i + dl - 1])
        sumo = add_vectors(sumo, moves_list[i - 1])
    return False

pocz = 0
kon = n
while pocz < kon:
    sr = (pocz + kon) // 2
    if czy(sr):
        kon = sr
    else:
        pocz = sr + 1

if czy(pocz):
    print(pocz)
else:
    print(-1)


n = int(input())
a = list(map(int, input().split()))
res = 0
new_a = []
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] > 0:
            res += a[i]
    else:
        new_a.append(a[i])
a = new_a
a.sort()
res += a[-1]
a.pop()
while len(a) > 1:
    if a[-1] + a[-2] > 0:
        res += a[-1] + a[-2]
        a.pop()
        a.pop()
    else:
        break
print(res)


#!/bin/python3
import sys
import math
n = int(input())
a = list(map(int, input().split()))
even = 0
odds = []
for i in range(n):
    if a[i] % 2 == 0 and a[i] > 0:
        even += a[i];
    elif a[i] % 2 == 1:
        odds.append(-a[i]);
odds.sort()
maxsum = -odds[0]
i = 1
cursum = -odds[0];
while i < len(odds):
    cursum += -(odds[i])
    i += 1
    if i >= len(odds):
        break;
    cursum += -(odds[i])
    i+=1
    maxsum = max(maxsum, cursum)
print(maxsum + even)


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

f = 0
for i in range(n):
    if a[i] >= 0:
        f += a[i]

if f % 2:
    print(f)
else:
    m = 10 ** 9
    for i in range(n):
        if a[i] % 2:
            m = min(m, abs(a[i]))

    print(f - m)


n = int(input())
a = list(map(int, input().split()))
c = list([x for x in a if x % 2 == 0 and x > 0])
b = list([x for x in a if x % 2 != 0])
b = sorted(b, reverse=True)
mm = int(-1e10)
s = 0
for i in range(len(b)):
    s += b[i]
    if i % 2 == 0:
        mm = max(mm, s)
# print(c)
print(sum(c) + mm)


def max(a, b):
	if a > b:
		return a
	else:
		return b

def min(a, b):
	if a < b:
		return a
	else:
		return b

def __starting_point():
	n = int(input())
	A = input().split(' ')
	ans, count, Min, Max = 0, 0, 1000000000, -100000000000
	for i in range(n):
		now = int(A[i])
		if now % 2 == 0:
			ans += max(now, 0)
		else:
			if (now < 0):
				Max = max(Max, now)
			else:
				Min = min(Min, now)
				ans += now

	if ans % 2 == 0:
		ans = max(ans - Min, ans + Max)
	print(ans)

__starting_point()


N = int( input() )
A = list( map( int, input().split() ) )
dp = [ [ - int( 1e9 ) for i in range( 2 ) ] for j in range( N + 1 ) ]
dp[ 0 ][ 0 ] = 0
for i in range( N ):
  for j in range( 2 ):
    if abs( A[ i ] ) & 1:
      dp[ i + 1 ][ j ] = max( dp[ i ][ j ], dp[ i ][ j ^ 1 ] + A[ i ] )
    else:
      dp[ i + 1 ][ j ] = max( dp[ i ][ j ], dp[ i ][ j ] + A[ i ] )
print( dp[ N ][ 1 ] )


n = int(input())
a = list(map(int, input().split()))
a.sort(key=lambda x: -x)
s_p = sum([x for x in a if x > 0])
if s_p % 2 == 1:
    print(s_p)
else:
    m_p = list([x for x in a if x > 0 and x % 2 == 1])
    m_n = list([x for x in a if x < 0 and x % 2 == 1])
    if len(m_p) > 0 and len(m_n) > 0:
        s_p += max(-min(m_p), max(m_n))
    elif len(m_p) == 0 and len(m_n) > 0:
        s_p += max(m_n)
    else:
        s_p += -min(m_p)
    print(s_p)


_ = input()
v = [int(x) for x in input().split()]

neg_par = []
neg_impar = []
poz_par = []
poz_impar = []

for x in v:
    if x < 0:
        if x % 2 == 0:
            neg_par.append(x)
        else:
            neg_impar.append(x)
    else:
        if x % 2 == 0:
            poz_par.append(x)
        else:
            poz_impar.append(x)

neg_par.sort()
neg_impar.sort()
poz_par.sort()
poz_impar.sort()

res = sum(poz_par)
if len(poz_impar) > 0:
    if len(poz_impar) % 2 == 1:
        res += sum(poz_impar)
    else:
        if len(neg_impar) > 0 and neg_impar[-1] + poz_impar[0] > 0:
            res += sum(poz_impar)
            res += neg_impar[-1]
        else:
            res += sum(poz_impar[1:])
else:
    res += neg_impar[-1]
print(res)


input()
a=[int(x) for x in input().split()]

oc=0
ps=0
pmo=1e6
nmo=-1e6

for x in a:
    if x>0:
        ps+=x
    if x%2==1 and x>0 and pmo>x:
        pmo=x
    if x%2==1 and x>0:
        oc+=1
    if x%2==1 and x<0 and nmo<x:
        nmo=x

if oc%2==1:
    print(ps)
else:
    print(max(ps-pmo,ps+nmo))


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 0
m1 = float('inf')
m2 = -float('inf')
while i < n and a[i] >= 0:
    if a[i] % 2 == 1:
        m1 = a[i]
    i += 1
s = sum(a[:i])
if s % 2 == 1:
    print(s)
else:
    while i < n and a[i] % 2 == 0:
        i += 1
    if i < n: m2 = a[i]
    print(max(s-m1,s+m2))


n = int(input())
lst = [int(x) for x in input().split(" ")]

even = list([x for x in lst if x % 2 == 0])
odd = list([x for x in lst if x % 2 != 0])

even_sum = 0
for i in even:
    if i > 0:
        even_sum += i # always take all even sums

odd = reversed(sorted(odd))

possible = []
rolling = 0
for i in odd: # there must be at least one odd number
    rolling += i
    possible.append(even_sum + rolling)

possible = reversed(sorted(possible))
for i in possible: # print highest sum
    if i % 2 != 0:
        print(i)
        break


import math
n = int(input())

l = list(map(int, input().split(" ")))
li = []
for i in l:
    if(i > 0):
        li.append(i)
s = sum(li)
found = False
if(s%2 == 0):
    m = 10000
    for i in li:
        if i < m and i%2==1:
            m = i
            found = True
    if(found):
        m2 = -10000
        for i in l:
            if i > m2 and i < 0 and i%2 == 1:
                m2 = i
        if(abs(m2) > m):
            print(s-m)
        else:
            print(s+m2)
    else:
        m2 = -10000
        for i in l:
            if i > m2 and i < 0 and i%2 == 1:
                m2 = i
        print(s+m2)
else:
    print(s)


n = int(input())
a = [int(i) for i in input().split()]
otrmax = -10**4 - 1
polmin = 10**4 +1
sm = 0
for i in a:
	if i<0:
		if i>otrmax and i%2==1:
			otrmax = i
	else:
		if i<polmin and i%2==1:
			polmin = i
		sm += i

if sm%2==0:
	vrs = []
	if polmin!=10^4 +1:
		vrs.append(sm-polmin)
	if otrmax!=-10^4 - 1:
		vrs.append(sm+otrmax)
	print(max(vrs))
else:
	print(sm)


n=int(input())
a=sorted(list(map(int,input().split())))
mx=max(a)
b=[]
c=[]
d=[]
e=[]
sum1=0
sum2=0
for i in range(n):
    if a[i]>=0:
        sum1+=a[i]
        if a[i]%2==0:
            b.append(a[i])
        else:
            c.append(a[i])
    else:
        sum2+=a[i]
        if a[i]%2==0:
            d.append(a[i])
        else:
            e.append(a[i])
if sum1%2==1 and sum1>0:
    print(sum1)
else:
    if len(e)>0:
        if len(c)>0:
            print(max(sum1+e[-1],sum1-c[0]))
        else:
            print(sum1+e[-1])
    else:
        if len(c)>0:
            print(sum1-c[0])


n=int(input())
a=list(map(int,input().split()))
s=0
b=0
c=0
for i in a:
    if i>0:
        s+=i
        if i%2!=0:
            if b>0:
                b=min(b,i)
            if b==0:
                b=i
    if i<0 and i%2!=0:
        if c<0:
            c=max(c,i)
        if c==0:
            c=i
if s%2!=0:
    print(s)
else:
    if (abs(c)<b or b==0) and c!=0:
        s=s+c
    else:
        s=s-b
    print(s)


import math
(n)=list(map(int,input().split()))
alist=list(map(int,input().split()))
sumpos=0
maxNegOdd=-1e9
maxPosODD=1e9
for i in alist:
    if i>0:
        sumpos+=i
        if i<maxPosODD and i%2!=0:
            maxPosODD=i
    elif i%2!=0 and maxNegOdd<i:
        maxNegOdd=i
if sumpos%2==0:
    if maxPosODD>abs(maxNegOdd):
        sumpos+=maxNegOdd
    else:
        sumpos-=maxPosODD
print(sumpos)


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

minus_odd = -10001
plus_odd = 10001
total = 0

for i in a:
    if i % 2:
        if i < 0:
            minus_odd = max(minus_odd, i)
        else:
            plus_odd = min(plus_odd, i)

    if i > 0:
        total += i

if total % 2 == 0:
    if minus_odd == -10001:
        print(total - plus_odd)
    elif plus_odd == 10001:
        print(total + minus_odd)
    else:
        if -minus_odd > plus_odd:
            print(total - plus_odd)
        else:
            print(total + minus_odd)

else:
    print(total)


n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
s = 0
for i in range(n):
    if a[i] > 0: s += a[i]
    else: break
if s % 2: print(s)
else:
    mx = -100000
    for i in range(n):
        if a[i] < 0 and a[i] % 2: mx = max(a[i], mx)
    mn = 100000
    for i in range(n):
        if a[i] >= 0 and a[i] % 2: mn = min(a[i], mn)
    #print(mx, mn)
    print(max(s + mx, s - mn))


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

pos = [x for x in nums if x > 0]
neg = [x for x in nums if x < 0]

s1 = sum(pos)
if s1 % 2 == 1:
    print(s1)
    return

podd = [x for x in pos if x % 2 == 1]
nodd = [x for x in neg if x % 2 == 1]

if podd:
    min_podd = min(podd)
    if not nodd:
        s1 -= min_podd
    else:
        max_nodd = max(nodd)
        if min_podd + max_nodd > 0:
            s1 += max_nodd
        else:
            s1 -= min_podd
else:
    s1 += max(nodd)

print(s1)


n = int(input())
nums = [int(i) for i in input().split()]
result = 0
min_positive = 10001
max_negative = -10001
for i in nums:
    if i > 0:
        result += i
    if i % 2 == 1:
        if 0 < i < min_positive:
            min_positive = i
        elif max_negative < i < 0:
            max_negative = i
if result % 2 == 0:
    if abs(max_negative) > min_positive:
        result -= min_positive
    else:
        result += max_negative
print(result)


n = int(input())
a = list(map(int,input().split()))
s=0
neg = -10000
pos = 10000
for i in range(n):
	if a[i]%2:
		if a[i]<0:
			neg = max(a[i],neg)
		else:
			pos = min(a[i],pos)
	if a[i]>0:s += a[i]
if neg%2 == 0: neg = 10000
if pos%2 == 0: pos = 10000
if s%2==0:
	s-=min(abs(neg),pos)
print(s)


#! /bin/python
n = int(input())
tab = list(map(int, input().split()))
tab = sorted(tab, reverse=True)
#  print(tab)
maxi = 0
tmpOdd = 0
maxOdd = 0
oddFirst = True
for i in tab:
    if i % 2 == 0 and i > 0:
        maxi += i
    elif i %2 == 1:
        tmpOdd += i
        if tmpOdd % 2 == 1:
            if maxOdd < tmpOdd or oddFirst:
                oddFirst = False
                maxOdd = tmpOdd
maxi += maxOdd
print(maxi)


n=int(input())
s=input()
s=s.split()
l=[]
o=[]
on=[]
sum=0
for i in s:
	te=int(i)
	l.append(te)
	if(te>0 and te%2==1):
		o.append(te)
	elif(te>0 and te%2==0):
		sum+=te
	elif(te<0 and te%2==1):
		on.append(te)
o.sort(reverse=True)
on.sort(reverse=True)
ko=0
for i in on:
	if(i%2==1):
		ko=i
		break

j=2
sumo=0
if(len(o)>0):
	sumo=o[0]
while(j<len(o)):
	sumo+=o[j]+o[j-1]
	j+=2

if(len(o)==0):
	print(sum+ko)
elif(len(o)%2==1):
	print(sum+sumo)
elif(len(o)%2==0):
	if(len(on)>0 and ko<0):
		print(max(sum+sumo,sum+sumo+ko+o[-1]))
	elif(len(on)>0 and ko==0):
		print(sum+sumo)
	else:
		print(sum+sumo)


h, n = list(map(int, input().split()))
c, m = 0, 2 ** h
r = 0
while m > 1:
    if c == 0:
        if n > m // 2:
            r += m - 1
            n -= m // 2
            c = 1 - c
    else:
        if n > m // 2:
            n -= m // 2
        else:
            r += m - 1
            c = 1 - c
    c = 1 - c
    r += 1
    m //= 2
    #print(c, m, r, n)
print(r)


"""
Codeforces Contest 287 Div 2 Problem C

Author  : chaotic_iak
Language: Python 3.4.2
"""

################################################### SOLUTION

def main():
    h,n = read()
    n -= 1
    n = bin(n)[2:]
    n = "0" * (h-len(n)) + n

    s = ""
    for i in range(h):
        if i and n[i-1] == "0":
            s += "1" if n[i] == "0" else "0"
        else:
            s += n[i]

    ct = 0
    for i in range(h):
        ct += 1
        if s[i] == "1": ct += 2**(h-i)-1
    print(ct)

#################################################### HELPERS

def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    inputs = input().strip()
    if mode == 0: return inputs
    if mode == 1: return inputs.split()
    if mode == 2: return list(map(int, inputs.split()))

def write(s="\n"):
    if s is None: s = ""
    if isinstance(s, list): s = " ".join(map(str, s))
    s = str(s)
    print(s, end="")

write(main())


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

s = height
reverted = False
for h in range(height-1, -1, -1):

    if n > 2**h:
        more = True
        n -= 2**h
    else:
        more = False

    if more ^ reverted:
        s += (2 * 2**h - 1)

    reverted = not more

print (s)


h,n=list(map(int,input().split()))
p=1<<(h-1)
i=r=0
n-=1
while h:
	r+=1
	if n>=p:j=1;n-=p
	else:j=0
	if j^i:r+=p+p-1
	else:i=1-i
	p>>=1
	h-=1
print(r)


def summ(x):
    ret=1
    acc=1
    while(acc<=x):
        ret+=acc
        acc*=2
    return ret

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

ans = 1
lvl = 0
cur = 'L'
amnt = 2**h
while(1):
    if(lvl==h):
        break
    if(cur=='L'):
        if(n<=amnt//2):
            amnt//=2
            cur='R'
            ans+=1
            lvl+=1
        else:
            amnt//=2
            n-=amnt
            cur='L'
            ans+=summ(amnt)
            lvl+=1
    else:
        if(n<=amnt//2):
            amnt//=2
            cur='R'
            ans+=summ(amnt)
            lvl+=1
        else:
            amnt//=2
            n-=amnt
            cur='L'
            ans+=1
            lvl+=1
print(ans-1)


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

result = 0
side = 0
for h in range(H, 0, -1):
    result += 1
    if side ^ (N > 1 << (h - 1)):
        result += (1 << h) - 1
    else:
        side ^= 1
    if N > 1 << (h - 1):
        N -= 1 << (h - 1)

print(result)


h,n = map(int, input().split(' '))
ans = 0
left = True
for i in range(h) :
    ch = h-i
    half = 2**(ch-1)

    if n <= half :
        if left :
            ans += 1
            left = False
            continue
        else :
            ans += half*2
            left = False
            continue
    else :
        if left :
            ans += half*2
            left = True
            n -= half
        else :
            ans += 1
            left = True
            n -= half
print(ans)


line = input().split()

h = int(line[0])
n = int(line[1])

last = 1
th = 2 ** h
ans = 1
l = 1
r = th
while th > 0:
    mid = (l + r) // 2
    if n <= mid:
        if last == 1:
            ans += 1
        else:
            ans += th
        last = 0
        r = mid
    else:
        if last == 0:
            ans += 1
        else:
            ans += th
        last = 1
        l = mid + 1
    th = th // 2

print(str(ans - 2))


def ans():
    h, n= [int(i) for i in input().split()]
    div= 2**(h- 1)
    mystr= ""
    for i in range(h):
        #print(div)
        if n> div:
            mystr+= "G"
            div+= 2**(h- i- 2)
        else:
            mystr+= "L"
            div-= 2**(h- i- 2)

    #print(mystr)
    if mystr[0]== "L":
        ans= 1
    elif mystr[0]== "G":
        ans= 2**h
    for i in range(len(mystr)- 1):
        if mystr[i+ 1]== mystr[i]:
            ans+= 2**(h- i- 1)
        else:
            ans+= 1

    print(ans)

    return
ans()


h,n = list(map(int,input().split()))
l = 1; r = 2**h
ans = 0
now = 'l'
for i in range(h,0,-1):
    if n < (l+r)/2 and now == 'l':
        now = 'r'
        r -= 2**(i-1)
        ans += 1
    elif n < (l+r)/2 and now == 'r':
        r -= 2**(i-1)
        ans += 2**i
    elif n > (l+r)/2 and now == 'l':
        l += 2**(i-1)
        ans += 2**i
    else:
        now = 'l'
        l += 2**(i-1)
        ans += 1
print(ans)


__author__ = 'Konrad Strack'

def command_gen():
    while True:
        yield 'L'
        yield 'R'

def solve():
    h, n = [int(x) for x in input().split()]

    leaves = 2 ** h

    path = []
    left, right = 1, leaves
    for i in range(h):
        middle = (left + right) // 2
        if n <= middle:
            path.append('L')
            right = middle
        else:
            path.append('R')
            left = middle + 1

    command = command_gen()
    sum = 0
    hi = h
    for p in path:
        cmd = next(command)

        if p != cmd:
            sum += 2 ** hi - 1
            next(command)
        hi -= 1

    sum += len(path)
    print(sum)

def __starting_point():
    solve()
__starting_point()


h, n = map(int, input().split())
t = bin(n-1)[2:]
t = '0'*(h-len(t))+t
res = 0
flag = True
for i in range(h):
	if(t[i] == ('1' if flag else '0')):
		res += 2**(h-i)
	else:
		flag = not flag
		res += 1
print(res)


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

total = 2 ** (h + 1) - 1

sum_v = 0
range_v = (0, 2 ** h - 1)
prev_r = range_v
x = n - 1
left = False
curr_h = 0

def in_range(r, x):
    return r[0] <= x <= r[1]

def range_width(r):
    return r[1] - r[0] + 1

def update_range(r, l):
    w = range_width(r) // 2
    st = r[0] if l else r[0] + w
    return st, st + w - 1

#print("X ", x)
while range_width(range_v) != 0:
    left = not left
    #print(range_v)

    tmp = range_v
    if in_range(range_v, x):
        range_v = update_range(range_v, left)
        sum_v += 1
        curr_h += 1
        #print("+ 1")
    else:
        range_v = update_range(prev_r, left)
        sum_v += 2 ** (h - curr_h + 1) - 1
        #print("+ ", 2 ** (h - curr_h + 1) - 1)

    prev_r = tmp

print(sum_v - 1)


import math
s = 'LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR'
(h, n) = [int(x) for x in input().split()]
n = 2**(h)-1+n
left = 2**h
right = 2**(h+1)-1
path = []
for i in range(h):
    center = (right+left)/2
    if n>center:
        path.append('R')
        left = math.ceil(center)
    else:
        path.append('L')
        right = int(center)

cost = 1
for i in range(len(path)):
    if s[i] != path[i]:
        cost += 2**(h-i)-1+1
        s = s[:i]+s[i+1:]
    else:
        cost += 1
print(cost-1)


h, n = list(map(int, input().split()))
h -= 1
n -= 1
l = 0
r = 2 << h
ll = True
ans = 0
i = 0
while r - l > 1:
    m = (l + r) // 2
    if ll == (n < m):
        ans += 1
    else:
        ans += 1 << (h - i + 1)
    if n < m:
        r = m
        ll = False
    else:
        l = m;
        ll = True
    i += 1
print(ans)


h, n = (int(x) for x in input().split())
leftPlus, rightPlus = 1, 2**h
answer = 1
curLevel = 0
delim = 2**(h - 1)
while curLevel != h:
	h -= 1
	if n <= delim:
		answer += leftPlus
		leftPlus, rightPlus = max(rightPlus // 2, leftPlus // 2), 1
		delim -= 2**(h - 1)
		# print ("L", answer)
	else:
		answer += rightPlus
		leftPlus, rightPlus = 1, max(rightPlus // 2, leftPlus // 2)
		delim += 2**(h - 1)
		# print ("R", answer)
print (answer - 1)


import math

def is_left_son(num):
    if num == num // 2 * 2:
        return True
    else:
        return False

def bin_search(place, depth):
    answer = ""
    length = 2 ** depth
    while length > 1:
        if place > length / 2:
            answer += "R"
            place -= length / 2
        else:
            answer += "L"
        length = length / 2
    return answer

def traverse(depth, route):
    answer = 0
    cur_vert = 1
    cur_dir = "L"
    while route:
        if route[0] == "R":
            cur_vert = cur_vert * 2 + 1
        else:
            cur_vert = cur_vert * 2
        if cur_dir == route[0]:
            answer += 1
        else:
            answer += 2**depth
        depth -= 1
        route = route[1:]
        cur_dir = "R" if is_left_son(cur_vert) else "L"
    return answer

h, n = (int(x) for x in input().split())
amount_visited = 0
cur_pos = 1
print(traverse(h, bin_search(n, h)))


h, n = list(map(int, input().split()))
h += 1

moves = []

result = h - 1

n += (2**(h-1)) - 1

while n != 1:
    if n % 2 == 1:
        moves.append(1)
    else:
        moves.append(0)
    n //= 2

index_on_list = 0

ch = 1

while len(moves) > 0:
    if moves[-1] != index_on_list % 2:
        result += (2**(h-ch)) - 1
    else:
        moves.pop()
        ch += 1

    index_on_list += 1

print(result)


import sys
def main():
    rdl = list(map(int,input().split()))
    obx(rdl[0],rdl[1],0,1)
def obx(lvl, ind, kl, current):
    if lvl ==0:
        print(int(kl))
        return
    all = 0
    for i in range(lvl+1):
        all += 2**i
    all -= 1

    if ind > (2**(lvl))/2:
        if current == 1:
            kl += all / 2 + 1
        else:
            kl += 1
            current *= -1
        obx(lvl-1,ind-(2**lvl)/2,kl,current)
    else:
        if current == -1:
            kl += all/2+1
        else:
            kl += 1
            current *= -1
        obx(lvl-1,ind,kl,current)

main()


def main():
	h, n = (list(map(int, input().split())))
	c, m = 0, 2 ** h
	r = 0
	while m > 1:
		if c == 0:
			if n > (m//2):
				r += m - 1
				n -= m//2
				c = 1 - c
		else:
			if n > m//2:
				n -= m//2
			else:
				r += m - 1
				c = 1 - c
		c = 1 - c
		r += 1
		m //= 2
	print(r)

def __starting_point():
	main()

__starting_point()


h, n = [int(_) for _ in input().split()]
start = 1
end = 2 ** h
last = "l"
ans = 0
for i in range(h):
    mid = (start + end) // 2
    if n <= mid:
        end = mid
        if last == 'l':
            last = 'r'
            ans += 1
        else:
            ans += 2 ** (h - i)
    else:
        start = mid
        if last == 'r':
            last = 'l'
            ans += 1
        else:
            ans += 2 ** (h - i)

print(ans)


h,n=input().split(' ')
h=int(h)
n=int(n)
s='l'
ans=0
for i in range(h,0,-1):
 if n>pow(2,i-1):
     if s=='l':
       ans+=pow(2,i)
     else:
       ans+=1
     s='l'
     n-=pow(2,i-1)
 else:
     if s=='r':
         ans+=pow(2,i)
     else:
         ans+=1;
     s='r'
print (ans)


def n_of_nodes(h):
    result = 0
    for i in range(h):
        result += 2 ** i
    return result

h, n = tuple(map(int, input().split()))

way = ""
t = h
while t:
    if n % 2:
        way = "L" + way
        n //= 2
        n += 1
    else:
        way = "R" + way
        n //= 2
    t -= 1

answer = 1
current = "L"
t = h
for i in way:
    if i == current:
        answer += 1
        if current == "L":
            current = "R"
        else:
            current = "L"
    else:
        answer += n_of_nodes(t) + 1
    t -= 1

print(answer - 1)


def isPrime(n) :
    # Corner cases
    if (n <= 1) :
        return False
    if (n <= 3) :
        return True

    # This is checked so that we can skip
    # middle five numbers in below loop
    if (n % 2 == 0 or n % 3 == 0) :
        return False

    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6

    return True
t=int(input())
for yes in range(t):
	a,b=map(int,input().split())
	xx=a-b
	yy=a+b
	if xx==1 and isPrime(yy)==True:
		print("YES")
	else:
		print("NO")


read = lambda: map(int, input().split())
def prime(x):
    d = 2
    while d*d<= x:
        if x % d == 0: return 0
        d += 1
    return 1
t = int(input())
res = ""
for i in range(t):
    a, b = read()
    res += "YES\n" if a-b==1 and prime(a+b) else "NO\n"
print(res)


def isPrime(n):
    for i in range(2,int(n**0.5)+1):
        if n%i==0:
            return False
    return True

    return True
for i in ' '*int(input()):
    a,b=map(int,input().split())
    if a-b>1:print('NO')
    else:
        print(['NO','YES'][isPrime(a+b)])


def check_prime(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

t = int(input())
for tnum in range(t):
    a, b = map(int, input().split())
    if a != b + 1:
        print("NO")
    else:
        print("YES" if check_prime(a + b) else "NO")


from math import sqrt
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    first = a - b
    second = a + b
    if first != 1:
        print('NO')
    else:
        f = False
        for i in range(2, int(sqrt(second)) + 1):
            if second % i == 0:
                f = True
                break
        if f:
            print('NO')
        else:
            print('YES')


def prime(n):
    if n < 2:
        return False
    elif n % 2 == 0:
        return False
    else:
        for k in range(3, 1 + int(n ** .5), 2):
            if n % k == 0:
                return False
    return True

t = int(input())
for i in range(t):
    a, b = list(map(int, input().split()))
    n = (a + b)
    if a - b > 1:
        print('NO')
    else:
        if prime(n):
            print('YES')
        else:
            print('NO')


t = int(input())
for _ in range(t):
    a, b = list(map(int, input().split()))
    if a - b != 1:
        print("NO")
        continue
    c = a + b
    for t in range(2, int(c ** 0.5) + 1):
        if c % t == 0:
            print("NO")
            break
    else:
        print("YES")


def check(a):
    for i in range(2, round(a**0.5 + 1)):
        if not a % i:
            return 0
    return 1

for i in range(int(input())):
    a, b = map(int, input().split())
    if (a - b) > 1 and (a + b) > 1:
        print('NO')
    else:
        print('YES' if check(a**2-b**2) else 'NO')


from math import sqrt
from itertools import count, islice

def isPrime(n):
    return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))

t=int(input())

for i in range(t):
	a,b=map(int,input().split())
	ans = False
	if a-b==1:
		x = a+b
		ans=isPrime(x)

	if ans:
		print("YES")
	else:
		print("NO")


t=int(input())
import math
for i in range(t):
    a,b=list(map(int,input().split()))
    if((a-b)!=1):
        print("NO")
    else:
        l=2*a-1
        p=0
        for k in range(2,int(math.sqrt(l))+1):
            if(l%k==0):
                print("NO")
                p=1
                break
        if(p==0):
            print("YES")


def prime(x):
    if x==1:
        return False
    ret=True
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            ret=False
    return ret

n=int(input())
for i in range(n):
    s=input().split()
    d=int(s[0])-int(s[1])
    if d!=1:
        print("NO")
    else:
        if prime(int(s[0])+int(s[1])):
            print("YES")
        else:
            print("NO")


t = int(input())
while t > 0:
    a, b = list(map(int,input().split()))
    if a - b != 1 :
        print("NO")
    else:
        num = a + b
        num2 = int(num ** 0.5)
        num3 = 2
        ans = 0
        while num3 <= num2:
            if num % num3 == 0:
                ans = 1
            num3 += 1
        if ans == 1:
            print("NO")
        else:
            print("YES")
    t -= 1


import sys

def isprime(x):
    import math
    if x == 1:
        return True

    for i in range(2, math.ceil(math.sqrt(x))+1):
        if x % i == 0:
            return False
    return True

def __starting_point():
    cin = sys.stdin

    T = int(next(cin))
    for _ in range(T):
        n, m = list(map(int, next(cin).split()))

        # n**2-m**2 = (n-m)*(n+m)

        if n-m == 1 and isprime(n+m):
            print('YES')
        else:
            print('NO')

__starting_point()


def isPrime(n) :
    # Corner cases
    if (n <= 1) :
        return False
    if (n <= 3) :
        return True

    # This is checked so that we can skip
    # middle five numbers in below loop
    if (n % 2 == 0 or n % 3 == 0) :
        return False

    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6

    return True
t=int(input())
for l in range(t):
	a,b=list(map(int,input().split()))
	if(a-b!=1):
		print("NO")
	else:
		if(isPrime(a+b)):
			print('YES')
		else:
			print('NO')


from math import sqrt; from itertools import count, islice

n = int(input())

def isPrime(n):
    return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))

def eval_(a, b):
    if  abs(a - b)!=1:
        return "NO"
    result = isPrime(a + b)
    if result:
        return "YES"
    else:
        return "NO"

for i in range(n):
    (a, b) = [int(x) for x in input().split()]
    print(eval_(a, b))


import math

t = int(input())

def isprime(c):
	# print(int(math.ceil(math.sqrt(c)))+1)
	for x in range(2, int(math.ceil(math.sqrt(c)))+1):
		# print("x: {}".format(x))
		if c % x == 0:
			return False

	return True

for x in range(t):
	a, b = list(map(int, input().split()))
	if (1 == a-b) and isprime(a + b):
		print ("YES")
	else:
		print ("NO")


from math import sqrt, floor

def check(n):
    for i in range(2, floor(sqrt(n)) + 1):
        if (n % i == 0):
            return False

    return True

t = int(input())

for i in range(t):
    a, b = list(map(int, input().split()))

    if (a - b == 1 and check(a + b)):
        print("YES")
    else:
        print("NO")


t = int(input())

def divider(n):
    i = 2
    j = 0
    while i**2 <= n and j != 1:
        if n%i == 0:
            j = 1
        i += 1
    if j == 1:
        return False
    else:
        return True

for i in range(t):
    a, b = list(map(int,input().split()))
    if a-b == 1 and divider(a+b):
        print("YES")
    else:
        print("NO")


def isprime(n):
    i = 2
    m = n
    while (i * i <= n):
        while (n % i == 0):
            n /= i
        i += 1
    return m == n

t = int(input())
for i in range(t):
    a, b = map(int, input().split())
    if (isprime(a + b) and a - b == 1):
        print("YES")
    else:
        print("NO")


t=int(input())
a=[]
b=[]
for i in range(t):
    aa,bb=[int(el) for el in input().split()]
    a.append(aa)
    b.append(bb)

def prost(n):
    if n==3:
        return True
    if n%2==0:
        return False
    for i in range (3,int(n**0.5)+1,2):
        if n%i==0:
            return False
    return True
    return

for i in range(t):
    if a[i]-b[i]!=1:
        print ('NO')
        continue
    if prost(a[i]+b[i]):
        print('YES')
    else:
        print('NO')


import random
def MillerRabinPrimalityTest(number):
    '''
    because the algorithm input is ODD number than if we get
    even and it is the number 2 we return TRUE ( spcial case )
    if we get the number 1 we return false and any other even
    number we will return false.
    '''
    if number == 2:
        return True
    elif number == 1 or number % 2 == 0:
        return False

    ''' first we want to express n as : 2^s * r ( were r is odd ) '''

    ''' the odd part of the number '''
    oddPartOfNumber = number - 1

    ''' The number of time that the number is divided by two '''
    timesTwoDividNumber = 0

    ''' while r is even divid by 2 to find the odd part '''
    while oddPartOfNumber % 2 == 0:
        oddPartOfNumber = oddPartOfNumber // 2
        timesTwoDividNumber = timesTwoDividNumber + 1

    '''
    since there are number that are cases of "strong liar" we
    need to check more then one number
    '''
    for time in range(3):

        ''' choose "Good" random number '''
        while True:
            ''' Draw a RANDOM number in range of number ( Z_number )  '''
            randomNumber = random.randint(2, number)-1
            if randomNumber != 0 and randomNumber != 1:
                break

        ''' randomNumberWithPower = randomNumber^oddPartOfNumber mod number '''
        randomNumberWithPower = pow(randomNumber, oddPartOfNumber, number)

        ''' if random number is not 1 and not -1 ( in mod n ) '''
        if (randomNumberWithPower != 1) and (randomNumberWithPower != number - 1):
            # number of iteration
            iterationNumber = 1

            ''' while we can squre the number and the squered number is not -1 mod number'''
            while (iterationNumber <= timesTwoDividNumber - 1) and (randomNumberWithPower != number - 1):
                ''' squre the number '''
                randomNumberWithPower = pow(randomNumberWithPower, 2, number)

                # inc the number of iteration
                iterationNumber = iterationNumber + 1
            '''
            if x != -1 mod number then it because we did not found strong witnesses
            hence 1 have more then two roots in mod n ==>
            n is composite ==> return false for primality
            '''
            if (randomNumberWithPower != (number - 1)):
                return False

    ''' well the number pass the tests ==> it is probably prime ==> return true for primality '''
    return True
cases=int(input())
for case in range(cases):
    a,b=map(int,input().split())
    t=MillerRabinPrimalityTest((a**2)-(b**2))
    if t:
        print("YES")
    else:
        print("NO")


def divider(n):
    i = 2
    j = 0
    while i**2 <= n and j != 1:
        if n % i == 0:
            j = 1
        i += 1
    if j == 1:
        return False
    else:
        return True

i = int(input())
for i in range(i):
    a, b = list(map(int, input().split()))
    if a - b == 1 and divider(a+b):
        print("YES")
    else:
        print("NO")


import math

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

def solve():
    a, b = (int(x) for x in input().split())
    if a - b != 1:
        print('NO')
        return

    if is_prime(a+b):
        print('YES')
    else:
        print('NO')

num_tests = int(input())
for _ in range(num_tests):
    solve()


import math as m
def f(a):
	if (a==2) : return True
	for i in range(2,round(m.sqrt(a))+1):
		if a%i==0:
			return False
	return True

t=int(input())

for i in range(t):
	a,b=input().split()

	a=int(a)
	b=int(b)

	if (a-b)==1 and f(a+b) :
		print("YES")
	else :
		print("NO")


#
import collections, atexit, math, sys, bisect

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        print(*args, **kwargs, file=sys.stderr)
    dprint('debug mode')
except ModuleNotFoundError:
    def dprint(*args, **kwargs):
        pass

inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit

N, M, Q = getIntList()

s1 = input()
s2 = input()

tot = 0
zt = [0]

for i in range(N):
    if s1[i:i+M] == s2:
        tot+=1
    zt.append(tot)
dprint(zt)
for i in range(Q):
    a,b = getIntList()
    b0 = b- M+1
    if b0<a:
        print(0)
    else:
        print(zt[b0] - zt[a-1])


n,m,q = list(map(int,input().split()))
s = input()
t = input()
l = []
r = []
for i in range(n-m+1):
    if s[i:i+m] == t:
        l.append(i)
        r.append(i+m-1)
for i in range(q):
    x,y = list(map(int,input().split()))
    x-=1
    y-=1
    ans = 0
    for j in range(len(l)):
        if x <= l[j] and y >= r[j]:
            ans+=1
    print(ans)


import re, bisect

n, m, q = [int(v) for v in input().split()]
s = input().strip()
t = input().strip()

starts = [m.start() for m in re.finditer('(?=%s)' % t, s)]

for _ in range(q):
    l, r = [int(v) for v in input().split()]
    if r - l + 1 < len(t):
        print(0)
    else:
        print(bisect.bisect_right(starts, r - len(t)) - bisect.bisect_left(starts, l - 1))


n, m, q = [int(i) for i in input().split()]
s = list(input())
t = list(input())
lt = len(t)
ls = len(s)
start = []
for i in range(ls - lt +1):
    j = i
    count = 0
    while s[j] == t[count]:
        j += 1
        count += 1
        if count >= lt:
            break
    if count == lt:
        start.append(i + 1)

start += [n + 1]
for i in range(q):
    l, r = [int(j) for j in input().split()]
    r -= lt - 1
    if l > r:
        print(0)
        continue
    f = False
    for j in range(len(start)):
        if (f == False) and (start[j] >= l):
            f = True
            begin = j
        if (f) and (start[j] > r):
            end = j
            break
    print(end - begin)


import sys
import io

stream_enable = 0

inpstream = """
15 2 3
abacabadabacaba
ba
1 15
3 4
2 14
"""

if stream_enable:
    sys.stdin = io.StringIO(inpstream)
    input()

def inpmap():
    return list(map(int, input().split()))

n, m, q = inpmap()
a = input()
b = input()
s = [0] * n
s[0] = int(a.startswith(b))
for i in range(1, n):
    s[i] = s[i - 1] + int(a[i:i+m] == b)
for i in range(q):
    x, y = inpmap()
    r = (s[y - m] if y - m >= 0 else 0) - (s[x - 2] if x - 2 >= 0 else 0)
    print(max(r, 0))


n,m,q=list(map(int,input().split()))
s=str(input())
t=str(input())
arrx=[]
i=0
count=0
while(i<n):
    if(s[i]==t[0]):
        j=0
        while(j+i<n and j<m and s[j+i]==t[j]):
            j+=1
        if(j==len(t)):
            count+=1
    arrx.append(count)
    i+=1
for i in range(q):
    x,y=list(map(int,input().split()))
    if(y-x<m-1):
        print(0)
    else:
        if(x==1):
            print(arrx[y-m])
        else:
            print(arrx[y-m]-arrx[x-2])


from sys import stdin
from math import *

line = stdin.readline().rstrip().split()
n = int(line[0])
m = int(line[1])
q = int(line[2])

s = stdin.readline().rstrip().split()[0]
t = stdin.readline().rstrip().split()[0]

bools = [0] * (n - m + 1 + 1)

accum = 0
for i in range(n - m, -1, -1):
    if s[i:i+m] == t:
        accum += 1
    bools[i] = accum

for i in range(q):
    numbers = list(map(int, stdin.readline().rstrip().split()))
    l = numbers[0] - 1
    r = numbers[1] - 1 - m + 1 + 1
    if r > l:
        print(bools[l] - bools[r])
    else:
        print(0)
 #suma = 0
#    for j in range(l, r+1):
#        if bools[j]:
#            suma += 1


n, m, q = list(map(int, input().split()))
s = list(input())
t = list(input())
a = [list(map(int, input().split())) for i in range(q)]

if n < m:
    for i in range(q):
        print(0)
    return

res = [0] * (n - m + 1)
for i in range(n - m + 1):
    if s[i:(i + m)] == t:
        res[i] = 1

for u in range(q):
    l = a[u][0]
    r = a[u][1]

    ans = 0
    for y in range(l - 1, r - m + 1):
        # print(y)
        if res[y] == 1:
            ans += 1

    print(ans)


n, m, q = map(int, input().split())
s = input()
t = input()
arr = []
for i in range(n - m + 1):
    if s[i:i + m] == t:
        arr.append(i)
for i in range(q):
    l, r = map(int, input().split())
    k = 0
    for j in range(len(arr)):
        if arr[j] >= l - 1 and arr[j] + m - 1<= r - 1:
            k = k + 1
    print(k)


n, m, q = list(map(int, input().split()))
s = input()
t = input()
arr = [0] * n
for i in range(n - m + 1):
    if t == s[i:i+m]:
        arr[i] = 1
    if i: arr[i] += arr[i - 1]
for i in range(q):
    l, r = list(map(int, input().split()))
    l -= 1
    r -= 1
    L = l - 1
    R = r - m + 1
    if R < L:
        print(0)
        continue
    if L >= 0:
        print(arr[R] - arr[L])
    else:
        print(arr[R])


#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M,q = inpl()
S = input()
T = input()
azu = [0]*(N-M+1)
qq = []

for i in range(q):
	qq.append(inpl())

if M > N:
	for i in range(q):
		print(0)
	return

for i in range(0,N-M+1):
	if S[i:i+M] == T:
		azu[i] = 1

SUM = 0
nyan = [0]
for az in azu:
	SUM += az
	nyan.append(SUM)

for l,r in qq:
	l -= 1
	if r - l < M:
		print(0)
	else:
		print(nyan[r-M+1] - nyan[l])


import sys

def main():
    n, m, q = list(map(int, input().strip().split()))
    s = input()
    t = input()

    pos = []
    for i in range(len(s)):

        if i + len(t) <= len(s) and s[i:i+len(t)] == t:
            pos.append(1)
        else:
            pos.append(0)

    sum = [0]
    for i in range(len(pos)):
        sum.append(sum[-1] + pos[i])

    for _ in range(q):
        l, r = list(map(int, input().strip().split()))
        r = r - len(t) + 1
        l -= 1

        if l < r:
            print(sum[r] - sum[l])
        else:
            print(0)

    return 0

def test(i):
    with open("test_{}.txt".format(i)) as fin:
        sys.stdin = fin
        main()

def __starting_point():
    # test(1)
    # test(2)
    return(main())

__starting_point()


n,m, q = list(map(int, input().split()))
s = str(input())
t = str(input())

def is_in(index):
    if index + m > n:
        return False

    for j in range(m):
        if not t[j] == s[index + j]:
            return False
    return True

precalc_ar_2 = [0 for  i in range(n  +1)]
in_was = [ False for i in range(n)]

for i in range(n):
    if is_in(i):
        in_was[i] = True

val = 0
for i in range(1, n + 1):
    if in_was[i - 1]:
        val +=1
    precalc_ar_2[i] = val

for i in range(q):
    l, r = list(map(int,input().split()))
    if r- m + 1 < 0 or r- m + 1 < l  - 1:
        print(0)
    else:
        print(precalc_ar_2[r - m +1] - precalc_ar_2[l - 1])


3

def calc(l, r, layers, li):
    if r - l == 1:
        return layers[li][l]

    xl = l
    if l % 2 == 1:
        xl -= 1
    xr = r
    if r % 2 == 1:
        xr += 1

    ans = calc(xl // 2, xr // 2, layers, li + 1)
    if xl != l:
        ans -= layers[li][xl]
    if xr != r:
        ans -= layers[li][xr - 1]
    return ans

def solve(N, M, Q, S, T, A):
    base = [0] * N
    i = 0
    while True:
        try:
            i = S.index(T, i)
            base[i] = 1
            i += 1
        except ValueError:
            break

    layers = [base]
    while len(layers[-1]) > 1:
        prev = layers[-1]
        if len(prev) % 2 == 1:
            prev.append(0)

        layer = []
        for i in range(len(prev) // 2):
            layer.append(prev[2 * i] + prev[2 * i + 1])

        layers.append(layer)

    ans = []
    for (l, r) in A:
        l -= 1

        r -= M - 1
        if r <= l:
            ans.append(0)
            continue

        ans.append(calc(l, r, layers, 0))

    return ans

def main():
    N, M, Q = [int(e) for e in input().split(' ')]
    S = input()
    T = input()
    A = [map(int, input().split(' ')) for _ in range(Q)]

    assert len(S) == N
    assert len(T) == M

    print(*solve(N, M, Q, S, T, A), sep='\n')

def __starting_point():
    main()

__starting_point()


import sys

n,m,q=list(map(int,input().split()))
s=input()
t=input()
A=[None]*q
for i in range(q):
    A[i]=list(map(int,input().split()))

if m>n:
    for i in range(q):
        print(0)

    return

score=[0 for i in range(n-m+1)]
for i in range(n-m+1):
    if t==s[i:i+m]:
        score[i]=1

SUM=[0 for i in range(n-m+1)]
SUM[0]=score[0]
for i in range(1,n-m+1):
    SUM[i]=score[i]+SUM[i-1]

SUM=[0]+SUM
for i in range(q):
    if A[i][1]-m+1<=A[i][0]-1:
        print(0)
    else:
        print(SUM[A[i][1]-m+1]-SUM[A[i][0]-1])


# from math import ceil
#from sys import stdout

t = 1#int(input())
for test in range(1,t+1):
    n,m,q = list(map(int, input().split()))
    s = input()
    t = input()
    indices = [0 for i in range(n)]
    for i in range(n):
        tmp = s.find(t, i)
        if tmp==-1:
            break
        else:
            indices[tmp] = 1
    pref = [0]
    for i in indices:
        pref.append(i+pref[-1])
    for i in range(q):
        l,r = list(map(int, input().split()))
        if r-l+1<m:
            print(0)
            continue
        print(pref[r-m+1]-pref[l-1])


n, m, q = list(map(int, input().split()))
a = input()
b = input()
c = [0]
for i in range(1, n + 1):
    # print(a[max(i - m, 0):i])
    c.append(c[i - 1] + (a[max(i - m, 0):i] == b))

# print(c)
for i in range(q):
    l, r = list(map(int, input().split()))
    if r - l >= m - 1:
        print(max(c[r] - c[l + m - 2], 0))
    else:
        print(0)


def coun(s, t):
    d = 0
    for i in range(len(s) - len(t) + 1):
        if s[i:i + len(t)] == t:
            d += 1
    return(d)

n, m, q = list(map(int, input().split()))
s = input()
t = input()
x = [0]

for j in range(n):
    x.append(coun(s[:j + 1], t))
for i in range(q):
    l, r = list(map(int, input().split()))
    r += 1
    if m <= r - l:
        print(x[r - 1] - x[max(0, l + m - 2)])
    else:
        print(0)


# n=int(input())
# ns=[int(x) for x in input().split()]
# dp=[None]*n
# def greater(i,num):
#     return ns[i]+ns[i+1]>=num
# def biSearch(t,l,r):
#     if r-l<=1:
#         return l
#     m=(l+r)//2
#     if greater(m,t)
#
#
# def update(t):
#     l=ns[t]
n,m,q=[int(x)for x in input().split()]
sn=input()
sm=input()

def eq(i):
    for j in range(m):
        if sn[i+j]!=sm[j]:
            return False
    return True
re=[0]*n
for i in range(n-m+1):
    if eq(i):
        re[i]=1
for i in range(1,n):
    re[i]+=re[i-1]

for i in range(q):
    l,r=[int(x)-1 for x in input().split()]
    if r-l+1<m:
        print(0)
        continue
    if l==0:
        print(re[r-m+1])
    else:
        print(re[r-m+1]-re[l-1])


N,M,Q = [int(x) for x in input().split()]
S = input() #length N
T = input() #length M
A = []
pref = []
for i in range(N):
  A.append(0)
  pref.append(0)
for i in range(N):
  if S[i:i+M] == T:
    A[i] = 1
  if i > 0:
    pref[i] = pref[i-1] + A[i]
  else:
    pref[i] = A[i]
for i in range(Q):
  l,r = [int(x) for x in input().split()]
  l -= 1
  r -= 1
  if r-l+1 >= M:
    if r-M+1 >= 0:
      if l-1>=0:
        print(pref[r-M+1]-pref[l-1])
      else:
        print(pref[r-M+1])
    else:
      print(0)
  else:
    print(0)


'''input
3 5 2
aaa
baaab
1 3
1 1
'''
from bisect import bisect_left, bisect_right

n, m, q = list(map(int, input().split()))
s, t = input(), input()
x = []
for i in range(len(s) - len(t) + 1):
	if s[i:i+len(t)] == t:
		x.append(i)
sx = set(x)
for _ in range(q):
	l, r = list(map(int, input().split()))
	if r - l + 1 < len(t):
		print(0)
		continue
	i = bisect_right(x, l - 1)
	j = bisect_left(x, r - len(t))
	if l - 1 in sx:
		i -= 1
	if r - len(t) not in sx:
		j -= 1
	print(j - i + 1)


from bisect import bisect_left, bisect_right

def main():
    n, m, q = list(map(int, input().split(' ')))
    s = input()
    t = input()

    ps = []
    for i in range(n-m+1):
        if t == s[i:i+m]:
            ps.append(i)

    ans = []
    for _ in range(q):
        l, r = list(map(int, input().split(' ')))
        l, r = l - 1, r - 1
        i = bisect_left(ps, l)
        j = bisect_right(ps, r - m + 1)
        ans.append(max(j - i, 0))
    for x in ans:
        print(x)

def __starting_point():
    main()

__starting_point()


def mi():
	return list(map(int, input().split()))

n,m,q = mi()
s = list(input())
t = list(input())
pre1 = [0]*n
pre2 = [0]*n
if n>=m:
	for i in range(n-m+1):
		if (s[i:i+m]==t):
			pre1[i+m-1] = 1
			pre2[i] = 1
	for i in range(1,n):
		pre1[i]+=pre1[i-1]
		pre2[i]+=pre2[i-1]
pre1.insert(0,0)
pre2.insert(0,0)

while q:
	q-=1
	l,r = mi()
	s1, s2 = 0,0
	#for i in range(l, r+1):
		#s1+=pre1[i]
		#s2+=pre2[i]
	if m>n:
		print(0)
		continue
	if r<m or r-l+1<m or n-l+1<m:
		print(0)
		continue
	s1 = pre1[r]-pre1[l-1+m-1]
	s2 = pre2[r-m+1]-pre2[l-1]
	if s1>0 and s2>0:
		print(min(s1,s2))
	else:
		print(0)


arr = [0] * (10 ** 6 + 1)
n = int(input())
for i in input().split():
    arr[int(i)] += 1
i = 10 ** 6
j = i
k = i
c = 0
while j > 0:
    if arr[j] % 2 == 1 and (arr[j] > 1 or c == 0):
        arr[j - 1] += 1
        c = 1
    else:
        c = 0
    j -= 1
r = 0
while i > 0 and k > 0:
    if arr[i] < 2:
        if i == k:
            k -= 1
        i -= 1
    elif i == k and arr[i] < 4:
        k -= 1
    elif arr[k] < 2:
        k -= 1
    else:
        r += i * k
        arr[i] -= 2
        arr[k] -= 2
print(r)


n = int(input())
l = list(map(int, input().split()))
l.sort(key=lambda x: -x)
i = 0
cur = 0
ans = 0
while i < len(l)-1:
    if l[i] == l[i+1] or l[i]-1 == l[i+1]:
        if cur == 0:
            cur = l[i+1]
        else:
            ans += cur*l[i+1]
            cur = 0
        i += 2
    else:
        i += 1
print(ans)


def __starting_point():
    input()
    data = sorted(map(int, input().split()), key=lambda x: -x)

    if len(data) < 4:
        print(0)
        return

    total = 0
    i = 0

    while i < len(data) - 3:
        if abs(data[i] - data[i + 1]) > 1:
            i += 1
            continue

        success = False
        for j in range(i + 2, len(data) - 1):
            if abs(data[j] - data[j + 1]) > 1:
                continue

            success = True
            total += min(data[i], data[i + 1]) * min(data[j], data[j + 1])
            i = j + 2
            break

        if not success:
            i += 1

    print(total)

__starting_point()


n = int(input())
s = map(int, input().split())
s = list(reversed(sorted(s)))
i = 1
k =[]
while i < n:
    if s[i-1] - s[i] == 1:
        k.append(s[i])
        i += 1
    elif s[i-1] == s[i]:
        k.append(s[i])
        i += 1
    i +=1
ans = 0
for i in range(1, len(k), 2):
    ans += k[i]*k[i-1]
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l.sort(reverse=True)
a = []
i = 0
while i < len(l) - 1:
    #print(l[i], l[i + 1])
    if l[i] == l[i + 1]:
        a.append(l[i])
        i += 2
    else:
        if l[i] == l[i + 1] + 1:
            a.append((l[i] - 1))
            i += 2
        else:
            i += 1

#print(a)
if len(a) % 2 != 0:
    a.append(0)

s, i = 0, 0
while i < len(a):
    s += a[i] * a[i + 1]
    i += 2
print(s)


n=int(input())
L=[int(x) for x in input().split()]
L.sort(reverse=True)
i=0
while i<n-1:
	if L[i]-1==L[i+1]:
		L[i]-=1
		i+=1
	elif L[i]==L[i+1]:
		i+=1
	i+=1
val=[]
i=0
while i<n-1:
	if L[i]==L[i+1]:
		val.append(L[i])
		i+=1
	i+=1
area=0
n=len(val)
i=0
while i<n-1:
	area+=val[i]*val[i+1]
	i+=2
print(area)


ans = 0
n = 0
n = int(input(""))
l = input("")
st = []
for x in l.split(" "):
    st.append(int(x))
st.sort()
i = n-1
while i>=3:
    if st[i]>st[i-1]+1:
        i = i -1
        continue
    l = st[i-1]
    i = i -2
    while i>0 and st[i]>st[i-1]+1:
        i=i-1
    if i == 0:
        break
    b = st [i-1]
    ans = ans + l*b
    i = i - 2
print(ans)


n = int(input())
l = []
inline = input().split()
for i in range (n):
    l.append(int(inline[i]))
l.sort()
right_equal = 1
ans = 0
if len(l) >= 4:
    for i in range(len(l) - 2, -1, -1):
        if l[i] != l[i + 1]:
            if right_equal % 2 != 0:
                if l[i + 1] - l[i] == 1:
                    l[i + 1] -= 1
                    right_equal = 2
                else:
                    l.pop(i + 1)
            else:
                right_equal = 1
        else:
            right_equal += 1
if len(l) >= 4:
    if l[0] != l[1]:
        l.pop(0)
    flag = 1
    for i in range(len(l) - 2, -1, -2):
        if flag == 1:
            c = l[i]
        else:
            ans += c * l[i]
            c = 0
        flag = 1 - flag
print (ans)


n = int(input())

lst = []
lst.extend(list(map(int, input().split())))

tarea = 0

lst.sort()
lst = lst[::-1]
lst.append(0)

i = 0
mark = 0
ar = []
while i != n:
    if (lst[i] - lst[i+1])<=1:
        ar.append(lst[i+1])
        mark += 1
        i += 2
    else:
        i += 1
    if mark == 2:
        tarea = tarea + ar[0]*ar[1]
        ar = []
        mark = 0

print(tarea)


sux = 0
two = 0
x=int(input())
s=list(map(int, input().split(' ')))

t = [0] * (1000001)
for i in s:
    t[i] += 1
for i in range(len(t)-1, 0, -1):
    if t[i]%2==1 and t[i-1]>0:
        t[i] -= 1
        t[i-1] += 1
    elif t[i]%2==1 and t[i]>0:
        t[i] -= 1
for i in range(len(t)-1, 0, -1):
    if two != 0 and t[i] != 0:
        sux += i*two
        two = 0
        t[i] -= 2
    if t[i] % 4 == 0:
        sux += (t[i]//4)*i*i
    else:
        sux += (t[i]//4)*i*i
        if two != 0:
            sux += i*two
            two = 0

        else:
            two = i

print(sux)


#!/c/Python34/python
# coding: utf-8 ans

def main():
    n = int(input())
    L = sorted(map(int, input().split()))
    L.reverse()
    K = []
    i = 1
    while(i < n):
        if L[i-1] == L[i]:
            K.append(L[i])
            i += 1
        elif L[i-1]-L[i] == 1:
            K.append(L[i])
            i += 1
        i += 1
    ans = 0
    for i in range(1, len(K), 2):
        ans += K[i-1] * K[i]
    print(ans)
    #print(K)

def __starting_point():
    main()

__starting_point()


_ = int(input())
as_ = list(sorted(map(int, input().split())))

def get_pair():
    while len(as_) >= 2:
        s0 = as_.pop()
        s1 = as_.pop()
        if s0-1 == s1 or s0 == s1:
            return s1
        as_.append(s1)
    return None

ans = 0
tb = get_pair()
lr = get_pair()
while not (tb is None or lr is None):
    ans += tb * lr
    tb = get_pair()
    lr = get_pair()
print(ans)


def main():
    n = int(input())
    l = [int(i) for i in input().split()]
    l.sort()
    l.reverse()
    candidate = []
    i = 1
    while (i < n):
        if (l[i - 1] - l[i] <= 1):
            candidate.append(min(l[i - 1], l[i]))
            i += 2
        else:
            i += 1

    area = 0
    for i in range(1, len(candidate), 2):
        area += candidate[i] * candidate[i - 1]
    return area

def __starting_point():
    print(main())
__starting_point()


n = int(input())
ls = list(map(int, input().split()))
ls.sort(reverse=True)

area = 0
pairs = []
i = 0
while i < len(ls)-1:
    if (ls[i] - ls[i+1]) > 1:
        i += 1
    else:
        pairs.append(ls[i+1])
        i += 2
    if len(pairs) == 2:
        area += pairs.pop() * pairs.pop()
print(area)


n = int(input())
maxn = 10**6 + 2
cnt = [0] * maxn
for x in map(int, input().split()):
    cnt[x] += 1
ansv = []
for i in range(maxn - 2, 1, -1):
    ansv += [i] * ((cnt[i] + (cnt[i+1] & 1)) >> 1)
    if cnt[i] > 0:
        cnt[i] += cnt[i+1] & 1
ans = 0
for i in range(1, len(ansv), 2):
    ans += ansv[i] * ansv[i-1]
print(ans)


s = input()
lst = [int(i) for i in input().split()]
lst.sort()
lst = lst[::-1]
n = 0
k = 0
while len(lst) >= 2:
    if lst[0] == lst[1] or lst[0] == lst[1]+1:
        if k != 0:
            n += k*lst[1]
            lst.pop(0)
            lst.pop(0)
            k = 0
        else:
            k = lst[1]
            lst.pop(0)
            lst.pop(0)

    else:
        lst.pop(0)
print(n)


n, v, ps, pp = int(input()), 0, 0, 0
for l in sorted(map(int, input().split()), reverse=True):
    if ps == 0 or ps > l + 1:
        ps = l
    elif pp == 0:
        pp, ps = l, 0
    else:
        v, pp, ps = v + pp * l, 0, 0
print(v)


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

length = [0] * 1000000
miv = 1000000
mav = 0
answ = 0
for i in range(len(sticks)):
	length[sticks[i]-1] = length[sticks[i]-1] + 1
	if sticks[i]-1 > mav:
		mav = sticks[i] - 1
	if sticks[i] -1 < miv:
		miv = sticks[i] -1

length = length[miv:mav+1]
for i in range(len(length)-1, -1, -1):
	if length[i] % 2 == 1:
		if i > 0 and length[i-1] > 0:
			length[i] = length[i] - 1
			length[i-1] = length[i-1] + 1
		else:
			length[i] = length[i] - 1

square = []
for i in range(len(length)-1, -1, -1):

	while length[i] > 0:
		square.append(i + miv + 1)
		length[i] = length[i] - 2
		if len(square) == 2:
			answ += square[0] * square[1]
			square = []
print(answ)


I = lambda : map(int,input().split())
n = int(input())
p = list(I())
cnt = [0] * 1000001
for i in p: cnt[i] += 1
for i in range(1000000,1,-1):
    if cnt[i] % 2 == 1 and cnt[i - 1] > 0:
        cnt[i] -= 1
        cnt[i - 1] += 1
    elif cnt[i] % 2 == 1 and cnt[i - 1] == 0:
        cnt[i] -= 1
p = 0
ans = 0
for i in range(1000000,1,-1):
    if cnt[i] != 0:
        if p != 0:
            cnt[i] -= 2
            ans += p * i
            p = 0
        ans += i * i * (cnt[i] // 4)
        if cnt[i] % 4 != 0:
            p = i
print (ans)


from collections import Counter

input()
lengths = [int(i) for i in input().split()]
cnt = Counter(lengths)
lengths.sort(reverse=True)
total_square = 0

for le in lengths:
    if cnt[le] % 2 != 0:
        if cnt[le-1] > 0:
            cnt[le-1] += 1
        cnt[le] -= 1

for le in lengths:
    if cnt[le] >= 4:
        cnt[le] -= 4
        total_square += le ** 2
    elif cnt[le] < 4 and cnt[le] > 0:
        min_le = le - 1
        while min_le > 0 and cnt[min_le] < 2:
            min_le -= 1
        cnt[le] -= 2
        cnt[min_le] -= 2
        total_square += le * min_le

print(total_square)


import sys
def otb(l):
    i = 0
    while i < n - 1:
        if l[i] - 1 == l[i + 1]:
            l[i] -= 1
            i += 1
        elif l[i] == l[i + 1]:
            i += 1
        i += 1
    znach = []
    i = 0
    while i < n - 1:
        if l[i] == l[i + 1]:
            znach.append(l[i])
            i += 1
        i += 1
    return znach
def ploshad(n,znach):
    summa = 0
    n = len(znach)
    for i in range(0, n - 1, 2):
        summa += znach[i] * znach[i + 1]
    sys.stdout.write(str(summa))

n = int(sys.stdin.readline())
l = []
l = [int(j) for j in sys.stdin.readline().split()]
l.sort(reverse=True)
znach=otb(l)
ploshad(n,znach)


n = int(input())
a, b = 0, 0
ans = 0
for i in sorted(map(int,input().split()),reverse=True):
    if a == 0 or a > i + 1:
        a = i
    elif b == 0:
        a, b= 0, i
    else:
        ans += i * b
        a, b = 0, 0
print(ans)


def max(a, b):
	if a > b:
		return a
	else:
		return b
n, k = map(int, input().split())
x = [int(t) for t in input().split()]
y = [int(t) for t in input().split()]
f, s = 0, 0
for i in range(n):
    f = max(0, x[i] + f - k * y[i])
    s = max(0, y[i] + s - k * x[i])
    if f > k or s > k:
        print('NO')
        return
print('YES')


def max(a, b):
	if a > b:
		return a
	return b
n, k = map(int, input().split())
o = [int(t) for t in (input()+' '+input()).split()]
f, s = 0, 0
for i in range(n):
    f = max(0, o[i] + f - k * o[i+n])
    s = max(0, o[i+n] + s - k * o[i])
    if f > k or s > k:
        print('NO')
        return
print('YES')


n, k = map(int, input().split())
o = [int(t) for t in (input()+' '+input()).split()]
f, s = 0, 0
for i in range(n):
    f = max(0, o[i] + f - k * o[i+n])
    s = max(0, o[i+n] + s - k * o[i])
    if f > k or s > k:
        print('NO')
        return
print('YES')


def get(px, py, x, y):
	ans = 10**18
	nonlocal k
	if px <= k:
		cnt = (px + x + k - 1) // k - 1
		if y == cnt:
			ans = min(ans, px + x - cnt * k)
		elif y > cnt and y <= x * k:
			ans = min(ans, 1)
	if py <= k:
		cnt = (x + k - 1) // k - 1
		if y == cnt:
			ans = min(ans, x - cnt * k)
		elif y > cnt and y <= (x - 1) * k + (k - py):
			ans = min(ans, 1)
	return ans

n, k = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dp = [[10**18] * (n + 1), [10**18] * (n + 1)]
dp[0][0], dp[1][0] = 0, 0
for i in range(n):
	dp[0][i + 1] = get(dp[0][i], dp[1][i], x[i], y[i])
	dp[1][i + 1] = get(dp[1][i], dp[0][i], y[i], x[i])
print('YES' if min(dp[0][-1], dp[1][-1]) <= k else 'NO')


from math import ceil

p,x,y = map(int, input().split())
h = x
while h >=y:
    h-=50
h+=50
for i in range(h, 10000000000, 50):
    u = (i//50)%475
    d = []
    for j in range(25):
        u = (u * 96 + 42)%475
        d.append(26 + u)
    if p in d:
        k = i
        break
if k-x>0:
    print(ceil((k-x)/100))
else:
    print(0)


from sys import stdin, stdout

def findWinners(s):
    winSet=set()
    i=(s//50)%475
    for _ in range(25):
        i = (i*96+42)%475
        winSet.add(26+i)
    return winSet

p,x,y = list(map(int, stdin.readline().rstrip().split()))

x1=x
successfulHacks=0
winning=False
while x1>=y and not winning:
    if p in findWinners(x1):
        winning=True
    x1-=50

while not winning:
    x+=100
    successfulHacks+=1
    if p in findWinners(x) or p in findWinners(x-50):
        winning=True

print(successfulHacks)


from sys import stdin
input = stdin.readline

p, x, y = [int(i) for i in input().split()]

def shirt(score, place):
  i = int(score/50)%475
  for j in range(25):
    i = (i*96+42)%475
    if place==(i+26):
      return True
  return False

ans = -1
c = x
while c>=y:
  if shirt(c, p):
    ans = 0
    break
  else:
    c -= 50

if ans==-1:
  c = 0
  while True:
    if shirt((c*100)+50+x,p) or shirt((c*100)+100+x,p):
      ans = c+1
      break
    else:
      c+=1
print(ans)


def calc_T_shirt_winner_places(s):
    """
    i := (s div 50) mod 475
repeat 25 times:
    i := (i * 96 + 42) mod 475
    print (26 + i)
    """
    i = (s // 50) % 475
    i_indices = set()
    for j in range(25):
        i = (i * 96 + 42) % 475
        i_indices.add(26 + i)

    return i_indices

def reachable_by_unsuccessful_hacks(wanted_place, orig_score, min_place):
    score = orig_score
    while score >= min_place:
        if wanted_place in calc_T_shirt_winner_places(score):
            return True
        score -= 50

    if wanted_place in calc_T_shirt_winner_places(score) and score >= min_place:
        return True
    return False

def calc_number_of_successful_hacks_needed(wanted_place, orig_score):
    hacks = 0
    score_by_50, score_by_100 = orig_score + 50, orig_score + 100

    while True:
        hacks += 1
        if (score_by_50 >= min_place and wanted_place in calc_T_shirt_winner_places(score_by_50)) or (score_by_100 >= min_place and wanted_place in calc_T_shirt_winner_places(score_by_100)):
            return hacks
        score_by_50 += 100
        score_by_100 += 100

codecraft_place, curr_score, min_place = [int(p) for p in input().split()]
if reachable_by_unsuccessful_hacks(codecraft_place, curr_score, min_place):
    print(0)
else:
    print(calc_number_of_successful_hacks_needed(codecraft_place, curr_score))


import math
p,x,y=map(int,input().split())
s=0
s=int(math.ceil((y-x)/50))
while(s<=1000000):
	score = x+50*s
	i=(score//50)%475
	l=[]

	for j in range(25):
		i=(i*96+42)%475
		l.append(26+i)
	if(p in l):
		break
	else:
		s+=1
if(s<=0):
	print(0)
else:
	print(int(math.ceil(s/2)))


def findNumbers(s):
    t = [0]*25
    i = (s//50)%475
    for k in range(25):
        i = (i * 96 + 42) % 475
        t[k] = i+26
    return t

p, x, y = list(map(int, input().split() ))

k = 0

if x >= y:
    xt = x

    while (p not in findNumbers(xt) and xt >= y ):
        xt -= 50
    if p in findNumbers(xt) and xt >= y:
        print(0)
    else:
        xt = x
        while (p not in findNumbers(xt)):
            xt += 50
            k+=0.5
##            print(str(k) + " " + str(xt) )

        print( int(k+0.5))
else:
    k = (y-x) // 100
    xt = ((y-x) // 100) * 100 + x
    if xt<y:
        xt+=100
        k+=1
##    print(xt)
    while (p not in findNumbers(xt) and xt >= y ):
        xt -= 50
    if p in findNumbers(xt) and xt >= y:
        print(k)
    else:
        xt = x
        while (p not in findNumbers(xt)):
            xt += 50
            k+=0.5
##            print(str(k) + " " + str(xt) )

        print( int(k+0.5))


from sys import stdin, stdout
from math import ceil

p, x, y = map(int, stdin.readline().split())
s = set()

if x < y:
    ans = (y - x) // 100
    x = x + 100 * ans
else:
    ans = 0

if x >= y:
    label = 0
    for i in range(100):
        xc = x + 100 * i

        while (xc >= y):
            if (not xc in s):
                s.add(xc)

                ind = (xc // 50) % 475

                for j in range(25):
                    ind = (ind * 96 + 42) % 475

                    if ind + 26 == p:
                        label = 1
                        ans += i

                if label:
                    break
            elif i:
                break

            xc -= 50

        if label:
            break

stdout.write(str(ans))


def f(s):
    i = (s // 50) % 475
    l = []
    for j in range(25):
        i = (i * 96 + 42) % 475
        l.append(26 + i)
    return l

p, x, y = list(map(int, input().split()))

i = x
while i >= y:
    i -= 50
    if f(i).count(p) > 0:
        break
if i >= y:
    print(0)
    return

i = x
c = 0
while True:
    if f(i).count(p) > 0:
        break
    i += 50
    c += 1

#print(i)

if c % 2 == 1:
    print((c + 1) // 2)
else:
    print(c // 2)

#print(f(7258 + 150))


import sys

input_ = sys.stdin.readline

def precompute_places():
    res = {}

    for i in range(476):
        res[i] = get_tshirt_winners(i)

    return res

def get_tshirt_winners(i):
    winners = set()

    for _ in range(25):
        i = (i * 96 + 42) % 475
        winners.add(i + 26)

    return winners

def can_haz_tshirt(s, p, places):
    i = (s // 50) % 475

    if p in places[i]:
        return True
    return False

def main():
    p, x, y = list(map(int, input_().split()))

    places = precompute_places()

    x_down = x
    while x_down >= y:
        if can_haz_tshirt(x_down, p, places):
            return 0
        x_down -= 50

    x += 100
    successes = 1
    for _ in range(476):
        if can_haz_tshirt(x, p, places) or can_haz_tshirt(x - 50, p, places):
            return successes

        x += 100
        successes += 1

    return -1

def __starting_point():
    print(main())

__starting_point()


def main():
    p, x, y = list(map(int, input().split()))

    # 0 check
    xcopy = x
    while xcopy >= y:
        if p in choice(xcopy):
            print(0)
            return
        xcopy -= 50

    # + check
    i = 1
    while x <= 23800:
        if (p in choice(x + 100*i - 50)) or (p in choice(x + 100*i)):
            print(i)
            return
        i += 1

def choice(s):
    i = (s//50)%475

    res = []
    for n in range(25):
        i = (i*96 + 42) % 475
        res.append(26 + i)

    return res

def __starting_point():
    # nonlocal stime
    # stime = time.clock()
    main()

__starting_point()


p, x, y = list(map(int, input().split()))

cur = x
while cur - 50 >= y:
    cur -= 50

def gen(s):
    i = (s // 50) % 475
    res = []
    for _ in range(25):
        i = (i * 96 + 42) % 475
        res.append(26 + i)
    return res

while p not in gen(cur):
    cur += 50

print((max(cur - x, 0) + 99) // 100)


import sys

def main():
    p,x,y=list(map(int,sys.stdin.readline().split()))

    s = x
    i = (s // 50) % 475
    for _ in range(25):
        i = (i * 96 + 42) % 475
        next = 26 + i
        if next == p:
            result = 0
            sys.stdout.write(str(result)+'\n')
            return

    s = x - 50
    while True:
        if s < y: break
        i = (s // 50) % 475
        for _ in range(25):
            i = (i * 96 + 42) % 475
            next = 26 + i
            if next == p:
                result = 0
                sys.stdout.write(str(result)+'\n')
                return
        s -= 50

    iplus = 1
    while True:
        for s in (x + iplus*100, x + iplus*100-50):
            i = (s // 50) % 475
            for _ in range(25):
                i = (i * 96 + 42) % 475
                next = 26 + i
                if next == p:
                    result = iplus
                    sys.stdout.write(str(result)+'\n')
                    return
        iplus += 1

main()


import sys

inf = 1<<60

def solve():
    p, x, y = map(int, input().split())

    for s in range(x, y - 1, -50):
        if p in list_tshirt(s):
            print(0)
            return

    for i in range(1, 476):
        s = x + i*50

        if p in list_tshirt(s):
            print((i + 1) // 2)
            return

def list_tshirt(s):
    res = [0]*25
    i = (s // 50) % 475

    for k in range(25):
        i = (i*96 + 42) % 475
        res[k] = i + 26

    return res

def __starting_point():
    solve()
__starting_point()