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

namespace AGC045
{
    using static Ex;
    public class Solve
    {
        public static void Main(string[] args)
        {
            new AGC_B();
        }
    }
    public class AGC_A
    {
        public AGC_A()
        {
            //T個のテストケース
            var t = ReadInt;
            for (int i = 0; i < t; i++)
            {
                var n = ReadInt;
                var arr = ReadLongArray();
                var ss = Read;
                long x = 0;

                for (int j = 0; j < n; j++)
                {
                    var a = arr[j];
                    var s = ss[j];
                    (x ^ a).Cw();
                    if (x == (x ^ a)) continue;
                    if (s == '0')
                    {
                        if (x == (s - '0')) continue;
                    }
                    else
                    {
                        if (x > (s - '0')) continue;
                    }
                    x ^= a;
                }
                ZeroOne(x);
            }
        }
        void ZeroOne(long x) { (x == 0 ? "0" : "1").Cw(); }
    }
    public class AGC_B
    {
        public AGC_B()
        {
            var s = Read.ToCharArray();
            long len = s.Length;
            //アンバランス度 = max { S ′ の l 文字目から r 文字目までに含まれる 0 の個数と 1 の個数の差の絶対値 : 1 ≤ l ≤ r ≤ N }
            long ans = 1;

            var zero = new long[len];
            var one = new long[len];
            var zero2 = new long[len];
            var one2 = new long[len];
            var q = new long[len];
            var q2 = new long[len];
            long[] max = new long[2];
            long[] maxIdx = new long[2];
            //long[] now = new long[3];
            {

                zero2[0] = s[0] != '0' ? 1 : 0;
                one2[0] = s[0] != '1' ? 1 : 0;
                zero[0] = s[0] == '0' ? 1 : 0;
                one[0] = s[0] == '1' ? 1 : 0;
                q[0] = s[0] == '?' ? 1 : 0;
                q2[0] = s[0] != '?' ? 1 : 0;
                max[0] = zero[0];
                max[1] = one[0];
            }
            for (long i = 1; i < len; i++)
            {
                zero2[i] = s[i] != '0' ? zero2[i - 1] + 1 : 0;
                one2[i] = s[i] != '1' ? one2[i - 1] + 1 : 0;
                zero[i] = s[i] == '0' ? zero[i - 1] + 1 : 0;
                one[i] = s[i] == '1' ? one[i - 1] + 1 : 0;
                q[i] = s[i] == '?' ? q[i - 1] + 1 : 0;
                q2[i] = s[i] != '?' ? q2[i - 1] + 1 : 0;
                if (max[0] < zero[i])
                {
                    max[0] = zero[i];
                    maxIdx[0] = i;
                }
                if (max[1] < one[i])
                {
                    max[1] = one[i];
                    maxIdx[1] = i;
                }
                //if (s[i] == '0') now[0]++;
                //else if (s[i] == '1') now[1]++;
                //else now[2]++;
            }

            for (long i = len - 2; i >= 0; i--)
            {
                if (zero2[i] > 0 && zero2[i + 1] > 0) zero2[i] = zero2[i + 1];
                if (one2[i] > 0 && one2[i + 1] > 0) one2[i] = one2[i + 1];
                if (zero[i] > 0 && zero[i + 1] > 0) zero[i] = zero[i + 1];
                if (one[i] > 0 && one[i + 1] > 0) one[i] = one[i + 1];
                if (q[i] > 0 && q[i + 1] > 0) q[i] = q[i + 1];
                if (q2[i] > 0 && q2[i + 1] > 0) q2[i] = q2[i + 1];
            }

            ans = Math.Max(max[0], ans);
            ans = Math.Max(max[1], ans);

            long pre = 0;
            long cou = 0;
            for (long i = maxIdx[0]; i >= 0;)
            {
                cou += zero[i];
                i -= zero[i];
                ans = Math.Max(cou, ans);
                if (pre >= cou) break;
                pre = cou;
                if (i < 0) break;

                cou -= zero2[i];
                i -= zero2[i];
                if (i < 0) break;
            }

            cou = 0; long pp = 0;
            for (long i = maxIdx[0]; i < len;)
            {
                cou += zero[i];
                i++;
                ans = Math.Max(cou, ans);
                if (pp >= cou) break;
                pp = cou;
                if (i >= len) break;

                cou -= zero2[i];
                i += zero2[i];
                if (i >= len) break;
                i += zero[i] - 1;
            }
            ans = Math.Max(pre + pp - max[0], ans);

            cou = 0; pre = 0;
            for (long i = maxIdx[1]; i >= 0;)
            {
                cou += one[i];
                i -= one[i];
                ans = Math.Max(cou, ans);
                if (pre >= cou) break;
                pre = cou;
                if (i < 0) break;

                cou -= one2[i];
                i -= one2[i];
                if (i < 0) break;
            }

            cou = 0; pp = 0;
            for (long i = maxIdx[1]; i < len;)
            {
                cou += one[i];
                i++;
                ans = Math.Max(cou, ans);
                if (pp >= cou) break;
                pp = cou;
                if (i >= len) break;

                cou -= one2[i];
                i += one2[i];
                if (i >= len) break;
                i += one[i] - 1;
            }
            ans = Math.Max(pre + pp - max[1], ans);

            if (ans == 1)
            {
                char c = '!';
                for (long i = 0; i < len; i++)
                {
                    if (s[i] != '?')
                    {
                        if (c == s[i] && i - 1 >= 0 && q[i - 1] >= 2)
                        {
                            2.Cw();
                            return;
                        }
                        c = s[i];
                    }
                }
            }

            ans.Cw();
        }
    }
    public class AGC_C
    {
        public AGC_C()
        {
        }
    }
    public class AGC_D
    {
        public AGC_D()
        {
        }
    }
    public class AGC_
    {
        public AGC_()
        {
        }
    }

    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }



        public static bool Mins<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
        public static bool Maxs<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
        public static void Swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
        public static void Swap<T>(List<T> list, int i, int j) { T tmp = list[j]; list[j] = list[i]; list[i] = tmp; }


        static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); }
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static void yesno(this bool b) { (b ? "yes" : "no").Cw(); }
        public static void YesNo(this bool b) { (b ? "Yes" : "No").Cw(); }
        public static void YESNO(this bool b) { (b ? "YES" : "NO").Cw(); }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var v = new string[N]; for (long i = 0; i < N; ++i) v[i] = Read; return v; }
        public static int[] ReadIntArray(long N) { var v = new int[N]; for (long i = 0; i < N; ++i) v[i] = ReadInt; return v; }
        public static long[] ReadLongArray(long N) { var v = new long[N]; for (long i = 0; i < N; ++i) v[i] = ReadLong; return v; }

        public static (T, T) ToTpl2<T>(this T[] v) { return (v[0], v[1]); }
        public static (T, T, T) ToTpl3<T>(this T[] v) { return (v[0], v[1], v[2]); }
        public static (T, T, T, T) ToTpl4<T>(this T[] v) { return (v[0], v[1], v[2], v[3]); }
        public static (T, T, T, T, T) ToTpl5<T>(this T[] v) { return (v[0], v[1], v[2], v[3], v[4]); }


        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

        /// <summary>
        /// lower_boundは、探索したいkey以上のイテレータを返す
        /// upper_boundは、探索したいkeyより大きいイテレータを返す
        public static int UpperBound<T>(List<T> a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(List<T> a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Count - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}