CodeEff/ECCO huggingface dataset:
# Original solution
import sys
sys.setrecursionlimit(10**9)


N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
count = 0

for _ in range(M):
    A, B = [int(x) - 1 for x in input().split()]
    to[A].append(B)
    to[B].append(A)


def dfs(v, to, seen):
    global count
    seen[v] = True
    count += 1
    for nv in to[v]:
        if seen[nv]:
            continue
        dfs(nv, to, seen)


def main():
    global count
    seen = [False] * N
    cnts = []
    for i in range(N):
        if not seen[i]:
            dfs(i, to, seen)
            cnts.append(count)
            count = 0
    
    print((max(cnts)))


if __name__ == "__main__":
    main()



# Optimized solution
import sys
sys.setrecursionlimit(10**9)


N, M = list(map(int, input().split()))
to = [[] for _ in range(N)]
count = 0

for _ in range(M):
    A, B = [int(x) - 1 for x in input().split()]
    to[A].append(B)
    to[B].append(A)


def dfs(v, to, seen):
    global count
    seen[v] = True
    count += 1
    for nv in to[v]:
        if seen[nv]:
            continue
        dfs(nv, to, seen)


def main():
    global count
    ans = 0
    seen = [False] * N
    for i in range(N):
        if not seen[i]:
            dfs(i, to, seen)
            ans = max(ans, count)
            count = 0
    
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
import sys
sys.setrecursionlimit(500*500)

class UnionFind():
    def __init__(self, n):
        self.par = [-1]*n

    def root(self, x):
        if self.par[x] < 0:
            return x
        return self.root(self.par[x])

    def unite(self, x, y):
        if x > y:
            x, y = y, x
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx

    def size(self, x):
        return -self.par[self.root(x)]

    def same(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        return rx == ry

    def return_par(self):
        return self.par

n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = list(map(int, input().split()))
    uf.unite(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)


# Optimized solution
import sys
sys.setrecursionlimit(10**8)

class UnionFind():
    def __init__(self, n):
        self.par = [-1]*n

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

    def union(self, x, y):
        if x > y:
            x, y = y, x
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx

    def size(self, x):
        return -self.par[self.find(x)]

    def same(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        return rx == ry

    def return_par(self):
        return self.par

n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = list(map(int, input().split()))
    uf.union(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))
print(ans)
# Original solution
MOD = 10**9+7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

P = [0 for i in range(R+1)]
for k in range(R+1):
  u = (R-M*(k+1))//(k+1)
  for j in range(u+1):
    P[(k+1)*j+M*(k+1)] += nCr(N-M,j)*(-1)**(j%2)
    P[(k+1)*j+M*(k+1)] %= MOD
for k in range(1,R+1):
  u = (R-M*(k+1))//k
  for j in range(u+1):
    P[k*j+M*(k+1)] -= nCr(N-M,j)*(-1)**(j%2)
    P[k*j+M*(k+1)] %= MOD

Q = [nCr(i+N,N) for i in range(R+1)]

def f(MAX):
  ans = 0
  for t in range(MAX+1):
    ans += P[t]*Q[MAX-t]
    ans %= MOD
  return ans

def F(x):
  return (Q[x]-nCr(N,M)*f(x))%MOD

print(((F(R)-F(L-1))%MOD))

# Optimized solution
MOD = 10**9+7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

P = [0 for i in range(R+1)]
Q = [0 for i in range(R+1)]
Z = [0 for i in range(R+1)]
for k in range(1,R+1):
  u = (R-M*k)//k
  for j in range(u+1):
    P[k*j+M*k] += nCr(N-M,j)*(-1)**(j%2)
    P[k*j+M*k] %= MOD
for k in range(R+1):
  Q[k] += nCr(k+N,N)
  Q[k] %= MOD
  Z[k] += nCr(k+N,N)
  Z[k] %= MOD
for k in range(R-M+1):
  Q[k+M] -= nCr(k+N,N)
  Q[k+M] %= MOD

def f(MAX):
  ans = 0
  for t in range(MAX+1):
    ans += P[t]*Q[MAX-t]
    ans %= MOD
  return ans

def F(x):
  return (Z[x]-nCr(N,M)*f(x))%MOD

print(((F(R)-F(L-1))%MOD))
# Original solution
N = int(eval(input()))
A = [int(i) for i in input().split()] 
mod = 10**9 + 7

b = [0]*N
b[0] = A[0]
for n in range(1,N):
    b[n] = A[n] ^ b[n-1]

dp = [[not j for i in range(1<<20)] for j in range(2)]
cnt = [0 for i in range(1<<20)]
z = 0

for i in range(N):
    if b[i] == 0:
        z +=1
    dp[0][b[i]] += dp[1][b[i]]*(z-cnt[b[i]])
    dp[0][b[i]] %= mod
    dp[1][b[i]] += dp[0][b[i]]
    dp[1][b[i]] %= mod
    cnt[b[i]] = z

if b[N-1]:
    print((dp[0][b[N-1]]))
else:
    ans = pow(2, z-1, mod)
    for i in range(1, 1<<20):
        ans += dp[1][i]
        ans %= mod
    print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(i) for i in input().split()] 
mod = 10**9 + 7

b = [0]*N #
b[0] = A[0]
for n in range(1,N):
    b[n] = A[n] ^ b[n-1]
#print('累積論理和',b)
m = max(b)
dp = [[0]*(m+1) for j in range(2)]
dp[0] = [True]*(m+1)
dp[1] = [False]*(m+1)
cnt = [0]*(m+1)
z = 0

for i in range(N):
    if b[i] == 0:
        z +=1
    dp[0][b[i]] += dp[1][b[i]]*(z-cnt[b[i]])
    dp[0][b[i]] %= mod
    dp[1][b[i]] += dp[0][b[i]]
    dp[1][b[i]] %= mod
    cnt[b[i]] = z


if b[N-1]:
    print((dp[0][b[N-1]]))
else:
    ans = pow(2, z-1, mod)
    for i in range(1,m+1):
        ans += dp[1][i]
        ans %= mod
    print(ans)
# Original solution
from collections import defaultdict
from itertools import accumulate
from operator import xor


def solve(acc):
    MOD = 10 ** 9 + 7
    cnt0 = 0
    dp0 = defaultdict(lambda: 1)
    dp1 = defaultdict(lambda: 0)
    last_0 = defaultdict(lambda: 0)
    for a in acc:
        if a == 0:
            cnt0 += 1
        else:
            if a not in dp1:
                dp1[a] = 1
                last_0[a] = cnt0
            else:
                bw0 = cnt0 - last_0[a]
                if bw0 > 0:
                    dp0[a] = (dp0[a] + dp1[a] * bw0) % MOD
                    last_0[a] = cnt0
                dp1[a] = (dp1[a] + dp0[a]) % MOD

    if acc[-1] == 0:
        return (pow(2, cnt0 - 1, MOD) + sum(dp1.values())) % MOD
    else:
        return dp0[acc[-1]]


n = int(eval(input()))
aaa = list(map(int, input().split()))
acc = list(accumulate(aaa, func=xor))
print((solve(acc)))


# Optimized solution
from itertools import accumulate
from operator import xor


def solve(acc):
    MOD = 10 ** 9 + 7
    cnt0 = 0
    dp0 = {}
    dp1 = {}
    last_0 = {}
    for a in acc:
        if a == 0:
            cnt0 += 1
        else:
            if a not in dp1:
                dp0[a] = 1
                dp1[a] = 1
                last_0[a] = cnt0
            else:
                bw0 = cnt0 - last_0[a]
                if bw0 > 0:
                    dp0[a] = (dp0[a] + dp1[a] * bw0) % MOD
                    last_0[a] = cnt0
                dp1[a] = (dp1[a] + dp0[a]) % MOD

    if acc[-1] == 0:
        return (pow(2, cnt0 - 1, MOD) + sum(dp1.values())) % MOD
    else:
        return dp0[acc[-1]]


n = int(eval(input()))
aaa = list(map(int, input().split()))
acc = list(accumulate(aaa, func=xor))
print((solve(acc)))
# Original solution
x,a,b=list(map(int,input().split()));print((['delicious',['safe','dangerous'][b-a>x]][a-b<0]))

# Optimized solution
x,a,b=list(map(int,input().split()))
print((('delicious',('safe','dangerous')[b-a>x])[a<b]))
# Original solution
import collections

h, w, n = list(map(int, input().split()))
y, x = list(map(int, input().split()))
s = input().rstrip()
t = input().rstrip()
counter = collections.Counter()
for c in s:
    counter[c] += 1


def check(counts, direction, opposite_direction, pos, target):
    for i in range(n):
        counts[direction] -= 1
        if s[i] == direction:
            pos += 1
        if pos == target:
            return False
        if t[i] == opposite_direction and pos > 1 and counts[
                opposite_direction] < pos:
            pos -= 1

    return True


for d, od, pos, target in [
    ('R', 'L', x, w + 1),
    ('L', 'R', w + 1 - x, w + 1),
    ('D', 'U', y, h + 1),
    ('U', 'D', h + 1 - y, h + 1),
]:
    ok = check(collections.Counter(list(counter.items())), d, od, pos, target)
    if not ok:
        print('NO')
        break
else:
    print('YES')

# Optimized solution
h, w, n = list(map(int, input().split()))
y, x = list(map(int, input().split()))
s = input().rstrip()
t = input().rstrip()


def check(direction, opposite_direction, pos, target):
    for i in range(n):
        if s[i] == direction:
            pos += 1
        if pos == target:
            return False
        if t[i] == opposite_direction and pos > 1:
            pos -= 1
    return True


for d, od, pos, target in [
    ('R', 'L', x, w + 1),
    ('L', 'R', w + 1 - x, w + 1),
    ('D', 'U', y, h + 1),
    ('U', 'D', h + 1 - y, h + 1),
]:
    ok = check(d, od, pos, target)
    if not ok:
        print('NO')
        break
else:
    print('YES')
# Original solution
from typing import List
import sys

input = lambda: sys.stdin.readline().rstrip()
n = int(eval(input()))
c = list(map(int, input().split()))
c = [x-1 for x in c]
# print(c)
adj = [[] for i in range(n)]
for i in range(n-1):
    a, b = tuple(map(int, input().split()))
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


size: List[int] = [1 for i in range(n)]
stack: List[List[int]] = [[] for color in range(n)]
in_time: List[int] = [-1 for i in range(n)]
out_time: List[int] = [-1 for i in range(n)]
timer = 0
total = n*(n+1)//2
ans: List[int] = [total for color in range(n)]
# print(ans)


def dfs(parent: int, root: int):
    global timer
    in_time[root] = timer
    timer += 1

    for child in adj[root]:
        if parent == child:
            continue
        dfs(root, child)
        size[root] += size[child]

        cnt = size[child]
        while stack[c[root]]:
            x = stack[c[root]][-1]
            if in_time[x] > in_time[root] and out_time[x] != -1:
                cnt -= size[x]
                stack[c[root]].pop()
            else:
                break
        ans[c[root]] -= cnt*(cnt+1)//2

    out_time[root] = timer
    timer += 1

    stack[c[root]].append(root)


sys.setrecursionlimit(10**6)

dfs(0, 0)
# print(size)
for color in range(n):
    cnt = n
    while len(stack[color]) > 0:
        x = stack[color][-1]
        cnt -= size[x]
        stack[color].pop()
    # print("node:", -1, "color:", color, "cnt:", cnt)
    ans[color] -= cnt*(cnt+1)//2
    print((ans[color]))


# Optimized solution
import sys


def input(): return sys.stdin.readline().rstrip()


n = int(eval(input()))
c = list(map(int, input().split()))
c = [x-1 for x in c]
# print(c)
adj = [[] for i in range(n)]
for i in range(n-1):
    a, b = tuple(map(int, input().split()))
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)


size = [1 for i in range(n)]
stack = [[] for color in range(n)]
in_time = [-1 for i in range(n)]
out_time = [-1 for i in range(n)]
timer = 0
total = n*(n+1)//2
ans = [total for color in range(n)]
# print(ans)


def dfs(parent, root):
    global timer
    in_time[root] = timer
    timer += 1

    for child in adj[root]:
        if parent == child:
            continue
        dfs(root, child)
        size[root] += size[child]

        cnt = size[child]
        while stack[c[root]]:
            x = stack[c[root]][-1]
            if in_time[x] > in_time[root] and out_time[x] != -1:
                cnt -= size[x]
                stack[c[root]].pop()
            else:
                break
        ans[c[root]] -= cnt*(cnt+1)//2

    out_time[root] = timer
    timer += 1

    stack[c[root]].append(root)


sys.setrecursionlimit(10**6)

dfs(0, 0)
# print(size)
for color in range(n):
    cnt = n
    while len(stack[color]) > 0:
        x = stack[color][-1]
        cnt -= size[x]
        stack[color].pop()
    # print("node:", -1, "color:", color, "cnt:", cnt)
    ans[color] -= cnt*(cnt+1)//2
    print((ans[color]))
# Original solution
A,B,X=list(map(int,input().split()))
if A <= X <= (A+B):
  print("YES")
else:
  print("NO")

# Optimized solution
A,B,X=list(map(int,input().split()))

if A>X or A+B <X:
  print("NO")
else:
  print("YES")
# Original solution
a, b, x = list(map(int, input().split()))

if x <= a + b and x >= a:
  print('YES')
else:
  print('NO')

# Optimized solution
a, b, x = list(map(int, input().split()))
print(('YES' if a <= x <= a + b else 'NO'))
# Original solution
from itertools import permutations, combinations, chain
from collections import defaultdict
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

def dpinit(ps, val=0):
    import copy
    res = [val for i in [0]*ps[-1]]
    for i in ps[:-1][::-1]:
        res = [copy.deepcopy(res) for k in [0]*i]
    return res

inf = 10**10
dp = [defaultdict(lambda : inf) for i in range(2**N+1)]
dp[0][0] = 0

for b in range(2**N):
    c = bin(b).count('1')
    for i in range(1,N+1):
        p = N-i
        f = 1<<p
        if b & f:
            continue
        nb = b | f
        k = bin(b % f).count('1')
        v = A[i-1] if (i-c) % 2 == 1 else B[i-1]
        for val, inv in list(dp[b].items()):
            if val <= v:
                dp[nb][v] = min(dp[nb][v], inv+abs(c+1-(i+k)))

if not dp[2**N-1]:
    print((-1))
    exit()
ans = min(dp[2**N-1].values())
print((ans if ans != inf else -1))




# Optimized solution
from itertools import chain
N = int(eval(input()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

def count_bit(x):
    res = 0
    while x:
        res += x % 2
        x >>= 1
    return res

def int2bin(x,N): 
    res = [0]*N
    for i in range(N):
        res[N-1-i] = x % 2
        x >>= 1
    return res

inf = 10**10
M = N//2 # the n of odd index
ans = inf
for b in range(2**N):
    valid = True 
    if count_bit(b) == M:
        odd_index = int2bin(b,N) # 1 : odd
        evens = []
        odds = []
        for i in range(N):
            if odd_index[i]:
                if i % 2:
                    odds.append((A[i],i))
                else:
                    odds.append((B[i],i))
            else:
                if i % 2:
                    evens.append((B[i],i))
                else:
                    evens.append((A[i],i))
        SE = sorted(evens)
        SO = sorted(odds)
        L = [None]*N
        L[::2] = SE
        L[1::2] = SO
        for (a,_),(b,_) in zip(L,L[1:]):
            if a > b:
                valid = False
                break
        if valid:
            L = list(zip(L,list(range(N))))
            L = sorted(L,key=lambda x : x[0][1])
            L = [(a,c) for (a,b),c in L]
            temp = 0
            for i in range(N):
                for j in range(i):
                    if L[j] > L[i]:
                        temp += 1
            ans = min(temp,ans)

if ans == inf:
    ans = -1
print(ans)
# Original solution
import sys
input=sys.stdin.readline
class BinaryIndexedTree():
  def __init__(self,n):self.bit=[0]*n
  def add(self,i,x):
    i+=1
    while i<=len(self.bit):
      self.bit[i-1]+=x
      i+=i&-i
  def sum_1(self,i):
    a=0
    i+=1
    while i:
      a+=self.bit[i-1]
      i-=i&-i
    return a
  def sum(self,i,j):
    a=self.sum_1(j-1)
    if i!=0:a-=self.sum_1(i-1)
    return a
def tentousu(a):
  bit=BinaryIndexedTree(n)
  b=[0]*n
  for i in range(n):
    b[a[i]]=i
  ans=0
  for i in range(n):
    j=b[i]+bit.sum(b[i]+1,n)
    ans+=j-i
    bit.add(b[i],1)
  return ans
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
import itertools
c=set()
for i in range(n):
  if i%2:c.add((b[i],a[i],i))
  else:c.add((a[i],b[i],i))
ans=inf=float('inf')
for i in itertools.combinations(c,(n+1)//2):
  ii=c-set(i)
  ac=[(j[0],j[2])for j in i]
  bc=[(j[1],j[2])for j in ii]
  ac.sort()
  bc.sort()
  x=[]
  for j in range(n):
    if j%2:x.append(bc[j//2])
    else:x.append(ac[j//2])
  f=False
  for j in range(1,n):
    if x[j-1][0]>x[j][0]:f=True
  if f:continue
  m=[]
  for j in range(n):m.append(x[j][1])
  ans=min(ans,tentousu(m))
if ans==inf:ans=-1
print(ans)

# Optimized solution
def tentousu(a):
  ans=0
  for i in range(len(a)):
    for j in range(i+1,len(a)):
      if a[i]>a[j]:ans+=1
  return ans
n=int(eval(input()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(1,n,2):a[i],b[i]=b[i],a[i]
ans=inf=float('inf')
for i in range(2**n):
  s=bin(i)[2:].zfill(n)
  if s.count("0")!=n//2:continue
  ac=[]
  bc=[]
  for j in range(n):
    if s[j]=="1":ac.append((a[j],j))
    else:bc.append((b[j],j))
  ac.sort()
  bc.sort()
  x=[]
  for j in range(n):
    if j%2:x.append(bc[j//2])
    else:x.append(ac[j//2])
  f=False
  for j in range(1,n):
    if x[j-1][0]>x[j][0]:f=True
  if f:continue
  m=[]
  for j in range(n):m.append(x[j][1])
  ans=min(ans,tentousu(m))
if ans==inf:ans=-1
print(ans)
# Original solution


def main():
    import sys
    input = sys.stdin.readline
    n = int(eval(input()))
    a = tuple(map(int,input().split()))
    b = tuple(map(int,input().split()))

    dg = 20

    pp = 20

    dp = [10**5]*(10**7)

    new = set([])
    for i in range(n):
        s = (1<<i)
        dp[s*pp+i] = i
        new.add(s*dg+i)

    for k in range(n-1):
        tank = set([])
        if len(new) == 0:
            break
        for popelt in new:
            s,idx = popelt//dg,popelt%dg
            if (k-idx)%2 == 0:
                fr = a[idx]
            else:
                fr = b[idx]
            cnt = 0
            for j in range(n):
                if (s>>j)&1 == 0:
                    if (j-k)%2 == 1:
                        val = a[j]
                    else:
                        val = b[j]
                    if val >= fr and dp[(s+(1<<j))*pp+j] > dp[s*pp+idx]+j-cnt:
                        dp[(s+(1<<j))*pp+j] = dp[s*pp+idx]+j-cnt
                        tank.add((s+(1<<j))*dg + j)
                else:
                    cnt += 1
        new = tank
    
    res = 10**5
    s = (2**n-1)*pp
    for i in range(n):
        if res > dp[s+i]:
            res = dp[s+i]
    if res == 10**5:
        print((-1))
    else:
        print(res)


if __name__ == '__main__':
    main()

# Optimized solution
import sys
input = sys.stdin.readline

def count(P):
    res = 0
    #A1 ... AnのBIT(1-indexed)
    BIT = [0]*(N+1)

    #A1 ~ Aiまでの和 O(logN)
    def BIT_query(idx):
        res_sum = 0
        while idx > 0:
            res_sum += BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def BIT_update(idx,x):
        while idx <= N:
            BIT[idx] += x
            idx += idx&(-idx)
        return


    Pi = [None]*N
    for i in range(N):
        Pi[P[i]] = i
    for i in range(N):
        p = Pi[i]
        res += i-BIT_query(p+1)
        BIT_update(p+1, 1)
    return res
 

N = int(eval(input()))
A = tuple(map(int,input().split()))
B = tuple(map(int,input().split()))
uhalf = -(-N//2)
dhalf = N - uhalf
inf = 10**9+7
ans = inf
for S in range(1<<N):
    card = [A[i] if S&(1<<i) else B[i] for i in range(N)]
    parity = [(1&(S>>i))^(i&1) for i in range(N)]
    even = [(card[i], i) for i in range(N) if parity[i]]
    odd = [(card[i], i) for i in range(N) if not parity[i]]
    if len(even) != uhalf or len(odd) != dhalf:
        continue
    even.sort()
    odd.sort()
    if any(e[0] > o[0] for e, o in zip(even, odd)) or any(e[0] < o[0] for e, o in zip(even[1:], odd)):
        continue
    perm = [even[i//2][1] if not i&1 else odd[i//2][1] for i in range(N)]
    ans = min(ans, count(perm))
print((ans if ans < inf else -1))
# Original solution
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N = inp()
AA = inpl()
BB = inpl()

# In[]:
# N = 3
# AA = [3, 4, 3]
# BB = [3, 2, 3]

cards = []
for i,(a,b) in enumerate(zip(AA,BB)):
    if i%2 == 0:
        cards.append((a, b, i))
    else:
        cards.append((b, a, i))


n = (N+1)//2

# In[]:
def solve(ii):
    tmp = 0
    # print(ii)
    for _ in range(N):
        next = []
        for k, i in enumerate(ii):
            if i == 0:
                tmp += k
            else:
                next.append(i-1)
        ii = next[:]
    # print(tmp)
    return tmp



# In[]:
ans = INF
for Acards in itertools.combinations(cards, n):
    Ais = sorted([(Acard[0], Acard[2]) for Acard in Acards])

    ii = set([i for A,i in Ais])
    Bis = []
    for a,b,i in cards:
        if i not in ii:
            Bis.append((b,i))
    Bis.sort()

    nums = []
    ii = []
    for i in range(N):
        if i%2 == 0:
            n,i = Ais[i//2]
        else:
            n,i = Bis[i//2]
        nums.append(n)
        ii.append(i)

    # print(nums,ii)
    if nums != sorted(nums):
        continue
    else:
        ans = min(ans,solve(ii))
        if ans == 0:
          print((0))
          sys.exit()


if ans == INF:
    print((-1))
else:
    print(ans)


# Optimized solution
# from collections import defaultdict,deque
# import sys,heapq,bisect,math,itertools,string,queue,copy,time
# sys.setrecursionlimit(10**8)
#
#
import sys
import itertools
INF = float("INF")

N = int(eval(input()))
AA = list(map(int, sys.stdin.readline().split()))
BB = list(map(int, sys.stdin.readline().split()))

cards = set()
for i,(a,b) in enumerate(zip(AA,BB)):
    if i%2 == 0:
        cards.add((a, b, i))
    else:
        cards.add((b, a, i))




# In[]:
def solve(ii):
    tmp = 0
    for _ in range(N):
        next = []
        for k, i in enumerate(ii):
            if i == 0:
                tmp += k
            else:
                next.append(i-1)
        ii = next[:]
    return tmp



# In[]:
ans = INF
for Acards in itertools.combinations(cards, (N+1)//2):
    Bcards = cards - set(Acards)

    Ais = sorted([(card[0], card[2]) for card in Acards])
    Bis = sorted([(card[1], card[2]) for card in Bcards])

    nums = []
    ii = []
    for i in range(N):
        if i%2 == 0:
            n,i = Ais[i//2]
        else:
            n,i = Bis[i//2]
        nums.append(n)
        ii.append(i)

    if nums != sorted(nums):
        continue
    else:
        ans = min(ans,solve(ii))
        if ans == 0:
          print((0))
          sys.exit()


if ans == INF:
    print((-1))
else:
    print(ans)