using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] boys = new long[n];
            if (n == 1)
                boys[0] = long.Parse(Console.ReadLine());
            else
            {
                string s = Console.ReadLine();
                int l = 0;
                int length = l + 1;
                for (long i = 0; i < boys.Length - 1; i++)
                {
                    while (s[length] != ' ')
                        length++;
                    boys[i] = long.Parse(s.Substring(l, length - l));
                    l = length;
                    length++;
                }
                boys[n - 1] = long.Parse(s.Substring(length));
            }
            long m = long.Parse(Console.ReadLine());
            long[] girls = new long[m];
            if (m == 1)
                girls[0] = long.Parse(Console.ReadLine());
            else
            {
                string s = Console.ReadLine();
                int l = 0;
                int length = l + 1;
                for (long i = 0; i < girls.Length - 1; i++)
                {
                    while (s[length] != ' ')
                        length++;
                    girls[i] = long.Parse(s.Substring(l, length - l));
                    l = length;
                    length++;
                }
                girls[m - 1] = long.Parse(s.Substring(length));
            }
            Array.Sort(boys);
            Array.Sort(girls);
            if (boys[boys.Length - 1] < girls[0]-1 || girls[girls.Length - 1] < boys[0]-1)
            {
                Console.WriteLine("0");
                return;
            }
            long count = 0;
            for (long i = 0; i < boys.Length; i++)
            {
                for (long j = 0; j < girls.Length; j++)
                {
                    if (girls[j] != 0)
                    {
                        if (boys[i] - girls[j] < 2 && boys[i] - girls[j] > -2)
                        {
                            girls[j] = 0;
                            count++;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            long[] boys = new long[n];
            if (n == 1)
                boys[0] = long.Parse(Console.ReadLine());
            else
            {
                string s = Console.ReadLine();
                int l = 0;
                int length = l + 1;
                for (long i = 0; i < boys.Length - 1; i++)
                {
                    while (s[length] != ' ')
                        length++;
                    boys[i] = long.Parse(s.Substring(l, length - l));
                    l = length;
                    length++;
                }
                boys[n - 1] = long.Parse(s.Substring(length));
            }
            long m = long.Parse(Console.ReadLine());
            long[] girls = new long[m];
            if (m == 1)
                girls[0] = long.Parse(Console.ReadLine());
            else
            {
                string s = Console.ReadLine();
                int l = 0;
                int length = l + 1;
                for (long i = 0; i < girls.Length - 1; i++)
                {
                    while (s[length] != ' ')
                        length++;
                    girls[i] = long.Parse(s.Substring(l, length - l));
                    l = length;
                    length++;
                }
                girls[m - 1] = long.Parse(s.Substring(length));
            }
            Array.Sort(boys);
            Array.Sort(girls);
            if (boys[boys.Length - 1] < girls[0] || girls[girls.Length - 1] < boys[0])
            {
                Console.WriteLine("0");
                return;
            }
            long count = 0;
            for (long i = 0; i < boys.Length; i++)
            {
                for (long j = 0; j < girls.Length; j++)
                {
                    if (girls[j] != 0)
                    {
                        if (boys[i] - girls[j] < 2 && boys[i] - girls[j] > -2)
                        {
                            girls[j] = 0;
                            count++;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();  //taking no of boys
        int b = int.Parse(s);

        int[] arrb = new int[b];
        string[] s1 = Console.ReadLine().Split(' ');
        for (int i = 0; i < b; i++) arrb[i] = int.Parse(s1[i]); //Initializing boys array

        s = Console.ReadLine();     //taking no of girls
        int g = int.Parse(s);

        int[] arrg = new int[g];
        s1 = Console.ReadLine().Split(' ');
        for (int i = 0; i < g; i++) arrg[i] = int.Parse(s1[i]); //Initializing girls array

        /* * */
        int counter = 0;
        Array.Sort(arrb);   Array.Sort(arrg);

        for (int i=0;i<b;i++)
        {
            for (int j=0;j<g;j++)
            {
                if (arrb[i] != -1 && arrg[j] != -1)
                {
                    if (Math.Abs(arrb[i] - arrg[j]) <=1) { arrb[i] = -1; arrg[j] = -1; counter++; break; }
                }
            }
        }

        Console.WriteLine(counter);
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();  //taking no of boys
        int b = int.Parse(s);

        int[] arrb = new int[b];
        string[] s1 = Console.ReadLine().Split(' ');
        for (int i = 0; i < b; i++) arrb[i] = int.Parse(s1[i]); //Initializing boys array

        s = Console.ReadLine();     //taking no of girls
        int g = int.Parse(s);

        int[] arrg = new int[g];
        s1 = Console.ReadLine().Split(' ');
        for (int i = 0; i < g; i++) arrg[i] = int.Parse(s1[i]); //Initializing girls array

        int counter = 0;

        for (int i=0;i<b;i++)
        {
            int index = -1;
            bool right = true;
            for (int j=0;j<g;j++)
            {
                if (arrb[i] != -1 && arrg[j] != -1)
                {
                    if (Math.Abs(arrb[i] - arrg[j]) == 0) { arrb[i] = -1; arrg[j] = -1; counter++; right = false; }
                    else if (Math.Abs(arrb[i]-arrg[j])==1) { index = j;}
                }
            }
            if (right == true && index!=-1) { arrb[i] = -1; arrg[index] = -1;counter++; }
        }

        Console.WriteLine(counter);
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();  //taking no of boys
        int b = int.Parse(s);

        int[] arrb = new int[b];
        string[] s1 = Console.ReadLine().Split(' ');
        for (int i = 0; i < b; i++) arrb[i] = int.Parse(s1[i]); //Initializing boys array

        s = Console.ReadLine();     //taking no of girls
        int g = int.Parse(s);

        int[] arrg = new int[g];
        s1 = Console.ReadLine().Split(' ');
        for (int i = 0; i < g; i++) arrg[i] = int.Parse(s1[i]); //Initializing girls array

        int counter = 0;

        for (int i=0;i<b;i++)
        {
            for (int j=0;j<g;j++)
            {
                if (arrb[i] != -1 && arrg[j] != -1)
                { if (Math.Abs(arrb[i] - arrg[j]) <= 1) { arrb[i] = -1; arrg[j] = -1; counter++; } }
            }
        }

        Console.WriteLine(counter);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static void Main(string[] args)
        {
            int n_boy = int.Parse(Console.ReadLine());
            string boys = Console.ReadLine();
            string[] boy_arr = boys.Split(' ');
            int m_girl = int.Parse(Console.ReadLine());
            string girls = Console.ReadLine();
            string[] girl_arr = girls.Split(' ');
            //----------------------------------------
            Array.Sort(boy_arr); Array.Sort(girl_arr);
            //----------------------------------------
            int point1 =0, point2 = 0, counter = 0;
            while (point1<n_boy && point2< m_girl)
            {
                if (Math.Abs(int.Parse(boy_arr[point1]) - int.Parse(girl_arr[point2])) <= 1) { point2++; point1++; counter++; }
                else if (int.Parse(boy_arr[point1]) < int.Parse(girl_arr[point2])) point1++;
                else point2++;
            }
            Console.Write(counter);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static void Main(string[] args)
        {
            int n_boy = int.Parse(Console.ReadLine());
            string boys = Console.ReadLine();
            string[] boy_arr = boys.Split(' ');
            int m_girl = int.Parse(Console.ReadLine());
            string girls = Console.ReadLine();
            string[] girl_arr = girls.Split(' ');
            //----------------------------------------
            if (girl_arr.Length == 1 && boy_arr.Length > 1)
            {
                for (int i = 0; i < n_boy; i++)
                    if ((int.Parse(boy_arr[i]) == int.Parse(girl_arr[0]) + 1) || (int.Parse(boy_arr[i]) == int.Parse(girl_arr[0]) - 1)) { Console.Write(1); Environment.Exit(0); }
            }
            if (boy_arr.Length == 1 && girl_arr.Length > 1)
            {
                for (int i = 0; i < m_girl; i++)
                    if ((int.Parse(girl_arr[i]) == int.Parse(boy_arr[0]) + 1) || (int.Parse(girl_arr[i]) == int.Parse(boy_arr[0]) - 1)) { Console.Write(1); Environment.Exit(0); }
            }
            //----------------------------------------
            int[] b = new int[n_boy];
            int[] g = new int[m_girl];
            for (int i = 0; i < n_boy; i++)
                b[i] = int.Parse(boy_arr[i]);
            for (int i = 0; i < m_girl; i++)
                g[i] = int.Parse(girl_arr[i]);
            Array.Sort(b);
            Array.Sort(g);
            //----------------------------------------
            int point1 = 0, point2 = 0, counter = 0;
            while (point1 < n_boy && point2 < m_girl)
            {
                if (Math.Abs(b[point1] - g[point2]) <= 1) { point2++; point1++; counter++; }
                else if (b[point1] < g[point2]) point1++;
                else point2++;
            }
            Console.Write(counter);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static void Main(string[] args)
        {
            int n_boy = int.Parse(Console.ReadLine());
            string boys = Console.ReadLine();
            string[] boy_arr = boys.Split(' ');
            int m_girl = int.Parse(Console.ReadLine());
            string girls = Console.ReadLine();
            string[] girl_arr = girls.Split(' ');
            //----------------------------------------
            if (girl_arr.Length == 1 && boy_arr.Length > 1)
            {
                for (int i = 0; i < n_boy; i++)
                {
                    if ((int.Parse(boy_arr[i]) == int.Parse(girl_arr[0]) + 1) || (int.Parse(boy_arr[i]) == int.Parse(girl_arr[0]) - 1))
                    { Console.Write(1); Environment.Exit(0); }
                }
            }
            if (boy_arr.Length == 1 && girl_arr.Length > 1)
            {
                for (int i = 0; i < m_girl; i++)
                {
                    if ((int.Parse(girl_arr[i]) == int.Parse(boy_arr[0]) + 1) || (int.Parse(girl_arr[i]) == int.Parse(boy_arr[0]) - 1))
                    { Console.Write(1); Environment.Exit(0); }
                }
            }
            //----------------------------------------
            Array.Sort(boy_arr); Array.Sort(girl_arr);
            //----------------------------------------
            int point1 = 0, point2 = 0, counter = 0;
            while (point1 < n_boy && point2 < m_girl)
            {
                if (Math.Abs(int.Parse(boy_arr[point1]) - int.Parse(girl_arr[point2])) <= 1) { point2++; point1++; counter++; }
                else if (int.Parse(boy_arr[point1]) < int.Parse(girl_arr[point2])) point1++;
                else point2++;
            }
            Console.Write(counter);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static void Main(string[] args)
        {
            int n_boy = int.Parse(Console.ReadLine());
            string boys = Console.ReadLine();
            string[] boy_arr = boys.Split(' ');
            int m_girl = int.Parse(Console.ReadLine());
            string girls = Console.ReadLine();
            string[] girl_arr = girls.Split(' ');
            //----------------------------------------
            if (girl_arr.Length == 1)
            {
                for (int i = 0; i < n_boy; i++)
                {
                    if ((int.Parse(boy_arr[i]) == int.Parse(girl_arr[0]) + 1) || (int.Parse(boy_arr[i]) == int.Parse(girl_arr[0]) - 1))
                    { Console.Write(1); break; }
                }
            }
            else if (boy_arr.Length == 1)
            {
                for (int i = 0; i < m_girl; i++)
                {
                    if ((int.Parse(girl_arr[i]) == int.Parse(boy_arr[0]) + 1) || (int.Parse(girl_arr[i]) == int.Parse(boy_arr[0]) - 1))
                    { Console.Write(1); break; }
                }
            }
            else
            {
                //----------------------------------------
                Array.Sort(boy_arr); Array.Sort(girl_arr);
                //----------------------------------------
                int point1 = 0, point2 = 0, counter = 0;
                while (point1 < n_boy && point2 < m_girl)
                {
                    if (Math.Abs(int.Parse(boy_arr[point1]) - int.Parse(girl_arr[point2])) <= 1) { point2++; point1++; counter++; }
                    else if (int.Parse(boy_arr[point1]) < int.Parse(girl_arr[point2])) point1++;
                    else point2++;
                }
                Console.Write(counter);
            }
        }
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        if (n < m)
        {
            foreach (var item in a)
            {
                //var p = b.FirstOrDefault(s => s == item || s == item + 1 || s == item - 1);
                var p = b.FirstOrDefault(s => s == item);
                if (p != default(int))
                {
                    ans++;
                    b[Array.IndexOf(b, p)] = -2;
                }
            }
        }
        else
        {
            foreach (var item in b)
            {
                //var p = a.FirstOrDefault(s => s == item || s == item + 1 || s == item - 1);
                var p = a.FirstOrDefault(s => s == item);
                if (p != default(int))
                {
                    ans++;
                    a[Array.IndexOf(a, p)] = -2;
                }
            }
        }
        if (n < m)
        {
            foreach (var item in a)
            {
                var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
                if (p != default(int))
                {
                    ans++;
                    b[Array.IndexOf(b, p)] = -2;
                }
            }
        }
        else
        {
            foreach (var item in b)
            {
                var p = a.FirstOrDefault(s => s == item + 1 || s == item - 1);
                if (p != default(int))
                {
                    ans++;
                    a[Array.IndexOf(a, p)] = -2;
                }
            }
        }

        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(d => d).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(d => d).ToArray();
        int ans = 0;
        var min = a.Length < b.Length ? a : b;
        var max = a.Length > b.Length ? a : b;
        foreach (var item in min)
        {
            var p = max.FirstOrDefault(s => s == item || s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                max[Array.IndexOf(max, p)] = -100;
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        if (n < m)
        {
            foreach (var item in a)
            {
                var p = b.FirstOrDefault(s => s == item);
                if (p != default(int))
                {
                    ans++;
                    b[Array.IndexOf(b, p)] = -2;
                    a[Array.IndexOf(a, item)] = -3;
                }
            }
        }
        else
        {
            foreach (var item in b)
            {
                var p = a.FirstOrDefault(s => s == item);
                if (p != default(int))
                {
                    ans++;
                    a[Array.IndexOf(a, p)] = -2;
                    b[Array.IndexOf(b, item)] = -3;
                }
            }
        }
        if (n < m)
        {
            foreach (var item in a.Where(d => d > 0))
            {
                var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
                if (p != default(int))
                {
                    ans++;
                    b[Array.IndexOf(b, p)] = -2;
                }
            }
        }
        else
        {
            foreach (var item in b.Where(d => d > 0))
            {
                var p = a.FirstOrDefault(s => s == item + 1 || s == item - 1);
                if (p != default(int))
                {
                    ans++;
                    a[Array.IndexOf(a, p)] = -2;
                }
            }
        }

        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        if (n < m)
        {
            foreach (var item in a)
            {
                var p = b.FirstOrDefault(s => s == item || s == item + 1 || s == item - 1);
                if (p != default(int))
                {
                    ans++;
                    b[Array.IndexOf(b, p)] = -2;
                }
            }
        }
        else
        {
            foreach (var item in b)
            {
                var p = a.FirstOrDefault(s => s == item || s == item + 1 || s == item - 1);
                if (p != default(int))
                {
                    ans++;
                    a[Array.IndexOf(a, p)] = -2;
                }
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(d => d).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).OrderBy(d => d).ToArray();
        int ans = 0;
        foreach (var item in a)
        {
            var p = b.FirstOrDefault(s => s == item);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
                a[Array.IndexOf(a, item)] = -3;
            }
        }
        foreach (var item in a.Where(d => d > 0))
        {
            var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(d => d).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).OrderBy(d => d).ToArray();
        int ans = 0;
        foreach (var item in a.Where(d => d > 0))
        {
            var p = b.FirstOrDefault(s => s == item);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
                a[Array.IndexOf(a, item)] = -3;
            }
        }
        foreach (var item in a.Where(d => d > 0))
        {
            var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
                a[Array.IndexOf(a, item)] = -3;
            }
        }
        //////////////////////////////////////////////////////////////////////
        foreach (var item in b.Where(d => d > 0))
        {
            var p = a.FirstOrDefault(s => s == item);
            if (p != default(int))
            {
                ans++;
                a[Array.IndexOf(b, p)] = -2;
                b[Array.IndexOf(a, item)] = -3;
            }
        }
        foreach (var item in b.Where(d => d > 0))
        {
            var p = a.FirstOrDefault(s => s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                a[Array.IndexOf(b, p)] = -2;
                b[Array.IndexOf(a, item)] = -3;
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        if (n < m)
        {
            foreach (var item in a)
            {
                var p = b.FirstOrDefault(s => s == item);
                if (p != default(int))
                {
                    ans++;
                    b[Array.IndexOf(b, p)] = -2;
                    a[Array.IndexOf(a, item)] = -3;
                }
            }
        }
        else
        {
            foreach (var item in b)
            {
                var p = a.FirstOrDefault(s => s == item);
                if (p != default(int))
                {
                    ans++;
                    a[Array.IndexOf(a, p)] = -2;
                    b[Array.IndexOf(b, item)] = -3;

                }
            }
            if (n < m)
            {
                foreach (var item in a.Where(d => d > 0))
                {
                    var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
                    if (p != default(int))
                    {
                        ans++;
                        b[Array.IndexOf(b, p)] = -2;
                    }
                }
            }
            else
            {
                foreach (var item in b.Where(d => d > 0))
                {
                    var p = a.FirstOrDefault(s => s == item + 1 || s == item - 1);
                    if (p != default(int))
                    {
                        ans++;
                        a[Array.IndexOf(a, p)] = -2;
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        foreach (var item in a)
        {
            var p = b.FirstOrDefault(s => s == item);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
                a[Array.IndexOf(a, item)] = -3;
            }
        }
        foreach (var item in a.Where(d => d > 0))
        {
            var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(d => d).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(d => d).ToArray();
        int ans = 0;
        var min = a.Length <= b.Length ? a : b;
        var max = a.Length > b.Length ? a : b;
        foreach (var item in min)
        {
            var p = max.FirstOrDefault(s => s == item ||   s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                max[Array.IndexOf(max, p)] = -100;
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(d => d).ToArray();
        var m = int.Parse(Console.ReadLine());
        var b = Console.ReadLine().Split().Select(int.Parse).OrderBy(d => d).ToArray();
        int ans = 0;
        foreach (var item in a)
        {
            var p = b.FirstOrDefault(s => s == item);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
                a[Array.IndexOf(a, item)] = -3;
            }
        }
        foreach (var item in a.Where(d => d > 0))
        {
            var p = b.FirstOrDefault(s => s == item + 1 || s == item - 1);
            if (p != default(int))
            {
                ans++;
                b[Array.IndexOf(b, p)] = -2;
                a[Array.IndexOf(a, item)] = -3;
            }
        }
        Console.WriteLine(ans);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int m = int.Parse(Console.ReadLine());
            int[] g = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int u = 0;
            Array.Sort(b);
            Array.Sort(g);
            for (int i = 0; i <b.Length ; i++)
            {
                for (int j = 0; j < g.Length; j++)
                {
                    if (Math.Abs(b[i]-g[j])<=1)
                    {
                        u++;
                        g[j]=103;
                        break;

                    }
                }

            }
            Console.WriteLine(u);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp10
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int m = int.Parse(Console.ReadLine());
            int[] g = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int u = 0;
            Array.Sort(b);
            Array.Sort(g);
            for (int i = 0; i <b.Length ; i++)
            {
                for (int j = 0; j < g.Length; j++)
                {
                    if (Math.Abs(b[i]-g[j])<=1)
                    {
                        u++;
                        g[j]=101;
                        break;

                    }
                }

            }
            Console.WriteLine(u);
        }
    }
}


using System;
class x
{
	static void Main()
	{
		var n1    = int.Parse(Console.ReadLine());
		var boys  = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		var n2    = int.Parse(Console.ReadLine());
		var girls = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		Array.Sort(boys);
		Array.Sort(girls);
		var count =0;
        for (var i=0;i<n1;i++)
        {
            for (var j=0;j<n2;j++)
            {
                if (Math.Abs(girls[j] - boys[i]) <= 1) { count++; girls[j] = -1; break; }
            }
        }
		Console.Write(count);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        public static void Main()
        {
            var men_count = GetInts(1).ElementAt(0);
            var men = GetInts(men_count).OrderBy(x => x).ToArray();

            var women_count = GetInts(1).ElementAt(0);
            var women = GetInts(women_count).OrderBy(x => x).ToArray();

            var pairs = 0;

            for (int man_itt = 0, woman_itt = 0; man_itt < men_count && woman_itt < women_count;)
            {
                var diff = men[man_itt] - women[woman_itt];
                if (diff > 1)
                {
                    woman_itt++;
                }
                else if (diff < -1)
                {
                    man_itt++;
                }
                else
                {
                    pairs++;
                    man_itt++;
                    woman_itt++;
                }
            }

            Console.Write(pairs);
        }

        static IEnumerable<int> GetInts(int count)
        {
            Stack<int> stack = new Stack<int>();

            for (int i = 0; i < count; i++)
            {
                char ch = (char)Console.Read();
                while (!char.IsDigit(ch))
                {
                    ch = (char)Console.Read();
                }

                while (char.IsDigit(ch))
                {
                    stack.Push((int)char.GetNumericValue(ch));
                    ch = (char)Console.Read();
                }

                int current = 0;
                for (int rank = 1; stack.Count > 0; rank *= 10)
                {
                    current += rank * stack.Pop();
                }

                yield return current;
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace My
{
    class Program
    {
        public static void Main(string[] args)
        {
            int boys = int.Parse(Console.ReadLine());
            int[] boysval = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int girls = int.Parse(Console.ReadLine());
            int[] girlsval = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Array.Sort(boysval);
            Array.Sort(girlsval);
            int cnt = 0;
            int i = 0, j = 0;
            while(i<boysval.Length&&j<girlsval.Length)
            {
                if (Math.Abs(boysval[i] - girlsval[ j]) < 2)
                {
                    cnt++;
                    i++; j++;
                }
                else if (boysval[ i] - girlsval[j] > 1)
                    j++;
                else
                    i++;
            }
            Console.WriteLine(cnt);
            //Console.ReadKey();
        }

    }
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;

namespace codeforces
{
	class Program
	{
		public class User
		{
			public int c;

			public int r;
		}

		public class Comparer : IComparer<User>
		{
			public int Compare(User x, User y)
			{
				if (x.c < y.c)
					return -1;
				return 1;
			}
		}

		public static long getGcd(long a, long b)
		{
			if (b == 0)
				return a;
			return getGcd(b, a % b);
		}

		public static void WriteYESNO(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string GetString()
		{
			return Console.ReadLine();
		}

		public static List<int> getList()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static int Min(int x, int y)
		{
			return Math.Min(x, y);
		}

		public static int Max(int x, int y)
		{
			return Math.Max(x, y);
		}

		public static int Abs(int x)
		{
			return Math.Abs(x);
		}

		public static int getInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static bool Equal(int x, int y, int x1, int y1)
		{
			return x == x1 && y == y1;
		}

		public class Vertex
		{
			public List<int> edges;

			public int ct;

			public Vertex()
			{
				ct = 0;
				edges = new List<int>();
				for (var i = 0; i < 26; ++i)
					edges.Add(0);
			}
		}

		private static void Main(string[] args)
		{
/*			var input = new StreamReader("input.txt");
			var output = new StreamWriter("output.txt");*/
			var n = getInt();
			var l1 = getList();
			l1.Sort();
			var m = getInt();
			var l2 = getList();
			l2.Sort();
			var ans = new List<List<int>>();
			for (var i = 0; i <= n; ++i)
			{
				ans.Add(new List<int>());
				for (var j = 0; j <= m; ++j)
					ans[i].Add(0);
			}
			for (var i = 1; i <= n; ++i)
			{
				for (var j = 1; j <= m; ++j)
				{
					ans[i][j] = ans[i][j - 1];
					for (var q = 1; q <= i; ++q)
					{
						if (Abs(l2[j - 1] - l1[q - 1]) <= 1 && ans[i][j] < ans[q - 1][j - 1] + 1)
						{
							ans[i][j] = ans[q - 1][j - 1] + 1;
						}
					}
				}
			}
			Console.WriteLine(ans[n][m]);
			/*			input.Close();
			output.Close();*/
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace Igranje.CF277_5
{
    class ProblemB
    {
        public static void Main(string[] varg)
        {

            int n = int.Parse(Console.ReadLine());

            int [] a = new int[n];

            string[] tboys = Console.ReadLine().Split(new char[] {' '});
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(tboys[i]);
            int m = int.Parse(Console.ReadLine());
            int[] b = new int[m];
            string[] tgirls = Console.ReadLine().Split(new char[] {' '});
            for (int i = 0; i < m; i++)
                b[i] = int.Parse(tgirls[i]);

            Array.Sort(a);
            Array.Sort(b);

            int iA = 0;
            int iB = 0;
            int rv = 0;
            for (int i = 1; i <205; i++)
            {
                if (iA >= n) break;
                if (iB >= m) break;
                int boy = a[iA];
                int girl = b[iB];
                if (Math.Abs(boy - girl) < 2)
                {
                    rv++;
                    iA++;
                    iB++;
                }
                else
                {
                    if (boy > girl)
                    {
                        iB++;
                    }
                    else
                    {
                        iA++;
                    }
                }
            }
            System.Console.WriteLine(rv);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace Igranje.CF277_5
{
    class ProblemB
    {
        public static void Main(string[] varg)
        {

            int n = int.Parse(Console.ReadLine());

            int [] a = new int[n];

            string[] tboys = Console.ReadLine().Split(new char[] {' '});
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(tboys[i]);
            int m = int.Parse(Console.ReadLine());
            int[] b = new int[m];
            string[] tgirls = Console.ReadLine().Split(new char[] {' '});
            for (int i = 0; i < m; i++)
                b[i] = int.Parse(tgirls[i]);

            Array.Sort(a);
            Array.Sort(b);

            int iA = 0;
            int iB = 0;
            int rv = 0;
            for (int i = 1; i < 105; i++)
            {
                if (iA >= n) break;
                if (iB >= m) break;
                int boy = a[iA];
                int girl = b[iB];
                if (Math.Abs(boy - girl) < 2)
                {
                    rv++;
                    iA++;
                    iB++;
                }
                else
                {
                    if (boy > girl)
                    {
                        iB++;
                    }
                    else
                    {
                        iA++;
                    }
                }
            }
            System.Console.WriteLine(rv);

        }
    }
}


using System;
using System.Linq;

namespace ConsoleApplication5
{
    class Program
    {
        private static int[][] f;
        private static int[] boys;
        private static int[] girls;
        private static int n, m;
        static void Main(string[] args)
        {
            n = int.Parse(Console.ReadLine());
            boys = Console.ReadLine().Split(' ').Select(item => int.Parse(item)).ToArray();
            m = int.Parse(Console.ReadLine());
            girls = Console.ReadLine().Split(' ').Select(item => int.Parse(item)).ToArray();
            f = new int[n][];
            Array.Sort(boys);
            Array.Sort(girls);
            for (int i = 0; i < n; i++)
            {
                f[i] = new int[m];
                for (int j = 0; j < m; j++)
                {
                    f[i][j] = -1;
                }
            }

            Console.WriteLine(F(0, 0));
        }

        public static int F(int i, int j)
        {
            if (i >= n || j >= m)
            {
                return 0;
            }

            if (f[i][j] != -1)
            {
                return f[i][j];
            }
            else
            {
                if (Math.Abs(boys[i] - girls[j]) <= 1)
                {
                    f[i][j] = F(i + 1, j + 1) + 1;
                }
                else
                {
                    f[i][j] = Math.Max(F(i, j + 1), F(i + 1, j));
                }
                return f[i][j];
            }
        }
    }
}


using System;
using System.Linq;

namespace _489B
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var s1 = Console.ReadLine().Split().Select(int.Parse).OrderBy(x=>x).ToArray();
            var m = int.Parse(Console.ReadLine());
            var s2 = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
            int count = 0;
            for (int i=0;i<n;i++)
            {
                for (int j=0;j<m;j++)
                {
                    if (Math.Abs(s2[j] - s1[i]) <= 1) { count++; s2[j] = -1; break; }
                }
            }
            Console.WriteLine(count);

        }
    }
}


import java.io.*
import java.util.*

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    companion object {
        fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))
    }

    var tok = StringTokenizer("")

    fun close() { rd.close(); wr.close() }
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun readToken(): String {
        while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())
        return tok.nextToken()
    }
    fun readInt() = readToken().toInt()
    fun readLong() = readToken().toLong()
    fun readLine() : String {
        tok = StringTokenizer("")
        return rd.readLine()
    }
}

fun main(args: Array<String>) {
    Thread({ val io = ProblemIO.console(); solve(io) ; io.close() }).start()
}

fun solve(io: ProblemIO) {
    val a = IntArray(101)
    val b = IntArray(101)
    val n = io.readInt()
    for (i in 1 .. n) {
        val v = io.readInt()
        ++a[v]
    }
    val m = io.readInt()
    for (i in 1 .. m) {
        val v = io.readInt()
        ++b[v]
    }
    var res = 0
    for (i in a.indices) {
        for (d in -1 .. 1) {
            if (i + d >= 0 && i + d <= a.lastIndex && a[i] > 0 && b[i + d] > 0) {
                val v = Math.min(a[i], b[i + d])
                res += v
                a[i] -= v
                b[i + d] -= v
            }
        }
    }
    io.println(res)
}


fun main()
{
    val nb_boys = readLine()!!.toInt()
    val boys = readLine()!!.split(" ").map{it.toInt()}.sorted().toMutableList()
    val nb_girl = readLine()!!.toInt()
    val girl = readLine()!!.split(" ").map{it.toInt()}.sorted().toMutableList()
    var pairs = 0
    for (b in 0..nb_boys - 1)
    {
        for (g in 0..nb_girl - 1)
        {
            val diff = boys[b] - girl[g]
            if (diff == 0 || diff == 1 || diff == -1) {
                pairs++
                girl[g] = 200
                break
            }

        }
    }
    println(pairs)

}


import kotlin.math.abs

// -48
fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val b = r.readLine()!!.toInt()
    val bv = r.readLine()!!.split(" ").map { it.toInt() }.sorted()
    val g = r.readLine()!!.toInt()
    val gv = r.readLine()!!.split(" ").map { it.toInt() }.sorted()
    var bi = 0
    var gi = 0
    var pair = 0
    while (bi < b && gi < g) {
        when{
            abs(bv[bi]-gv[gi])<=1 -> {
                bi++
                gi++
                pair++
            }
            bv[bi] < gv[gi] -> bi++
            else ->gi++
        }
    }
    println(pair)
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val b = r.readLine()!!.toInt()
    val bv = r.readLine()!!.split(" ").map { it.toInt() }.sorted()
    val g = r.readLine()!!.toInt()
    val gv = r.readLine()!!.split(" ").map { it.toInt() }.sorted()
    var bi = 0
    var gi = 0
    var pair = 0
    while (bi < b && gi < g) {
        when{
            abs(bv[bi]-gv[gi])<=1 -> {
                bi++
                gi++
                pair++
            }
            bv[bi] < gv[gi] -> bi++
            else ->gi++
        }
    }
    println(pair)
}


import kotlin.math.*
fun main(args: Array<String>) {
    var n = int
    var a = arr
    var m = int
    var b = arr
    var mx = 0
    if (n > m) {
        n = m.also { m = n }
        a = b.also { b = a }
    }
    var temp = 0
    for (j in 0..(m - 1)) {
        temp = (0..(n - 1))
                .takeWhile { j + it != m }
                .filter { abs(b[j + it] - a[it]) <= 1 }
                .size
        mx = max(mx, temp)
    }
    print(mx)
}
val arr get() = readLine()!!.split(' ').map { it.toInt() }.sorted()
val int get() = readLine()!!.toInt()


class Solve(
        val n:Int = int,
        val a:MutableList<Int> = arr,
        val m:Int = int,
        val b:MutableList<Int> = arr){
    fun calculate(ad: Int): Int{
        var result = 0
        for (i in 0..(n - 1)) {
            if(a[i]==-5) continue
            for (j in 0..(m - 1)){
                if(a[i]==b[j]+ad) {
                    result++
                    b[j]=-5
                    a[i]=-5
                    break;
                }
            }
        }
        return result
    }
}
fun main(args: Array<String>) {
    val s: Solve = Solve()
    var mx = s.calculate(0)
    mx += s.calculate(1)
    mx += s.calculate(-1)
    print(mx)
}
val arr get() = readLine()!!.split(' ').map { it.toInt() }.toMutableList()
val int get() = readLine()!!.toInt()


class Solve(
        val n:Int = int,
        val a:MutableList<Int> = arr,
        val m:Int = int,
        val b:MutableList<Int> = arr){
    fun cal(ad: Int): Int{
        var result = 0
        for (i in 0..(n - 1)) {
            if(a[i]<0) continue
            for (j in 0..(m - 1)){
                if(a[i]==b[j]+ad) {
                    result++
                    b[j]*=-1
                    a[i]*=-1
                    break;
                }
            }
        }
        return result
    }
    fun restore(){
        (0..(n-1))
                .filter { a[it]<0 }
                .forEach { a[it]*=-1 }
        (0..(m-1))
                .filter { b[it]<0 }
                .forEach { b[it]*=-1 }
    }
}
fun main(args: Array<String>) {
    val s: Solve = Solve()
    var mx = 0
    mx = maxOf(mx, s.cal(0)+s.cal(1)+s.cal(-1))
    s.restore()
    mx = maxOf(mx, s.cal(0)+s.cal(-1)+s.cal(1))
    s.restore()
    mx = maxOf(mx, s.cal(1)+s.cal(0)+s.cal(-1))
    s.restore()
    mx = maxOf(mx, s.cal(1)+s.cal(-1)+s.cal(0))
    s.restore()
    mx = maxOf(mx, s.cal(-1)+s.cal(0)+s.cal(1))
    s.restore()
    mx = maxOf(mx, s.cal(-1)+s.cal(1)+s.cal(0))
    print(mx)
}
val arr get() = readLine()!!.split(' ').map { it.toInt() }.toMutableList()
val int get() = readLine()!!.toInt()


fun main(args: Array<String>) {
    val n = int
    val a = arr
    val m = int
    val b = arr
    var mx = 0
    for (i in 0..(n - 1)) {
        for (j in 0..(m - 1)){
            val t = a[i]-b[j];
            if(t==0||t==1||t==-1) {
                mx++
                b[j]=1234
                break;
            }
        }
    }
    print(mx)
}
val arr get() = readLine()!!.split(' ').map { it.toInt() }.sorted().toMutableList()
val int get() = readLine()!!.toInt()


fun main(args: Array<String>) {
    val n = int
    val a = arr
    val m = int
    val b = arr
    var mx = 0
    for (i in 0..(n - 1)) {
        for (j in 0..(m - 1)){
            val t = a[i]-b[j];
            if(t==0||t==1||t==-1) {
                mx++
                b[j]=1234
                break;
            }
        }
    }
    print(mx)
}
val arr get() = readLine()!!.split(' ').map { it.toInt() }.toMutableList()
val int get() = readLine()!!.toInt()


import kotlin.math.*
fun main(args: Array<String>) {
    var n = int
    var a = arr
    var m = int
    var b = arr
    var mx = 0
    if (n > m) {
        n = m.also { m = n }
        a = b.also { b = a }
    }
    m+=m
    b+=b
    var temp = 0
    for (j in 0..(m - 1)) {
        temp = (0..(n - 1))
                .takeWhile { j + it != m }
                .filter { abs(b[j + it] - a[it]) <= 1 }
                .size
        mx = max(mx, temp)
    }
    print(mx)
}
val arr get() = readLine()!!.split(' ').map { it.toInt() }.sorted()
val int get() = readLine()!!.toInt()


//package tasks.t489b

//import FunSeq.*
import kotlin.math.abs

val <T> Sequence<T>.head: T?
    get() = firstOrNull()

val <T> Sequence<T>.tail: Sequence<T>
    get() = drop(1)

fun countPairs(boys: Sequence<Int>, girls: Sequence<Int>): Int =
    if (boys.head == null || girls.head == null) 0
    else (girls.head!! - boys.head!!).let {
        when {
            abs(it) <= 1 -> 1 + countPairs(boys.tail, girls.tail)
            it < 0 -> countPairs(boys, girls.tail)
            else -> countPairs(boys.tail, girls)
        }
    }

fun main(args: Array<String>) {
    readLine()
    val boysLvl = readLine()!!
        .split(" ")
        .map { it.toInt() }
    readLine()
    val girlsLvl = readLine()!!
        .split(" ")
        .map { it.toInt() }
    val pairs = countPairs(boysLvl.sorted().asSequence(), girlsLvl.sorted().asSequence())
    println(pairs)
}


import kotlin.math.abs

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }.sorted()

    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }.sorted()

    var p = 0
    var i = 0
    var j = 0

    while (i < n && j < m) {
        if (abs(a[i] - b[j]) <= 1) {
            p++
            i++
            j++
        } else if (a[i] > b[j]) {
            j++
        } else {
            i++
        }
    }

    println(p)
}


import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.abs

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val boys = sort(br.readLine().split(" ").map { it.toInt() })
    val m = br.readLine().toInt()
    val girls = sort(br.readLine().split(" ").map { it.toInt() })

    val takenBoys = Array(n){x -> false}
    val takenGirls = Array(m){x -> false}

    var i = 0
    var j = 0
    var count = 0

    while (i < n && j < m){

        if (i == j){
            if (isValidPair(boys[i], girls[i]) && !takenBoys[i] && !takenGirls[i]){
                count ++
                takenBoys[i] = true
                takenGirls[i] = true
                i ++
                j ++
            }else{
                if (boys[i] < girls[i]) i ++
                else j ++
            }
        }else{
            if (isValidPair(boys[i], girls[j]) && !takenBoys[i] && !takenGirls[j]){
                takenBoys[i] = true
                takenGirls[j] = true
                count ++
                i ++
                j ++
            }else{
                if (i < j) j++
                else i ++
            }
        }

    }
    println(count)

}

fun isValidPair(x: Int, y: Int) = abs(x - y) <= 1

fun sort(xs: List<Int>): Array<Int>{
    val count = Array(110){x -> 0}
    for (x in xs){
        count[x] += 1
    }

    val sorted = Array(xs.size){x -> 0}

    var i = 0
    var j = 0

    while (i < count.size){
        while (count[i] > 0){
            sorted[j] = i
            count[i]--
            j++
        }
        i++
    }

    return sorted
}


import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.abs

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val boys = sort(br.readLine().split(" ").map { it.toInt() })
    val m = br.readLine().toInt()
    val girls = sort(br.readLine().split(" ").map { it.toInt() })

    val takenBoys = Array(n){x -> false}
    val takenGirls = Array(m){x -> false}

    var i = 0
    var j = 0
    var count = 0

    while (i < n && j < m){

        if (i == j){
            if (isValidPair(boys[i], girls[i]) && !takenBoys[i] && !takenGirls[i]){
                count ++
                takenBoys[i] = true
                takenGirls[i] = true
                i ++
                j ++
            }else{
                if (boys[i] < girls[i]) i ++
                else j ++
            }
        }else{
            if (isValidPair(boys[i], girls[j]) && !takenBoys[i] && !takenGirls[j]){
                takenBoys[i] = true
                takenGirls[j] = true
                count ++
                i ++
                j ++
            }else{
                if (i > j){
                    if (boys[i] > girls[j]) j++
                    else i++
                }
                else{
                    if (girls[j] > boys[i]) i++
                    else j++
                }
            }
        }

    }
    println(count)

}

fun isValidPair(x: Int, y: Int) = abs(x - y) <= 1

fun sort(xs: List<Int>): Array<Int>{
    val count = Array(110){x -> 0}
    for (x in xs){
        count[x] += 1
    }

    val sorted = Array(xs.size){x -> 0}

    var i = 0
    var j = 0

    while (i < count.size){
        while (count[i] > 0){
            sorted[j] = i
            count[i]--
            j++
        }
        i++
    }

    return sorted
}


//package codeforces.greedyAlgorithm

fun main() {
    val boysCount = readLine()!!.toInt()
    val boysDanceAbility = readLine()!!.split(" ").map { it.toInt() }
    val girlsCount = readLine()!!.toInt()
    val girlsDanceAbility = readLine()!!.split(" ").map { it.toInt() }

    println(getMaxPairCount(boysDanceAbility, girlsDanceAbility))
}

fun getMaxPairCount(boysDanceAbility: List<Int>, girlsDanceAbility: List<Int>): Int {
    val sortedBoys = boysDanceAbility.sorted().toMutableList()
    val sortedGirls = girlsDanceAbility.sorted().toMutableList()

    var boysStartIdx = 0
    var boysEndIdx = sortedBoys.lastIndex
    var girlsStartIdx = 0
    var girlsEndIdx = sortedGirls.lastIndex

    if (sortedBoys[0] > sortedGirls[0]) {
        while (girlsStartIdx < sortedGirls.size && sortedGirls[girlsStartIdx] < sortedBoys[0] - 1) {
            girlsStartIdx++
        }
    } else if (sortedBoys[0] < sortedGirls[0]) {
        while (boysStartIdx < sortedBoys.size && sortedBoys[boysStartIdx] < sortedGirls[0] - 1) {
            boysStartIdx++
        }
    }

    if (girlsStartIdx == sortedGirls.size || boysStartIdx == sortedBoys.size) return 0

    if (sortedBoys[boysEndIdx] > sortedGirls[girlsEndIdx]) {
        while (boysEndIdx >= boysStartIdx && sortedBoys[boysEndIdx] > sortedGirls[girlsEndIdx] + 1) {
            boysEndIdx--
        }
    } else if (sortedBoys[boysEndIdx] < sortedGirls[girlsEndIdx]) {
        while (girlsEndIdx >= girlsStartIdx && sortedGirls[girlsEndIdx] > sortedBoys[boysEndIdx] + 1) {
            girlsEndIdx--
        }
    }

    if (girlsEndIdx == -1 || boysEndIdx == -1) return 0

    var pairCount = 0
    while (boysStartIdx <= boysEndIdx && girlsStartIdx <= girlsEndIdx) {
        val isPair = sortedBoys[boysStartIdx] - 1 == sortedGirls[girlsStartIdx] ||
                sortedBoys[boysStartIdx] == sortedGirls[girlsStartIdx] ||
                sortedBoys[boysStartIdx] + 1 == sortedGirls[girlsStartIdx]

        when {
            isPair -> {
                pairCount++
                boysStartIdx++
                girlsStartIdx++
            }
            sortedBoys[boysStartIdx] < sortedGirls[girlsStartIdx] - 1 -> boysStartIdx++
            sortedGirls[girlsStartIdx] < sortedBoys[boysStartIdx] - 1 -> girlsStartIdx++
        }
    }

    return pairCount
}


import java.util.*
import kotlin.math.abs

fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    val n = nextInt()
    val men = IntArray(n, { nextInt() }).sortedArray()
    val m = nextInt()
    val women = IntArray(m, { nextInt() }).sortedArray()
    var res = 0
    men.forEach { c ->
        women.forEachIndexed { i, v ->
            if (abs(c - v) <= 1) {
                women[i] = 9999
                ++res
                return@forEach
            }
        }
    }
    print(res)
}


fun main() {
    readLine()
    var boys = readLine()!!.split(" ").map { s -> s.toInt() }
    readLine()
    var girls = readLine()!!.split(" ").map { s -> s.toInt() }
    boys = boys.sorted()
    girls = girls.sorted()
    var boysPos = 0
    var girlsPos = 0
    var numPairs = 0
    while (boysPos < boys.size && girlsPos < girls.size) {
        val diff = boys[boysPos] - girls[girlsPos]
        when {
            diff < -1 -> boysPos++
            diff > 1 -> girlsPos++
            else -> {
                numPairs++; boysPos++; girlsPos++
            }
        }
    }
    print(numPairs)
}


// 4/22/2020 7:56 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val boyHistogram = Array<Int>(102) {0} // one before for skill = 0, one after for lookahead not crashing things
    val girlHistogram = Array<Int>(102) {0}

    readInt() // nBoys
    val boySkill = readInts()
    boySkill.forEach{skill -> boyHistogram[skill]++}
    readInt() // nGirls
    val girlSkill = readInts()
    girlSkill.forEach{skill -> girlHistogram[skill]++}

    var nPairs = 0
    for (i in 1..100) {
        val equalMatches = minOf(boyHistogram[i], girlHistogram[i])
        nPairs += equalMatches
        boyHistogram[i] -= equalMatches
        girlHistogram[i]-= equalMatches

        val boyBetterMatches = minOf(boyHistogram[i+1], girlHistogram[i])
        nPairs += boyBetterMatches
        boyHistogram[i+1] -= boyBetterMatches
        girlHistogram[i] -= boyBetterMatches

        val girlBetterMatches = minOf(boyHistogram[i], girlHistogram[i+1])
        nPairs += girlBetterMatches
        boyHistogram[i] -= girlBetterMatches
        girlHistogram[i+1] -= girlBetterMatches
    }

    println(nPairs)
}


// 4/22/2020 7:56 AM

//package p489

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val boyHistogram = Array<Int>(101) {0}
    val girlHistogram = Array<Int>(101) {0}

    readInt() // nBoys
    val boySkill = readInts()
    boySkill.forEach{skill -> boyHistogram[skill]++}
    readInt() // nGirls
    val girlSkill = readInts()
    girlSkill.forEach{skill -> girlHistogram[skill]++}

    var nPairs = 0
    for (i in 1..99) {
        val equalMatches = minOf(boyHistogram[i], girlHistogram[i])
        nPairs += equalMatches
        boyHistogram[i] -= equalMatches
        girlHistogram[i]-= equalMatches

        val boyBetterMatches = minOf(boyHistogram[i+1], girlHistogram[i])
        nPairs += boyBetterMatches
        boyHistogram[i+1] -= boyBetterMatches
        girlHistogram[i] -= boyBetterMatches

        val girlBetterMatches = minOf(boyHistogram[i], girlHistogram[i+1])
        nPairs += girlBetterMatches
        boyHistogram[i] -= girlBetterMatches
        girlHistogram[i+1] -= girlBetterMatches
    }

    println(nPairs)
}


import kotlin.math.abs

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map(String::toInt).sorted()
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map(String::toInt).sorted()
    var i = 0
    var j = 0
    var result = 0
    while (i < n && j < m) {
        if (abs(a[i] - b[j]) <= 1) {
            result++
            i++
            j++
        } else if (a[i] > b[j]) {
            j++
        } else {
            i++
        }
    }
    println(result)
}


import kotlin.math.abs

fun main(args: Array<String>) {

    readLine()!!.toInt()

    val a = readLine()!!.split(" ").map { it.toInt() }.sorted()

    readLine()!!.toInt()

    val b = readLine()!!.split(" ").map { it.toInt() }.sorted()

    val min = if (a.size > b.size) b else a
    val max = (if (a == min) b else a).toMutableList()
    var count = 0

    for (i in 0 until min.size){
        for (j in 0 until max.size){
            if (abs(min[i] - max[j]) <= 1){
                max.removeAt(j)
                count++
                break
            }
        }
    }
    println(count)

}


import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.abs
import kotlin.math.sign

fun main(){
    var scanner = Scanner(System.`in`)
    var n = scanner.nextInt()
    var boys = ArrayList<Int>()
    for(i in 0 until n) boys.add(scanner.nextInt())
    var m = scanner.nextInt()
    var girls = ArrayList<Int>()
    for(i in 0 until m) girls.add(scanner.nextInt())
    var pairs:Int = 0
    for(i in 0 until boys.size){
        for(j in 0 until girls.size){
            if(abs(boys[i] - girls[j]) <= 1){
                boys[i] =-5
                girls[j] = -5
                n--
                pairs++
            }
        }
        if(n==0) break
    }
    println(pairs)
}


import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.abs
import kotlin.math.sign

fun main(){
    var scanner = Scanner(System.`in`)
    var n = scanner.nextInt()
    var boys = ArrayList<Int>()
    for(i in 0 until n) boys.add(scanner.nextInt())
    boys.sort()
    var m = scanner.nextInt()
    var girls = ArrayList<Int>()
    for(i in 0 until m) girls.add(scanner.nextInt())
    girls.sort()
    var pairs:Int = 0
    for(i in 0 until boys.size){
        for(j in 0 until girls.size){
            if(abs(boys[i] - girls[j]) <= 1){
                boys[i] =-5
                girls[j] = -15
                n--
                pairs++
            }
        }
        if(n==0) break
    }
    println(pairs)
}


import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.abs
import kotlin.math.sign

fun main(){
    var scanner = Scanner(System.`in`)
    var n = scanner.nextInt()
    var boys = ArrayList<Int>()
    for(i in 0 until n) boys.add(scanner.nextInt())
    boys.sorted()
    var m = scanner.nextInt()
    var girls = ArrayList<Int>()
    for(i in 0 until m) girls.add(scanner.nextInt())
    girls.sorted()
    var pairs:Int = 0
    for(i in 0 until boys.size){
        for(j in 0 until girls.size){
            if(abs(boys[i] - girls[j]) <= 1){
                boys[i] =-5
                girls[j] = -15
                n--
                pairs++
            }
        }
        if(n==0) break
    }
    println(pairs)
}


#include <cstdio>
#include <algorithm>
using namespace std;
int boy[1328];
int girl[1328];

int abs(int x){
    if(x>=0) return x;
    return -x;
}

int main(){
    int n, m;
    scanf("%d", &n);
    for(int i=0;i<n;i++) scanf("%d", &boy[i]);
    scanf("%d", &m);
    for(int i=0;i<m;i++) scanf("%d", &girl[i]);
    sort(boy, boy+n);
    sort(girl, girl+m);
    //
    int couple = 0;
    int N, M;
    N = 0;
    M = 0;
    while(N<n && M<m){
        int dif = abs(boy[N] - girl[M]);
        if(dif <= 1){
            couple++;
            N++;
            M++;
        }
        else{
            if(boy[N] < girl[M]) N++;
            else M++;
        }
    }
    printf("%d\n", couple);
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

int abs(int x){
	if(x < 0) return -x;
	return x;
}

int Boys, Girls;
int b[1000], g[1000];
int main(){
	scanf("%d", &Boys);
	for(int i=1;i<=Boys;i++){
		scanf("%d", &b[i]);
	}
	scanf("%d", &Girls);
	for(int i=1;i<=Girls;i++){
		scanf("%d", &g[i]);
	}
	sort(b+1, b+Boys+1);
	sort(g+1, g+Girls+1);
	int b_cnt = 1;
	int g_cnt = 1;
	int res = 0;
	while(b_cnt<=Boys && g_cnt<=Girls){
		int diff = abs(b[b_cnt] - g[g_cnt]);
		if(diff <= 1){
			//printf("%d %d\n", b[b_cnt], g[g_cnt]);
			res ++;
			b_cnt++;
			g_cnt++;
		}
		else if(b[b_cnt] < g[g_cnt]) b_cnt++;
		else g_cnt++;
	}
	printf("%d\n", res);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
int boy[1328];
int girl[1328];

int main(){
    int n, m;
    scanf("%d", &n);
    for(int i=0;i<n;i++) scanf("%d", &boy[i]);
    scanf("%d", &m);
    for(int i=0;i<n;i++) scanf("%d", &girl[i]);
    sort(boy, boy+n);
    sort(girl, girl+n);
    //
    int couple = 0;
    int N, M; //N-->男
    N = 0;
    M = 0;
    while(N<n && M<m){
        int dif = abs(boy[N] - girl[M]);
        if(dif <= 1){
            couple++;
            N++;
            M++;
        }
        else{
            if(boy[N] < girl[M]) N++;
            else M++;
        }
    }
    printf("%d\n", couple);
    return 0;
}


#include <bits/stdc++.h>

#define vi vector<int>
#define pb push_back
#define si set<int>
#define pii pair<int, int>
#define mp make_pair

#define foreach(it, tem) for(auto it : tem)
#define rep3(i, st, n, step) \
for(__typeof(st) i = (st); i < (n); i += step)
#define rep2(i, st, n) rep3(i, st, n, 1)
#define rep(i, n) rep2(i, 0, n)

#ifdef DEBUG
#define watch(i) cerr << #i << " = " << i << endl
#else
#define watch(i)
#endif // DEBUG

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LF;
typedef double DB;

int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n;
	int *b = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	sort(b, b + n);
	cin >> m;
	int *g = new int[m];
	for (int i = 0; i < m; i++)
	{
		cin >> g[i];
	}
	sort(g, g + m);
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (abs(b[i] - g[j]) <= 1)
			{
				g[j] = 100000;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define vi vector<int>
#define pb push_back
#define si set<int>
#define pii pair<int, int>
#define mp make_pair

#define foreach(it, tem) for(auto it : tem)
#define rep3(i, st, n, step) \
for(__typeof(st) i = (st); i < (n); i += step)
#define rep2(i, st, n) rep3(i, st, n, 1)
#define rep(i, n) rep2(i, 0, n)

#ifdef DEBUG
#define watch(i) cerr << #i << " = " << i << endl
#else
#define watch(i)
#endif // DEBUG

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LF;
typedef double DB;

int main()
{
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n;
	int *b = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	sort(b, b + n);
	cin >> m;
	int *g = new int[m];
	for (int i = 0; i < m; i++)
	{
		cin >> g[i];
	}
	sort(g, g + n);
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (abs(b[i] - g[j]) <= 1)
			{
				g[j] = -1000000;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int c[105], d[105], ans;

int main()
{
	int n; cin >> n; int a[n+1]; for(int i = 1; i <= n; i++) cin >> a[i];

	int m; cin >> m; int b[m+1]; for(int i = 1; i <= m; i++) cin >> b[i];

	for(int i = 1; i <= 100; i++)

	for(int j = 1; j <= n; j++)
		{
			if(!c[j] and a[j] == i)

			{

				c[j] = 1;
				for(int k = 1; k <= m; k++)
				if(!d[k] and i-1 <= b[k] and i+1 >= b[k])
				{
					d[k] = 1; ans++; break;
					}

				}

			}

		cout << ans;
		return 0;

	}


#include <bits/stdc++.h>

using namespace std;

int c[105], d[105], ans;

int main()
{
	int n; cin >> n; int a[n+1]; for(int i = 1; i <= n; i++) cin >> a[i];

	int m; cin >> m; int b[m+1]; for(int i = 1; i <= m; i++) cin >> b[i];

	for(int i = 1; i <= 100; i++)

	for(int j = 1; j <= n; j++)
		{
			if(!c[j] and a[j] == i)

			{

				for(int t = i-1; t <= i+1; t++)
				for(int k = 1; k <= m; k++)
				if(!d[k] and !c[j] and b[k] == t)
				{
					c[j] = 1; d[k] = 1; ans++; break;
					}

				}

			}

		cout << ans;
		return 0;

	}


/**/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define FOR(i, begin, end) for(__typeof(end) i = (begin); i < (end); i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted. O.o
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 */
const ll mod = 1000000009;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int b,g;
    V<int> bb,gg;
    cin>>b;
    while(b--){cin>>g;bb.pb(g);}
    cin>>g;
    while(g--){cin>>b;gg.pb(b);}
    sort(all(bb));
    sort(all(gg));
    int res = 0;
    int j = 0;
    For(i,0,bb.size()){
        if(j==(int)gg.size())break;
        for(;j<(int)gg.size();j++){
            if(abs(gg[j]-bb[i])<=1){res++;j++;break;}
            else if(bb[i]<gg[j]+1) break;
        }
    }
    cout<<res<<endl;
    return 0;
}
/**/


/*kee template*/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * Here's my safety pig, I hope my code compile and get accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
V<V<int> > graph;
V<int> match;
bool bpg(int u,V<bool> visited){
    For(i,0,graph[u].size()){
        if(!visited[graph[u][i]]){
            visited[graph[u][i]] = true;
            if(match[graph[u][i]] == -1){
                match[i] = u;
                return true;
            }else if (bpg(match[graph[u][i]],visited)){
                match[i] = u;
                return true;
            }
        }
    }
    return false;
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,cur,res = 0;
    V<int> b,g;
    cin>>n;
    V<int> emp(0);
    graph = V<V<int> >(n,emp);
    while(n--){
        cin>>cur;
        b.pb(cur);
    }
    cin>>n;
    while(n--){
        cin>>cur;
        g.pb(cur);
        For(i,0,b.size()){
            if(abs(b[i]-g.back())<2){
                graph[i].pb(g.size()-1);
            }
        }
    }
    match = V<int>(g.size(),-1);
    V<bool> visited;
    For(i,0,b.size()){
        visited = V<bool>(g.size(),false);
        if(bpg(i,visited))
            res++;
    }
    cout<<res;
    return 0;
}
/**/


/**/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define FOR(i, begin, end) for(__typeof(end) i = (begin); i < (end); i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted. O.o
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 */
const ll mod = 1000000009;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int b,g;
    V<int> bb,gg;
    cin>>b;
    while(b--){cin>>g;bb.pb(g);}
    cin>>g;
    while(g--){cin>>b;gg.pb(b);}
    sort(all(bb));
    sort(all(gg));
    int res = 0;
    int j = 0;
    For(i,0,bb.size()){
        if(j==(int)gg.size())break;
        for(;j<(int)gg.size();j++){
            if(abs(gg[j]-bb[i])<=1){res++;j++;break;}
            else break;
        }
    }
    cout<<res<<endl;
    return 0;
}
/**/


/*kee template*/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * Here's my safety pig, I hope my code compile and get accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,cur,res = 0;
    V<V<int> > graph;
    V<int> b,g;
    cin>>n;
    V<int> emp(0);
    graph = V<V<int> >(n,emp);
    while(n--){
        cin>>cur;
        b.pb(cur);
    }
    cin>>n;
    while(n--){
        cin>>cur;
        g.pb(cur);
        For(i,0,b.size()){
            if(abs(b[i]-g.back())<2){
                graph[i].pb(g.size()-1);
            }
        }
    }
    V<int> match(g.size(),-1);
    V<bool> visited;
    For(i,0,b.size()){
        visited = V<bool>(g.size(),false);
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            bool found = false;
            For(j,0,graph[u].size()){
                if(!visited[j]){
                    visited[j] = true;
                    if(match[j] == -1){
                        res++;
                        match[j] = i;
                        found = true;
                        break;
                    }else{
                        q.push(match[j]);
                    }
                }
            }
            if(found)break;
        }
    }
    cout<<res;
    return 0;
}
/**/


/*kee template*/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * Here's my safety pig, I hope my code compile and get accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
V<V<int> > graph;
V<int> match;

bool bpg(int u,V<bool> visited){
    For(i,0,graph[u].size()){
        if(!visited[graph[u][i]]){
            visited[graph[u][i]] = true;
            if(match[graph[u][i]] == -1){
                match[graph[u][i]] = u;
                return true;
            }else if (bpg(match[graph[u][i]],visited)){
                match[graph[u][i]] = u;
                return true;
            }
        }
    }
    return false;
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,cur,res = 0;
    V<int> b,g;
    cin>>n;
    V<int> emp(0);
    graph = V<V<int> >(n,emp);
    while(n--){
        cin>>cur;
        b.pb(cur);
    }
    cin>>n;
    while(n--){
        cin>>cur;
        g.pb(cur);
        For(i,0,b.size()){
            if(abs(b[i]-g.back())<2){
                graph[i].pb(g.size()-1);
            }
        }
    }
    match = V<int>(g.size(),-1);
    V<bool> visited;
    For(i,0,b.size()){
        V<bool> visited = V<bool>(g.size(),false);
        if(bpg(i,visited))
            res++;
    }
    cout<<res;
    return 0;
}
/**/


//http://codeforces.com/problemset/problem/489/B
/**/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define FOR(i, begin, end) for(__typeof(end) i = (begin); i < (end); i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted. O.o
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 */
const ll mod = 1000000009;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int b,g;
    V<int> bb,gg;
    cin>>b;
    while(b--){cin>>g;bb.pb(g);}
    cin>>g;
    while(g--){cin>>b;gg.pb(b);}
    sort(all(bb));
    sort(all(gg));
    int res = 0;
    int j = 0;
    For(i,0,bb.size()){
        if(j==(int)gg.size())break;
        for(;j<(int)gg.size();j++){
            if(abs(gg[j]-bb[i])<=1){res++;j++;break;}
        }
    }
    cout<<res<<endl;
    return 0;
}
/**/


/*kee template*/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define SORT(v) sort(all(v))
#define SORTd(v) sort(v.rbegin(),v.rend())
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * Here's my safety pig, I hope my code compile and get accepted.
 * _._ _..._ .-',     _.._(`))
 *'-. `     '  /-._.-'    ',/
 *   )         \            '.
 *  / _    _    |             \
 * |  a    a    /              |
 * \   .-.     /               ;
 *  '-('' ).-'       ,'       ;
 *     '-;           |      .'
 *        \           \    /
 *        | 7  .__  _.-\   \
 *        | |  |  ``/  /`  /
 *       /,_|  |   /,_/   /
 *          /,_/      '`-'
 */
const ll mod = 1000000007;
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,cur,res = 0;
    V<V<int> > graph;
    V<int> b,g;
    cin>>n;
    V<int> emp(0);
    graph = V<V<int> >(n,emp);
    while(n--){
        cin>>cur;
        b.pb(cur);
    }
    cin>>n;
    while(n--){
        cin>>cur;
        g.pb(cur);
        For(i,0,b.size()){
            if(abs(b[i]-g.back())<2){
                graph[i].pb(g.size()-1);
            }
        }
    }
    V<int> match(g.size(),-1);
    V<bool> visited;
    For(i,0,b.size()){
        visited = V<bool>(g.size(),false);
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            bool found = false;
            For(j,0,graph[u].size()){
                if(!visited[graph[u][j]]){
                    visited[graph[u][j]] = true;
                    if(match[graph[u][j]] == -1){
                        res++;
                        match[graph[u][j]] = u;
                        found = true;
                        break;
                    }else{
                        q.push(match[graph[u][j]]);
                    }
                }
            }
            if(found)break;
        }
    }
    cout<<res;
    return 0;
}
/**/


//http://codeforces.com/problemset/problem/489/B
/**/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define FOR(i, begin, end) for(__typeof(end) i = (begin); i < (end); i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define minv(v) min_element(all(v))
#define maxv(v) max_element(all(v))
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted. O.o
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 */
const ll mod = 1000000009;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int b,g;
    V<int> bb,gg;
    cin>>b;
    while(b--){cin>>g;bb.pb(g);}
    cin>>g;
    while(g--){cin>>b;gg.pb(b);}
    sort(all(bb));
    sort(all(gg));
    int res = 0;
    int j = 0;
    For(i,0,bb.size()){
        if(j==(int)gg.size())break;
        for(;j<(int)gg.size();j++){
            if(abs(gg[j]-bb[i]<=1)){res++;j++;break;}
        }
    }
    cout<<res<<endl;
    return 0;
}
/**/


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
struct dance{
    int skill;
    bool boy;
};
bool Q(dance a, dance b){
    if (a.skill < b.skill) return true;
    return false;
}
int main(){
    int n,m;
    cin >> n;
    vector<dance>vec;
    for (int i = 0; i < n; i++){
        dance tmp;
        cin >> tmp.skill;
        tmp.boy = 1;
        vec.push_back(tmp);
    }
    sort(vec.begin(), vec.end(),Q);
    vector<int>g;
    int sum = 0;
    cin >> m;
    for (int i = 0; i < m; i++){
        int tmp;
        cin >> tmp;
        g.push_back(tmp);

    }
    sort(g.begin(), g.end());
    for (int i = 0; i < m; i++){
        for (int j = 0; j < n; j++){
            if (vec[j].boy && (g[i] == vec[j].skill || g[i] == vec[j].skill + 1 || g[i] == vec[j].skill - 1)){
                sum++;
                vec[j].boy = 0;
                break;
            }
        }
    }
        cout << sum << endl;
}


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
struct dance{
    int skill;
    bool boy;
};
bool Q(dance a, dance b){
    if (a.skill < b.skill) return false;
    return true;
}
int main(){
    int n,m;
    cin >> n;
    vector<dance>vec;
    for (int i = 0; i < n; i++){
        dance tmp;
        cin >> tmp.skill;
        tmp.boy = 1;
        vec.push_back(tmp);
    }
    sort(vec.begin(), vec.end(),Q);
    vector<int>g;
    int sum = 0;
    cin >> m;
    for (int i = 0; i < m; i++){
        int tmp;
        cin >> tmp;
        g.push_back(tmp);

    }
    sort(g.begin(), g.end());
    for (int i = 0; i < m; i++){
        for (int j = 0; j < n; j++){
            if (vec[j].boy && (g[i] == vec[j].skill || g[i] == vec[j].skill + 1 || g[i] == vec[j].skill - 1)){
                sum++;
                vec[j].boy = 0;
                break;
            }
        }
    }
        cout << sum << endl;
}


#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
using namespace std;
struct dance{
    int skill;
    bool boy;
};
int main(){
    int n,m;
    cin >> n;
    vector<dance>vec;
    for (int i = 0; i < n; i++){
        dance tmp;
        cin >> tmp.skill;
        tmp.boy = 1;
        vec.push_back(tmp);
    }
    int sum = 0;
    cin >> m;
    for (int i = 0; i < m; i++){
        int tmp;
        cin >> tmp;
        for (int j = 0; j < n; j++){
            if (vec[j].boy && (tmp == vec[j].skill || tmp == vec[j].skill + 1 || tmp == vec[j].skill - 1)){
                sum++;
                vec[j].boy = 0;
                break;
            }
        }
    }
        cout << sum << endl;
}


#include "bits/stdc++.h"

using namespace std;

const int MAXN = 107;
int a[MAXN], b[MAXN];

int main()
{
   int n, m;
   scanf("%d", &n);
   for(int i=0; i<n; i++)
      scanf("%d", a+i);
   scanf("%d", &m);
   for(int i=0; i<m; i++)
      scanf("%d", b+i);
   sort(a, a+n);
   sort(b, b+m);
   int i = 0, j = 0, res = 0;
   while(true)
   {
      while(j<m && a[i]-1 > b[j])
         j++;
      while(i<n && a[i] < b[j]-1)
         i++;
      if(i==n || j==m)
         break;
      if(abs(a[i]-b[j])<=1)
      {
         cerr << a[i] << " " << b[j] << "\n";
         i++;
         j++;
         res++;
      }
   }
   printf("%d\n", res);

}


#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#define forl(i,n) for(int i=0;i<(int)n;i++)
#define pb(x) push_back(x)
#define mem(x,y) memset(x,y,sizeof(x))
#define mp make_pair
#define uu first
#define vv second
#define ll long long
using namespace std;

int main()
{
    int n,m;
    vector<int >an,am;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        an.push_back(x);

    }
    cin>>m;
    for(int j=0;j<m;j++)
    {
        int x;
        cin>>x;
        am.push_back(x);

    }
    sort(an.begin(), an.end());
    sort(am.begin(), am.end());
    int c=0;
    for(int i=0;i<an.size();i++)
    {
        for( int j=0;j<am.size();j++)
        {
            int x=abs(an[i]-am[j]);
            if(x<=1)
            {
               am.erase (am.begin()+j);
               c++;
            }

        }
    }
    printf("%d\n",c);
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int bitcount(long long x) {
    int cnt = 0;
    while (x > 0) {
        if (x & 1) cnt++;
        x >>= 1;
    }
    return cnt;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> b(n + 1), s(n + 1), even, odd, lastmax(n + 1);
    b[0] = 0;
    s[0] = 0;
    even.push_back(0);
    int mx1 = -1, mx2 = -1;

    for (int i=1; i<=n; i++) {
        long long tmp;
        scanf("%I64d", &tmp);
        b[i] = bitcount(tmp);
        s[i] = s[i-1] + b[i];
        mx1 = max(mx1, b[i]);
        mx2 = max(mx2, b[i]);
        if (s[i] & 1) {
            odd.push_back(i);
            lastmax[i] = mx1;
            mx1 = -1;
        }
        else {
            even.push_back(i);
            lastmax[i] = mx2;
            mx2 = -1;
        }
    }

    int n1 = odd.size(), n2 = even.size();
    long long ans = 0;
    ans += (long long)(n1) * (n1 - 1) / 2;
    ans += (long long)(n2) * (n2 - 1) / 2;
    for (int i=0; i<odd.size(); i++) {
        int j, k0 = odd[i], mx=-1;
        for (j=i+1; j<odd.size(); j++) {
            int k = odd[j];
            mx = max(mx, lastmax[k]);
            if (2 * mx <= s[k] - s[k0])
                break;
        }
        ans -= j - i - 1;
    }
    for (int i=0; i<even.size(); i++) {
        int j, k0 = even[i], mx=-1;
        for (j=i+1; j<even.size(); j++) {
            int k = even[j];
            mx = max(mx, lastmax[k]);
            if (2 * mx <= s[k] - s[k0])
                break;
        }
        ans -= j - i - 1;
    }

    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int bitcount(long long x) {
    int cnt = 0;
    while (x > 0) {
        if (x & 1) cnt++;
        x >>= 1;
    }
    return cnt;
}

void print(vector<int>& x) {
    for (int i=0; i<x.size(); i++)
        printf("%d ", x[i]);
    printf("\n");
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> b(n + 1), s(n + 1), even, odd, lastmax(n + 1);
    b[0] = 0;
    s[0] = 0;
    even.push_back(0);
    int mx1 = -1, mx2 = -1;

    for (int i=1; i<=n; i++) {
        long long tmp;
        scanf("%I64d", &tmp);
        b[i] = bitcount(tmp);
        s[i] = s[i-1] + b[i];
        mx1 = max(mx1, b[i]);
        mx2 = max(mx2, b[i]);
        if (s[i] & 1) {
            odd.push_back(i);
            lastmax[i] = mx1;
            mx1 = -1;
        }
        else {
            even.push_back(i);
            lastmax[i] = mx2;
            mx2 = -1;
        }
    }

    int n1 = odd.size(), n2 = even.size();
    long long ans = 0;
    ans += (long long)(n1) * (n1 - 1) / 2;
    ans += (long long)(n2) * (n2 - 1) / 2;

    for (int i=1; i<b.size(); i++) {
        int j, k=i+1;
        int cnt[2];
        cnt[0] = 0;
        cnt[1] = 0;
        cnt[s[i] & 1]++;
        for (j=i-1; j>=0 && b[j+1] <= b[i] && s[i] - s[j] < 2 * b[i]; j--);
        for (j++; j<i; j++) {
            for (; k<b.size() && b[k] < b[i] && s[k] - s[j] < 2 * b[i]; cnt[s[k] & 1]++, k++);
            ans -= cnt[s[j] & 1];
        }
    }

    printf("%I64d\n", ans);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

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

int n;
long long a[N];
int b[N];
int cnt[2][N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i <n; ++i) {
		cin >> a[i];
		b[i] = __builtin_popcountll(a[i]);
	}

	long long res = 0;
	int sufSum = 0;
	cnt[0][n] = 1;
	for (int i = n - 1; i >= 0; --i) {
		int sum = 0, mx = 0;
		int lstJ = i;
		int add = 0;
		for (int j = i; j < n && j - i < 65; ++j) {
			sum += b[j];
			mx = max(mx, b[j]);
			if (mx > sum - mx && sum % 2 == 0) --add;
			lstJ = j;
		}

		sufSum += b[i];
		add += cnt[sufSum & 1][i + 1];
		res += add;

		cnt[0][i] = cnt[0][i + 1];
		cnt[1][i] = cnt[1][i + 1];
		if (sufSum & 1) ++cnt[1][i];
		else ++cnt[0][i];
	}

	cout << res << endl;
	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#include<vector>

using namespace std;

const int MAXN = 300000 + 10;

int bits[MAXN];
int cnt[MAXN][2];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long int tmp;
		cin >> tmp;
		while (tmp) {
			if (tmp & 1) {
				bits[i]++;
			}
			tmp >>= 1;
		}
	}

	long long int Ans = 0;
	int Sufsum = 0;

	cnt[n][0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		int Max = 0;
		int Sum = 0;
		int Add = 0;
		for (int j = i; j < n && j - i < 64; j++) {
			Sum += bits[j];
			Max = max(Max, bits[j]);
			if (Sum % 2 == 0 && Max > Sum - Max) Add--;
		}

		Sufsum += bits[i];
		Add += cnt[i + 1][Sufsum & 1];
		Ans += Add;

		cnt[i][0] = cnt[i + 1][0];
		cnt[i][1] = cnt[i + 1][1];

		if (Sufsum & 1) cnt[i][1]++;
		else cnt[i][0]++;

	}
	cout << Ans << endl;

	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#include<vector>

using namespace std;

const int MAXN = 300000 + 10;

int bits[MAXN];
int cnt[MAXN][2];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		while (tmp) {
			if (tmp & 1) {
				bits[i]++;
			}
			tmp >>= 1;
		}
	}

	long long int Ans = 0;
	int Sufsum = 0;

	cnt[n][0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		int Max = 0;
		int Sum = 0;
		int Add = 0;
		for (int j = i; j < n && j - i < 64; j++) {
			Sum += bits[j];
			Max = max(Max, bits[j]);
			if (Sum % 2 == 0 && Max > Sum - Max) Add--;
		}

		Sufsum += bits[i];
		Add += cnt[i + 1][Sufsum & 1];
		Ans += Add;

		cnt[i][0] = cnt[i + 1][0];
		cnt[i][1] = cnt[i + 1][1];

		if (Sufsum & 1) cnt[i][1]++;
		else cnt[i][0]++;

	}
	cout << Ans << endl;

	return 0;
}


#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>
#include<unordered_map>
#include<unordered_set>
#include<tuple>
#include<vector>

using namespace std;

const int MAXN = 300000 + 10;

int bits[MAXN];
int cnt[MAXN][2];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long int tmp;
		cin >> tmp;
		while (tmp) {
			if (tmp & 1) {
				bits[i]++;
			}
			tmp >>= 1;
		}
	}

	long long int Ans = 0;
	int Sufsum = 0;

	cnt[n][0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		int Max = 0;
		int Sum = 0;
		int Add = 0;
		for (int j = i; j < n && j - i < 64; j++) {
			Sum += bits[j];
			Max = max(Max, bits[j]);
			if (Sum % 2 == 0 && Max > Sum - Max) Add--;
		}

		Sufsum += bits[i];
		Add += cnt[i + 1][Sufsum & 1];
		Ans += Add;

		cnt[i][0] = cnt[i + 1][0];
		cnt[i][1] = cnt[i + 1][1];

		if (Sufsum & 1) cnt[i][1]++;
		else cnt[i][0]++;

	}
	cout << Ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	int mi=70;
	for(int i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		a[i]=__builtin_popcountll(x);
	}
	ll ans=0;
	// for(int l=0;l<n;l++)
	// {
	// 	int sum=0;
	// 	int mx=-1;
	// 	for(int r=l;r<min(n,l+mi);r++)
	// 	{
	// 		sum+=a[r];
	// 		mx=max(mx,a[r]);
	// 		if(sum%2==0&&2*mx>=sum) ans++;

	// 	}
	// }
	// //vector<int> pref(n+1);
	int parity=0;
	int odd=0;
	int even=1;
	for(int i=0;i<n;i++)
	{
		parity=(parity+a[i])%2;
        if(parity==0) even++;
		else odd++;
	}
	auto f=[](int x){
		return (x*1LL*(x-1)) /2;
	};
	ans+=f(even)+f(odd);
	for(int l=0;l<n;l++)
	{
		int sum=0;
		int mx=-1;
		for(int r=l;r<min(n,l+mi);r++)
		{
			sum+=a[r];
			mx=max(mx,a[r]);
			if(sum%2==0&&2*mx>sum) ans--;

		}
	}
	cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	int mi=70;
	for(int i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		a[i]=__builtin_popcountll(x);
	}
	int ans=0;
	// for(int l=0;l<n;l++)
	// {
	// 	int sum=0;
	// 	int mx=-1;
	// 	for(int r=l;r<min(n,l+mi);r++)
	// 	{
	// 		sum+=a[r];
	// 		mx=max(mx,a[r]);
	// 		if(sum%2==0&&2*mx>=sum) ans++;

	// 	}
	// }
	// //vector<int> pref(n+1);
	int parity=0;
	int odd=0;
	int even=1;
	for(int i=0;i<n;i++)
	{
		parity=(parity+a[i])%2;
        if(parity==0) even++;
		else odd++;
	}
	auto f=[](int x){
		return (x*(x-1)) /2;
	};
	ans+=f(even)+f(odd);
	for(int l=0;l<n;l++)
	{
		int sum=0;
		int mx=-1;
		for(int r=l;r<min(n,l+mi);r++)
		{
			sum+=a[r];
			mx=max(mx,a[r]);
			if(sum%2==0&&2*mx>sum) ans--;

		}
	}
	cout<<ans<<endl;

}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 3e5 + 100;

int Count(ll x) {
	int Res = 0;
	while (x) {
		Res += (x&1LL);
		x >>= 1LL;
	}
	return Res;
}

int Arr[N];
int Pre[N];
int Odd[N];
int Even[N];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n;	cin >> n;
	for (int i = 1; i <= n; i++) {
		ll x;	cin >> x;
		Arr[i] = Count(x);
		Pre[i] = Pre[i - 1] + Arr[i];
	}

	for (int i = 1; i <= n; i++) {
		(Pre[i] % 2 == 0 ? Even : Odd)[i] = 1;

		Odd[i] += Odd[i - 1];
		Even[i] += Even[i - 1];
	}

	ll Ans = 0;
	for (int i = n - 1; i > 0; i--)
	{
		int Cur = (Pre[i - 1] % 2 == 0 ? Even[n] - Even[i] : Odd[n] - Odd[i]);

		int Sum = 0, Max = 0;
		for (int j = i; j <= min(n, i + 61); j++) {
			Sum += Arr[j];
			Max = max(Max, Arr[j]);

			Cur -= ((Pre[j] - Pre[i - 1]) % 2 == 0 && Max > Sum);
		}

		Ans += Cur;
	}

	cout << Ans << '\n';

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 3e5 + 100;

int Count(ll x) {
	int Res = 0;
	while (x) {
		Res += (x&1LL);
		x >>= 1LL;
	}
	return Res;
}

int Arr[N];
int Pre[N];
int Odd[N];
int Even[N];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n;	cin >> n;
	for (int i = 1; i <= n; i++) {
		ll x;	cin >> x;
		Arr[i] = Count(x);
		Pre[i] = Pre[i - 1] + Arr[i];
	}

	for (int i = 1; i <= n; i++) {
		(Pre[i] % 2 == 0 ? Even : Odd)[i] = 1;

		Odd[i] += Odd[i - 1];
		Even[i] += Even[i - 1];
	}

	ll Ans = 0;
	for (int i = n - 1; i > 0; i--)
	{
		int Cur = (Pre[i - 1] % 2 == 0 ? Even[n] - Even[i] : Odd[n] - Odd[i]);

		int Sum = Arr[i], Max = Arr[i];
		for (int j = i + 1; j <= min(n, i + 61); j++) {
			Sum += Arr[j];
			Max = max(Max, Arr[j]);

			Cur -= ((Pre[j] - Pre[i - 1]) % 2 == 0 && (Max > Sum - Max));
		}

		Ans += Cur;
	}

	cout << Ans << '\n';

	return 0;
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 3e5 + 100;

int Count(ll x) {
	int Res = 0;
	while (x) {
		Res += (x&1LL);
		x >>= 1LL;
	}
	return Res;
}

int Arr[N];
int Pre[N];
int Odd[N];
int Even[N];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n;	cin >> n;
	for (int i = 1; i <= n; i++) {
		ll x;	cin >> x;
		Arr[i] = Count(x);
		Pre[i] = Pre[i - 1] + Arr[i];
	}

	for (int i = 1; i <= n; i++) {
		(Pre[i] % 2 == 0 ? Even : Odd)[i] = 1;

		Odd[i] += Odd[i - 1];
		Even[i] += Even[i - 1];
	}

	ll Ans = 0;
	for (int i = n - 1; i > 0; i--)
	{
		int Cur = (Pre[i - 1] % 2 == 0 ? Even[n] - Even[i] : Odd[n] - Odd[i]);

		int Sum = 0, Max = 0;
		for (int j = i; j <= min(n, i + 61); j++) {
			Sum += Arr[j];
			Max = max(Max, Arr[j]);

			Cur -= ((Pre[j] - Pre[i - 1]) % 2 == 0 && Max > Sum - Max);
		}

		Ans += Cur;
	}

	cout << Ans << '\n';

	return 0;
}