#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int q,i,j,k,n;
	string s;
	cin>>q;
	while(q--){
		cin>>n;
		int ans=0,sum1=0,sum2=0;
		for(i=0;i<n;i++){
			cin>>s;
			if(s.size()&1) {
				sum1+=s.size();
				ans++;
			}
			else{
				int count1=0,count2=0;
				for(j=0;j<s.size();j++){
					if(s[j]=='0') count1++;
					else count2++;
				}
				if(count1%2==0&&count2%2==0) ans++;
				else sum2++;
			}
		}
		if(sum1>=sum2)	cout<<ans+min(sum1,sum2)<<endl;
		else cout<<ans+(sum2-sum1)-(sum2-sum1)%2+sum1<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    string s;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        int cnt1 = 0;
        int cnt2 = 0;
        vector <int> b(n);
        for (int j = 0; j < n; j++) {
            cin >> s;
            b[j] = s.size();
            for (int u = 0; u < s.size(); u++) {
                if (s[u] == '0')
                    cnt1++;
                else
                    cnt2++;
            }
        }
        sort(b.begin(), b.end());
        int g = 0;
        for (int u = 0; u < b.size(); u++) {
            int w = b[u];
            if (w % 2 == 1) {
                w--;
                if (cnt1 == 0 && cnt2 == 0)
                    break;
                else if (cnt1 == 0)
                    cnt2--;
                else if (cnt2 == 0)
                    cnt1--;
                else if (cnt1 % 2 == 1)
                    cnt1--;
                else if (cnt2 % 2 == 1)
                    cnt2--;
                else if (cnt1 < cnt2)
                    cnt1--;
                else
                    cnt2--;
            }
        if (w <= cnt1 / 2 * 2 + cnt2 / 2 * 2) {
            ++g;
            int kakayatohrenyaga = min(cnt1 / 2 * 2, w);
            cnt1 -= kakayatohrenyaga;
            cnt2 -= w - kakayatohrenyaga;
        }
    }
    cout << g << endl;
}
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }

            if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size()) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if (globcnt1 == globcnt2)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() == 1)
                bl = false;
            if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size()) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if ((globcnt1 + globcnt2) % 2 == 0 || !bl)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        int cnt0 = 0;
        int cnt1 = 0;
        for (int j = 0; j < n; ++j) {
            string s;
            cin >> s;
            for (int u = 0; u < s.size(); ++u) {
                if (s[u] == '1') {
                    ++cnt1;
                } else if (s[u] == '0') {
                    ++cnt0;
                }
            }
        }
        if (cnt1 % 2 == cnt0 % 2) {
            cout << n - 1 << endl;
        }
        else {
            cout << n << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int q;
    string s;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        int cnt1 = 0;
        int cnt2 = 0;
        vector <int> b(n);
        for (int j = 0; j < n; j++) {
            cin >> s;
            b[j] = s.size();
            for (int u = 0; u < s.size(); u++) {
                if (s[u] == '0')
                    cnt1++;
                else
                    cnt2++;
            }
        }
        sort(b.begin(), b.end());
        int g = 0;
        for (int u = 0; u < b.size(); u++) {
            int w = b[u];
            if (w % 2 == 1) {
                w--;
                if (cnt1 == 0 && cnt2 == 0)
                    break;
                else if (cnt1 == 0)
                    cnt2--;
                else if (cnt2 == 0)
                    cnt1--;
                else if (cnt1 % 2 == 1)
                    cnt1--;
                else if (cnt2 % 2 == 1)
                    cnt2--;
                else if (cnt1 < cnt2)
                    cnt1--;
                else
                    cnt2--;
            }
        if (w <= cnt1 / 2 * 2 + cnt2 / 2 * 2) {
            ++g;
            int kakayatohrenyaga = min(cnt2 / 2 * 2, w);
            cnt1 -= kakayatohrenyaga;
            cnt2 -= w - kakayatohrenyaga;
        }
    }
    cout << g << endl;
}
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }

            if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size()) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if ((globcnt1 + globcnt2) % 2 == 0)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

signed main() {
    int q;
    string s;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        int cnt1 = 0;
        int cnt2 = 0;
        vector <int> b(n);
        for (int i = 0; i < n; i++) {
            cin >> s;
            b[i] = s.size();
            for (int j = 0; j < s.size(); j++) {
                if (s[j] == '0')
                    cnt1++;
                else
                    cnt2++;
            }
        }
        sort(b.begin(), b.end());
        int g = 0;
        for (int i = 0; i < b.size(); i++) {
            int w = b[i];
            if (w % 2 == 1) {
                w--;
                if (cnt1 == 0 && cnt2 == 0)
                    break;
                else if (cnt1 == 0)
                    cnt2--;
                else if (cnt2 == 0)
                    cnt1--;
                else if (cnt1 % 2 == 1)
                    cnt1--;
                else if (cnt2 % 2 == 1)
                    cnt2--;
                else if (cnt1 < cnt2)
                    cnt1--;
                else
                    cnt2--;
            }
        if (w <= cnt1 / 2 * 2 + cnt2 / 2 * 2) {
            ++g;
            int kakayatohrenyaga = min(cnt2 / 2 * 2, w);
            cnt1 -= kakayatohrenyaga;
            cnt2 -= w - kakayatohrenyaga;
        }
    }
    cout << g << endl;
}
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        int help = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() % 2)
                help++;
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if (help >= globcnt2 || globcnt2 % 2 == 0)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        int help = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() % 2)
                help++;
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if (help >= globcnt2)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        int help = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() == 1)
                bl = false;
            if (a[j].size() % 2 && a[j].size() == cnt1)
                help++;
            else if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size()) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if ((globcnt1 + globcnt2) % 2 == 0 || !bl)
            cout << n;
        else if (help > 0)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() == 1)
                bl = false;
            if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size() && a[j].size() != cnt1) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if ((globcnt1 + globcnt2) % 2 == 0 || !bl)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        int help = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() == 1)
                bl = false;
            if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 < a[j].size())
                help++;
            else if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size()) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if ((globcnt1 + globcnt2) % 2 == 0 || !bl)
            cout << n;
        else if (help > 0)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        int help = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() == 1)
                bl = false;
            if (a[j].size() % 2 && cnt1 % 2)
                help++;
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if (help >= globcnt2)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int n;
        cin >> n;
        vector<string> a(n);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
        }
        int globcnt1 = 0;
        int globcnt2 = 0;
        int help = 0;
        bool bl = true;
        for (int j = 0; j < n; ++j) {
            int cnt1 = 0;
            int cnt2 = 0;
            for (int u = 0; u < a[j].size(); ++u) {
                if (a[j][u] == '1')
                    cnt1++;
                else
                    cnt2++;
            }
            if (a[j].size() == 1)
                bl = false;
            if (a[j].size() % 2 && cnt1 % 2)
                help++;
            else if (a[j].size() % 2 && cnt1 % 2 && cnt1 * 2 > a[j].size()) {
                globcnt1++;
            }
            if (a[j].size() % 2 == 0 && cnt1 % 2)
                globcnt2++;

        }
        if ((globcnt1 + globcnt2) % 2 == 0 || !bl)
            cout << n;
        else if (help > 0)
            cout << n;
        else
            cout << n - 1;
        cout << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    ll int q,i,n,j,d,sum,a,k,b,c[55],t,g,h;
    string s[55];
    cin>>q;
    for(i=0;i<q;i++)
    {
        sum=0;
        t=0;
        cin>>n;
        for(j=0;j<n;j++){
            cin>>s[j];
        if((s[j].size())%2!=0)
        sum++;
        else
            {
                a=0;
                b=0;
                for(k=0;s[j][k]!='\0';k++)
                    if(s[j][k]=='0')
                    a++;
                else
                    b++;
                if(a%2!=0)
                    t++;

            }
            }
            if(t%2==0)
                cout<<n<<"\n";
            else if(sum>0)
                cout<<n<<"\n";
            else
                cout<<n-1<<"\n";
    }
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    ll int q,i,n,j,d,sum,a[55],k,b[55],c[55],t,g,h;
    string s[55];
    cin>>q;
    for(i=0;i<q;i++)
    {
        sum=0;
        t=0;
        cin>>n;
        for(j=0;j<n;j++){
            cin>>s[j];
        if((s[j].size())%2!=0)
        sum++;
        else
            t++;}
            if(t%2==0)
                cout<<n<<"\n";
            else if(sum>0)
                cout<<n<<"\n";
            else
                cout<<n-1<<"\n";
    }
}


#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    ll int q,i,n,j,d,sum,a[55],k,b[55],c[55],t,g,h;
    string s[55];
    cin>>q;
    for(i=0;i<q;i++)
    {
        cin>>n;
        for(j=0;j<n;j++){
            cin>>s[j];
        if((s[j].size())%2!=0)
        sum++;
        else
            t++;}
            if(t%2==0)
                cout<<n<<"\n";
            else if(sum>0)
                cout<<n<<"\n";
            else
                cout<<n-1<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<t+1;i++)
    {    int n,e=0,o=0,one=0,z=0;
        cin>>n;
        for(int j=1;j<n+1;j++)
        {
            string s;
            cin>>s;
            if((s.size())%2==0)
            {
                e=e+1;
            }
            else
            {
                o=o+1;
            }
            for(int l=0;l<s.size();l++)
            {
                if(s[l]=='1')
                one++;
                else
                z++;
            }
        }

        if(o>0)
        cout<<""<<n<<endl;
        else if(one%2==0 && z%2==0)
        cout<<""<<n<<endl;
        else
        cout<<""<<n-1<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q,n,o=0,e=0,l[51];
    string s;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>n;
        o=0;e=0;
        for(int j=0;j<n;j++)
        {
            cin>>s;
            l[j]=s.size();
        }

        for(int k=0;k<n;k++)
        {
            if(l[k]%2==0)
            {
                e++;
            }
            else
            o++;
        }
        if(o>=1)
        {
            cout<<""<<n<<endl;
        }
        else
        {
            cout<<""<<n-1<<endl;
        }

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<t+1;i++)
    {    int n,e,o=0,one=0,z=0;
          e=0;
        cin>>n;
        for(int j=1;j<n+1;j++)
        {
            string s;
            cin>>s;
            if((s.size())%2==0)
            {
                e=e+1;
            }
            else
            {
                o=o+1;
            }
            for(int l=0;l<s.size();l++)
            {
                if(s[l]=='1')
                one++;
                else
                z++;
            }
        }

        if(o>0)
        cout<<""<<n<<endl;
        else if(one%2==0 && z%2==0)
        cout<<""<<n<<endl;
        else
        cout<<""<<n-1<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<t+1;i++)
    {    int n,e=0,o=0;
        cin>>n;
        for(int j=1;j<n+1;j++)
        {
            string s;
            cin>>s;
            if((s.size())%2==0)
            {
                e=e+1;
            }
            else
            {
                o=o+1;
            }
        }

        if(o>0)
        cout<<""<<n<<endl;
        else
        cout<<""<<n-1<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q;

    cin>>q;
    for(int i=0;i<q;i++)
    {int n,o=0,e=0,l[51],zero=0,one=0,b=0,c=0,flag=0;    string s;
        cin>>n;
         b=0;c=0;flag=0;
         cout<<n<<" ";
        for(int j=0;j<n;j++)
        {
            cin>>s;
            l[j]=s.size();
           one=0;zero=0;
            for(int w=0;w<l[j];w++)
            {
                if( s[w]=='1')
                {
                    one++;
                }
                else
                zero++;

            }
            if(zero%2==0 && one%2==0)
            {
                c++;
                flag=0;
            }
            else if (l[j]%2==1)
            {
                flag=1;
                break;
            }
            else if(l[j]%2==0)
            {
                flag=0;
                b++;
            }
            }
        if(flag)
            {
                cout<<""<<n<<endl;
            }
            else if(b>=1)
             cout<<""<<c+b-1<<endl;
             else
             {
                 cout<<""<<c<<endl;
             }

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int q;

    cin>>q;
    for(int i=0;i<q;i++)
    {int n,o=0,e=0,l[51],zero=0,one=0,b=0,c=0,flag=0;    string s;
        cin>>n;
         b=0;c=0;flag=0;

        for(int j=0;j<n;j++)
        {
            cin>>s;
            l[j]=s.size();
           one=0;zero=0;
            for(int w=0;w<l[j];w++)
            {
                if( s[w]=='1')
                {
                    one++;
                }
                else
                zero++;

            }
            if(zero%2==0 && one%2==0)
            {
                c++;
                flag=0;
            }
            else if (l[j]%2==1)
            {
                flag=1;
                break;
            }
            else if(l[j]%2==0)
            {
                flag=0;
                b++;
            }
            }
        if(flag)
            {
                cout<<""<<n<<endl;
            }
            else if(b>=1)
             cout<<""<<c+b-1<<endl;
             else
             {
                 cout<<""<<c<<endl;
             }

    }

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		int t=n;
		while(n--)
		{
			string s;
			cin>>s;
			for(int i=0;s[i];i++)
			{
				if(s[i]=='1')ont++;
				else ent++;
			}
		}if((ont+ent)%2==1 || (ont%2==0 && ent%2==0))cout<<t<<endl;
		else
			cout<<t-1<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt&1 || t&1)
				{
					eont++;
				}
				else
					ent++;
			}
		}
		cout<<(ont+ent+2*(eont/2))<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt%2==1 && t%2==1)
				{
					eont++;
				}
				else
					ent++;
			}
		}if(ont<1)eont--;
		cout<<(ont+ent+eont)<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt%2==1 && t%2==1)
				{
					eont++;
				}
				else
					ent++;
			}
		}if(eont%2==1 && ont<1)eont--;
		cout<<(ont+ent+eont)<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt&1 || t&1)
				{
					eont++;
				}
				else
					ent++;
			}
		}if(ont<1)eont--;
		cout<<(ont+ent+eont)<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt&1 || t&1)
				{
					eont++;
				}
				else
					ent++;
			}
		}
		if(ont>0 && eont%2==1)eont++;
		else eont--;
		cout<<(ont+ent+eont)<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		int t=n;
		while(n--)
		{
			string s;
			cin>>s;
			for(int i=0;s[i];i++)
			{
				if(s[i]=='1')ont++;
				else ent++;
			}
		}if((ont+ent)%2==1)cout<<t<<endl;
		else
			cout<<t-1<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt%2==1 && t%2==1)
				{
					eont++;
				}
				else
					ent++;
			}
		}
		cout<<(ont+ent+eont)<<endl;
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque>
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int ent=0,ont=0,eont=0;
		while(n--)
		{
			string s;
			cin>>s;
			if(s.length()%2==1){
				ont++;continue;
			}
			if(s.length()%2==0)
			{
				int nt=0,t=0;
				for(int i=0;s[i];i++)
				{
					if(s[i]=='1')nt++;
					else t++;
				}
				if(nt&1 || t&1)
				{
					eont++;
				}
				else
					ent++;
			}
		}
		if(ont>0 && eont%2==1)eont++;
		cout<<(ont+ent+2*(eont/2))<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;int c=0,c1=0,c0=0,cn=0;
	vector <int> cd(n);
	vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0!=c1) cn++;
			else c++;
		}
	}
	cout<<c+cn-1<<endl;
	q--;
}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;int c=0,c1=0,c0=0,cn=0;
	vector <int> cd(n);
	vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0!=c1) cn++;
			else c++;
		}
	}
	cout<<c+cn/2<<endl;
	q--;
}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;int c=0,c1=0,c0=0,cn=0;
	vector <int> cd(n);
	vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0!=c1) cn++;
			else c++;
		}
		else c++
	}
	cn-=(cn%2);
	cout<<c+cn<<endl;
	q--;
}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;int c=0,c1=0,c0=0,cn=0;
	vector <int> cd(n);
	vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0!=c1) cn++;
			else c++;
		}
		else c++;
	}
	cn-=(cn%2);
	cout<<c+cn<<endl;
	q--;
}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;int c=0,c1=0,c0=0,cn=0;
	vector <int> cd(n);
	vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0!=c1) cn++;
			else c++;
		}
	}
	cn-=(cn%2);
	cout<<c+cn<<endl;
	q--;
}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;
	int c=0,c1=0,c0=0,cee=0,ceo=0,co=0;
	// vector <int> cd(n);
	// vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0%2!=0) ceo++;
			else cee++;
		}
		else co++;
	}
	if(co==0)ceo-=(ceo%2);
	cout<<ceo+cee+co<<endl;
	q--;
}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int q,i,j,n,k;
string str;
cin>>q;
while(q>0)
{
	cin>>n;int c=0,c1=0,c0=0,cn=0,cn1=0;
	vector <int> cd(n);
	vector <int> p(n);
	for(i=0;i<n;i++)
	{
		cin>>str;
		if(str.size()%2==0)
		{
			int c0=0;c1=0;
			for(j=0;j<str.size();j++)
			{
				if(str[j]=='1') c1++;
				else c0++;
			}
			if(c0!=c1) cn++;
			else c++;
		}
		else cn1++;
	}
	if(cn1==0)cn-=(cn%2);
	cout<<c+cn+cn1<<endl;
	q--;
}
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0,flag2=0;
        int one=0,zero=0;
        while(n--){

        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(sz%2==1) flag++;
            //cout<<one<<' '<<zero<<endl;

        }

          if(one%2==0 and zero%2==0) flag++;

        if(flag)
        {
            cout<<m<<endl;
        }
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0,flag2=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==1 and zero%2==1) flag++;
            else if(one==sz and one%2==1) flag2++;
             else if(zero==sz and zero%2==1) flag2++;
           // cout<<one<<' '<<zero<<endl;
        }

        if(flag%2==1 and !flag2)
        {
            cout<<m-1<<endl;
        }
        else cout<<m<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0,flag2=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==1 and zero%2==1) flag++;
            else if(one==sz or zero==sz) flag2++;
            // else if(zero==sz ) flag2++;
           // cout<<one<<' '<<zero<<endl;
        }

        if(flag%2==0 or flag2)
        {
            cout<<m<<endl;
        }
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0,flag2=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==1 and zero%2==1) flag++;
            else if(one==sz or zero==sz) flag2++;
            else if(one%2==1 and zero%2==0) flag2++;
            else if(one%2==0 and zero%2==1) flag2++;
            // else if(zero==sz ) flag2++;
           // cout<<one<<' '<<zero<<endl;
        }

        if(flag%2==0 or flag2)
        {
            cout<<m<<endl;
        }
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=1;
         int one=0,zero=0;
        while(n--){
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==0 and zero%2==0) cnt++;
            else if((one%2==0 and zero%2==1) or(one%2==1 and zero%2==0)) cnt++;
            else if(one==sz or zero==sz) cnt++;
            if(cnt==0) flag=0;
        }

        if(flag) cout<<m<<endl;
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0,flag2=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==1 and zero%2==1) flag++;
            else if(one==sz and one%2==1) flag2++;
             else if(zero==sz and zero%2==1) flag2++;
           // cout<<one<<' '<<zero<<endl;
        }

        if(flag%2==0 or flag2)
        {
            cout<<m<<endl;
        }
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0,flag2=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==0 and zero%2==0) flag++;
            if(sz%2==1) flag++;

        }

        if(flag)
        {
            cout<<m<<endl;
        }
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0;
         int one=0,zero=0;
        while(n--){
        char ch[100];
        scanf(" %[^\n]",ch);

        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

        }

            if(one%2==0 and zero%2==0) cnt++;
            else if((one%2==0 and zero%2==1) or(one%2==1 and zero%2==0)) cnt++;
            else if(one==m or zero==m) cnt++;

        if(cnt) cout<<m<<endl;
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0;
         int one=0,zero=0;
        while(n--){
        char ch[100];
        scanf(" %[^\n]",ch);

        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

        }

            if(one%2==0 and zero%2==0) cnt++;
            else if((one%2==0 and zero%2==1) or(one%2==1 and zero%2==0)) cnt++;
            else if(one==zero) cnt++;

        if(cnt) cout<<m<<endl;
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==1 and zero%2==1) flag++;
           // cout<<one<<' '<<zero<<endl;
        }

        if(flag%2==0) cout<<m<<endl;
        else cout<<m-1<<endl;

    }
}


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

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int m=n;
        int cnt=0,flag=0;

        while(n--){
           int one=0,zero=0;
        char ch[100];
        scanf(" %[^\n]",ch);
        int sz=strlen(ch);
        for(int i=0;i<strlen(ch);i++)
        {
            if(ch[i]=='1') one++;
            else zero++;
        }

            if(one%2==1 and zero%2==1) flag++;
            else if(one==sz and one%2==1 and sz>1) flag++;
             else if(zero==sz and zero%2==1 and sz>1) flag++;
           // cout<<one<<' '<<zero<<endl;
        }

        if(flag%2==0) cout<<m<<endl;
        else cout<<m-1<<endl;

    }
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;

const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int dp[2][maxn][maxn];
vector<pair<int,pii> > nd[51];

void init()
{
	_rep(i,1,50)
	{
		pii tp;
		int up=i;
		int t = i&1;
		if(up&1)up--;
		for(int j=0;j<=up;j+=2)
		{
			nd[i].pb({up,{j,up-j+t}});
			if(t)
				nd[i].pb({up,{j+t,up-j}});
		}
		sort(all(nd[i]));
	}
}

int main()
{

	IO;
	int q;
	init();
	cin>>q;
	while(q--)
	{
		int n;
		cin>>n;
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			string s;
			cin>>s;
			len[i] =s.length();
			_for(j,0,len[i])
				cnt[s[j]-'0']++;
		}
		_rep(i,0,cnt[0])
			_rep(j,0,cnt[1]) dp[1][i][j] = dp[0][i][j] = 0;
		int t=0;
		int ans=0;
		_for(i,0,n)
		{
			_rep(j,0,cnt[0])
				_rep(k,0,cnt[1]) dp[t^1][j][k] = dp[t][j][k];
			_rep(j,0,cnt[0])
			{
				_rep(k,0,cnt[1])
				{
					for(auto x:nd[len[i]])
					{
						if(j<x.sc.fr||k<x.sc.sc)continue;
						int& ks = dp[t^1][j-x.sc.fr][k-x.sc.sc];
						ks = max(ks,dp[t][j][k]+1);
						ans = max(ks,ans);
					}
				}
			}
			t^=1;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;
typedef vector<vector<vector<int> > > viii;
const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int main()
{

	IO;
	int q;
	cin>>q;
	while(q--)
	{
		int n;
		cin>>n;
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			string s;
			cin>>s;
			len[i] =s.length();
			_for(j,0,len[i])
				cnt[s[j]-'0']++;
		}
		sort(all(len));
		int ans=0;
		_for(i,0,n)
		{
			if(len[i]&1)
			{
				if(cnt[0]&1)cnt[0]--;
				else
				{
					if(cnt[1]&1)cnt[1]--;
					else
					{
						if(cnt[1]==0&&cnt[0]==0)break;
						else
						{
							if(cnt[0])cnt[0]--;
							else cnt[1]--;
						}
					}
				}
				len[i]--;
			}
			if(len[i]/2>cnt[1]/2+cnt[0]/2)break;
			int yu1 = len[i]/2;
			int ff=2*min(yu1,cnt[0]/2);
			len[i]-=ff,cnt[0]-=ff;
			yu1 = len[i]/2;
			int ne=2*min(yu1,cnt[1]/2);
			len[i]-=ne,cnt[1]-=ne;
			if(len[i]==0)ans++;
			else break;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;

const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int dp[2][maxn][maxn];
vector<pii> nd[51];

void init()
{
	_rep(i,1,50)
	{
		pii tp;
		int up=i;
		int t = i&1;
		if(up&1)up--;
		for(int j=0;j<=up;j+=2)
		{
			nd[i].pb({j,up-j+t});
			if(t)
				nd[i].pb({j+t,up-j});
		}
	}
}

int main()
{
	IO;
	int q;
	cin>>q;
	init();
	while(q--)
	{
		int n;
		cin>>n;
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			string s;
			cin>>s;
			len[i] = s.length();
			_for(j,0,s.length())
				cnt[s[j]-'0']++;
		}
		_rep(i,0,cnt[0])
			_rep(j,0,cnt[1]) dp[1][i][j] = dp[0][i][j] = 0;
		int t=0;
		int ans=0;
		_for(i,0,n)
		{
			_rep(j,0,cnt[0])
				_rep(k,0,cnt[1]) dp[t^1][j][k] = dp[t][j][k];
			_rep(j,0,cnt[0])
			{
				_rep(k,0,cnt[1])
				{
					for(auto x:nd[len[i]])
					{
						if(j<x.fr||k<x.sc)continue;
						int& ks = dp[t^1][j-x.fr][k-x.sc];
						ks = max(ks,dp[t][j][k]+1);
						ans = max(ks,ans);
					}
				}
			}
			t^=1;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;

const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int dp[2][maxn][maxn];
vector<pii> nd[51];

void init()
{
	_rep(i,1,50)
	{
		pii tp;
		int up=i;
		int t = i&1;
		if(up&1)up--;
		for(int j=0;j<=up;j+=2)
		{
			nd[i].pb({j,up-j+t});
			if(t)
				nd[i].pb({j+t,up-j});
		}
	}
}

char s[200];
int main()
{
	int q;
	sc1(q);
	init();
	while(q--)
	{
		int n;
		cin>>n;
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			string s;
			scanf("%s",s);
			len[i] = strlen(s);
			_for(j,0,len[i])
				cnt[s[j]-'0']++;
		}
		_rep(i,0,cnt[0])
			_rep(j,0,cnt[1]) dp[1][i][j] = dp[0][i][j] = 0;
		int t=0;
		int ans=0;
		_for(i,0,n)
		{
			_rep(j,0,cnt[0])
				_rep(k,0,cnt[1]) dp[t^1][j][k] = dp[t][j][k];
			_rep(j,0,cnt[0])
			{
				_rep(k,0,cnt[1])
				{
					for(auto x:nd[len[i]])
					{
						if(j<x.fr||k<x.sc)continue;
						int& ks = dp[t^1][j-x.fr][k-x.sc];
						ks = max(ks,dp[t][j][k]+1);
						ans = max(ks,ans);
					}
				}
			}
			t^=1;
		}
		printf("%d\n",ans);
	}
	return 0;
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;

const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int dp[2][maxn][maxn];
vector<pair<int,pii> > nd[51];

void init()
{
	_rep(i,1,50)
	{
		pii tp;
		int up=i;
		int t = i&1;
		if(up&1)up--;
		for(int j=0;j<=up;j+=2)
		{
			nd[i].pb({up,{j,up-j+t}});
			if(t)
				nd[i].pb({up,{j+t,up-j}});
		}
		sort(all(nd[i]));
	}
}

int main()
{

	IO;
	int q;
	init();
	cin>>q;
	while(q--)
	{
		int n;
		cin>>n;
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			string s;
			cin>>s;
			len[i] =s.length();
			_for(j,0,len[i])
				cnt[s[j]-'0']++;
		}
		_rep(i,0,cnt[0])
			_rep(j,0,cnt[1]) dp[1][i][j] = dp[0][i][j] = 0;
		int t=0;
		int ans=0;
		_for(i,0,n)
		{
			_rep(j,0,cnt[0])
				_rep(k,0,cnt[1]) dp[t^1][j][k] = dp[t][j][k];
			_rep(j,0,cnt[0])
			{
				_rep(k,0,cnt[1])
				{
					for(auto x:nd[len[i]])
					{
						if(j<x.sc.fr||k<x.sc.sc)continue;
						int& ks = dp[t^1][j-x.sc.fr][k-x.sc.sc];
						ks = max(ks,dp[t][j][k]+1);
						ans = max(ks,ans);
					}
				}
			}
			t^=1;
		}
		printf("%d\n",ans);
	}
	return 0;
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;
typedef vector<vector<vector<int> > > viii;
const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int main()
{

	IO;
	int q;
	cin>>q;
	while(q--)
	{
		int n;
		cin>>n;
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			string s;
			cin>>s;
			len[i] =s.length();
			_for(j,0,len[i])
				cnt[s[j]-'0']++;
		}
		sort(all(len));
		int ans=0;
		_for(i,0,n)
		{
			if(len[i]&1)
			{
				if(cnt[0]&1)cnt[0]--;
				else
				{
					if(cnt[1]&1)cnt[1]--;
					else
					{
						if(cnt[1]==0&&cnt[0]==0)break;
						else
						{
							if(cnt[0]>cnt[1])cnt[1]--;
							else cnt[0]--;
						}
					}
				}
				len[i]--;
			}
			if(len[i]/2>cnt[1]/2+cnt[0]/2)break;
			int yu1 = len[i]/2;
			int ff=2*min(yu1,cnt[0]/2);
			len[i]-=ff,cnt[0]-=ff;
			yu1 = len[i]/2;
			int ne=2*min(yu1,cnt[1]/2);
			len[i]-=ne,cnt[1]-=ne;
			if(len[i]==0)ans++;
			else break;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

#define sc1(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define _rep(i,a,b) for(int i = (a);i<=(b);++i)
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _dep(i,a,b) for(int i = (a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()

typedef pair<int,int> pii;
typedef long long LL;

const int apsz = 26;
const LL o = 1;
const int maxn = 2507;

int dp[2][maxn][maxn];
vector<pair<int,pii> > nd[51];

void init()
{
	_rep(i,1,50)
	{
		pii tp;
		int up=i;
		int t = i&1;
		if(up&1)up--;
		for(int j=0;j<=up;j+=2)
		{
			nd[i].pb({up,{j,up-j+t}});
			if(t)
				nd[i].pb({up,{j+t,up-j}});
		}
		sort(all(nd[i]));
	}
}

char s[200];
int main()
{
	int q;
	sc1(q);
	init();
	while(q--)
	{
		int n;
		sc1(n);
		vector<int> len(n);
		vector<int> cnt(2,0);
		_for(i,0,n)
		{
			scanf("%s",s);
			len[i] = strlen(s);
			_for(j,0,len[i])
				cnt[s[j]-'0']++;
		}
		_rep(i,0,cnt[0])
			_rep(j,0,cnt[1]) dp[1][i][j] = dp[0][i][j] = 0;
		int t=0;
		int ans=0;
		_for(i,0,n)
		{
			_rep(j,0,cnt[0])
				_rep(k,0,cnt[1]) dp[t^1][j][k] = dp[t][j][k];
			_rep(j,0,cnt[0])
			{
				_rep(k,0,cnt[1])
				{
					for(auto x:nd[len[i]])
					{
						if(j<x.sc.fr||k<x.sc.sc)continue;
						int& ks = dp[t^1][j-x.sc.fr][k-x.sc.sc];
						ks = max(ks,dp[t][j][k]+1);
						ans = max(ks,ans);
					}
				}
			}
			t^=1;
		}
		printf("%d\n",ans);
	}
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
#define int long long
int getSum(string n)
    {
    int sum = 0;
   for(int i=0;i<n.size();i++)
   if(n[i]=='1')
   sum++;
 return sum;
 }

int32_t main(){
int t;
cin>>t;
while(t--){
	int n,i,len,f=0,ones;
	cin>>n;
	string s[n];
	for(i=0;i<n;i++){
		cin>>s[i];
		len=s[i].size();
		if(len%2==1)
		f=1;
		ones+=getSum(s[i]);
	}
	if(f==1){
		cout<<n<<'\n';
		continue;
	}
	else if(ones%2==1){
		cout<<n-1<<'\n';
		continue;
	}
	else
	cout<<n<<'\n';
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e4+9;
const double ep=1e-7;
const int mod=998244353;
const double pi=acos(-1);
const int INF=-1e9;
#define mk make_pair
#define PII pair<int,int>
#define PIII pair<int,PII >
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define eb emplace_back
typedef long long ll;
int n,d,p[maxn],ans,ma;
int dp[maxn][509];
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=1,a;i<=n;i++)scanf("%d",&a),p[a]++,ma=max(ma,a);
	for(int i=0;i<=ma;i++)for(int j=0;j<=502;j++)dp[i][j]=-1e9;
	dp[d][250]=p[d];
	for(int i=1;i<=ma;i++)
	{
		for(int j=1;j<=500;j++)
		{
			int pre=i-(j+d-250);
			if(pre<0||pre>=i)continue;
			for(int k=-1;k<=1;k++)
			{
				dp[i][j]=max(dp[i][j],dp[pre][j+k]+p[i]);
				ans=max(ans,dp[i][j]);
			}
		}
	}
	printf("%d\n",ans);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 30000 + 10;
const int M = 300;
int m = 30000;
int n, d;
int dp[maxn][650];///dp[i][j] 表示位于i位置, l = d + j步
map<int, int> mp;
int solve(int i, int j){
	int pos = i + d + j;
	int ans = 0;
	if(pos <= m) ans = max(ans, dp[pos][j + M]);
	if(pos - 1 <= m && j - 1 + M >= 0){
		ans = max(ans, dp[pos - 1][j - 1 + M]);
	}
	if(pos + 1 <= m && j + 1 + M <= 600){
		ans = max(ans, dp[pos + 1][j + 1 + M]);
	}
	return ans;
}
void init(){
	for(int i = m; i >= 0; i--){
		for(int j = -300; j <= 300; j++){
			dp[i][j + M] = max(dp[i][j + M], solve(i, j) + mp[i]);
		}
	}
}
int main(){
	scanf("%d%d", &n, &d);
	int pos;
	for(int i = 1; i <= n; i++){
		scanf("%d", &pos); mp[pos]++;
	}
	init();
	printf("%d\n", max(dp[d][0 + M], max(dp[d][-1 + M], dp[d][1 + M])));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int memo[30001][500];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > max_g)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    //freopen("output.txt","r",stdin);
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    //cout << g[939] << endl;
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int memo[30001][500];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > 30000+5)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    //freopen("output.txt","r",stdin);
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    //cout << g[939] << endl;
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
short memo[30002][30002];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > max_g+1)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int memo[40010][710];
int max_g=-1;
int g[40010];

int dp(int i,int d)
{
    if(i >max_g+5 || d<=0)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    p1 = g[i] + dp(i+d+1,d+1);
    if(d!=1)  p2 = g[i] + dp(i+d-1,d-1);
    p3 = g[i] + dp(i+d,d);
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = max(max_g,x);
    }
    cout << dp(l,l) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//short int memo[30001][30000];
vector <short> memo[30002];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > max_g+1)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    for(int w=0;w<=max_g+l;w++)
    {
        memo[w].reserve(w+1);
        for(int q=0;q<=w;q++)memo[w][q]=-1;
    }
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int memo[30001][500];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > max_g+1)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
short int memo[30001][500];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > max_g+1)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
short memo[30001][30000];
int max_g;
map <int,int> g;
int dp(int i,int d)
{
    if(i > max_g+1)return 0;
    if(memo[i][d]!=-1)return memo[i][d];
    int p1=0,p2=0,p3=0;
    if(i+d+1 <= 30000 && d+1 > 0)
    {
        p1 = g[i] + dp(i+d+1,d+1);
    }
    if(i+d-1 <= 30000 && d-1 > 0)
    {
        p2 = g[i] + dp(i+d-1,d-1);
    }
    if(i+d <= 30000 && d> 0)
    {
        p3 = g[i] + dp(i+d,d);
    }
    memo[i][d] = max(p1,max(p2,p3));
    return memo[i][d];
}
int main()
{
    memset(memo,-1,sizeof(memo));
    int n,l,x;
    cin >> n >> l;
    for(int w=0; w<n; w++)
    {
        cin >> x;
        g[x]++;
        max_g = x;
    }
    int s = g[0];
    s += dp(l,l);
    cout << s << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#define IO std::ios::sync_with_stdio(false)
#define ll long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define pdd pair <double, double>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f
using namespace std;
inline int read() {
    int x = 0, neg = 1; char op = getchar();
    while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
    while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
    return neg * x;
}
inline void print(int x) {
    if (x < 0) { putchar('-'); x = -x; }
    if (x >= 10) print(x / 10);
    putchar(x % 10 + '0');
}

int mp[30007];
int dp[30007][507];

int main() {
    ios::sync_with_stdio(false);
    int ans = 0, temp, n, d, next;
    memset(mp, 0, sizeof(mp));
    memset(dp, -1, sizeof(dp));
    cin >> n >> d;

    for (int i = 0; i < n; ++i) {
        cin >> temp;
        ++mp[temp];
    }
    dp[d][250] = mp[d];
    for (int x = d; x <= 30000; ++x) {
        for (int y = 1; y <= 500; ++y) {
            next = x - d - y + 250;
            if (next < 0 || next >= x) continue;
            for (int i = -1; i <= 1; ++i) {
                if(dp[next][y + i] != -1 && d + y + i > 0)
                dp[x][y] = max(dp[x][y], dp[next][y + i] + mp[x]);
            }
            ans = max(ans, dp[x][y]);
        }
    }

    cout << ans << endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
const int maxn=3e4+5;
const int inf=0x3f3f3f3f;
int n,a[maxn],dp[maxn][505],d,ans=0;
int main()
{
	scanf("%d%d",&n,&d);
	for(int i=1,t;i<=n;++i) scanf("%d",&t),a[t]++;
	memset(dp,-inf,sizeof(dp));
	dp[d][250]=a[d];
	for(int i=1;i<=30000;++i)
	for(int j=1;j<=500;++j)
	{
		int last=i-j-d+250;
		if(last<0||last>=i) continue;
		for(int k=-1;k<=1;++k)
		if(j+k>0) dp[i][j]=max(dp[i][j],dp[last][j+k]+a[i]);
		ans=max(ans,dp[i][j]);
	}
	printf("%d\n",ans);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 30000 + 10;
int n, d, m;
int cnt[maxn];
int dp[maxn][600];
int get(int dis){
	return dis - d + 250;
}
int main(){
	scanf("%d%d", &n, &d);
	int val;
	for(int i = 1; i <= n; i++){
		scanf("%d", &val); cnt[val]++;
	}
	m = 30000;
	for(int i = m; i >= d; i--){
		for(int j = d - 250; j <= d + 250; j++){
			dp[i][get(j)] = cnt[i];
			if(i + j >= 0 && i + j <= m && i + j > i){
				dp[i][get(j)] = max(dp[i][get(j)], dp[i + j][get(j)] + cnt[i]);
			}
			if(i + j - 1 >= 0 && i + j - 1 <= m && i + j - 1 > i){
				dp[i][get(j)] = max(dp[i][get(j)], dp[i + j - 1][get(j - 1)] + cnt[i]);
			}
			if(i + j + 1 >= 0 && i + j + 1 <= m && i + j + 1 > i){
				dp[i][get(j)] = max(dp[i][get(j)], dp[i + j + 1][get(j + 1)] + cnt[i]);
			}
		}
	}
	printf("%d\n", dp[d][get(d)]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
#define IO std::ios::sync_with_stdio(false)
#define ll long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define pdd pair <double, double>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f
using namespace std;
inline int read() {
    int x = 0, neg = 1; char op = getchar();
    while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
    while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
    return neg * x;
}
inline void print(int x) {
    if (x < 0) { putchar('-'); x = -x; }
    if (x >= 10) print(x / 10);
    putchar(x % 10 + '0');
}

int mp[30007];
int dp[30007][507];

int main() {
    ios::sync_with_stdio(false);
    int ans = 0, temp, n, d, next;
    memset(mp, 0, sizeof(mp));
    memset(dp, -1, sizeof(dp));
    cin >> n >> d;

    for (int i = 0; i < n; ++i) {
        cin >> temp;
        ++mp[temp];
    }
    dp[d][250] = mp[d];
    for (int x = d; x <= 30000; ++x) {
        for (int y = 0; y <= 500; ++y) {
            next = x - d - y + 250;
            if (next < 0 || next >= x) continue;
            for (int i = -1; i <= 1; ++i) {
                if(dp[next][y + i] != -1 && d + y + i > 0)
                dp[x][y] = max(dp[x][y], dp[next][y + i] + mp[x]);
            }
            ans = max(ans, dp[x][y]);
        }
    }

    cout << ans << endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
const int inf = 0x3f3f3f3f;
const int maxn = 30010;
const int M = 1e9+7;
int n,d,ans;

int a[maxn],dp[maxn][550];      //到第i个岛，上一步走了d+(j-250)远

signed main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>d;
    for(int i = 1,x; i <= n; i++)
    {
        cin>>x;
        a[x]++;
    }
    mem(dp,-1);dp[d][250] = a[d];
    int ans = a[d];
    for(int i = d; i<= 30000; i++)
    {
        for(int j = 1; j <= 500;j++)
        {
            if(dp[i][j] == -1) continue;
            int to = i+d+(j-250);
            //l
            dp[to][j] = max(dp[to][j],dp[i][j]+a[to]);
            ans = max(ans,dp[to][j]);
            //l-1
            if(j > 1)
            {
                dp[to-1][j-1] = max(dp[to-1][j-1],dp[i][j]+a[to-1]);
                ans = max(ans,dp[to-1][j-1]);
            }
            //l+1
            dp[to+1][j+1] = max(dp[to+1][j+1],dp[i][j]+a[to+1]);
            ans = max(ans,dp[to+1][j+1]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define all(__vv__) (__vv__).begin(), (__vv__).end()
#define endl "\n"
#define pai pair<int, int>
#define ms(__x__,__val__) memset(__x__, __val__, sizeof(__x__))
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll read() { ll s = 0, w = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') w = -1; for (; isdigit(ch); ch = getchar())	s = (s << 1) + (s << 3) + (ch ^ 48); return s * w; }
inline void print(ll x, int op = 10) { if (!x) { putchar('0'); if (op)	putchar(op); return; }	char F[40]; ll tmp = x > 0 ? x : -x;	if (x < 0)putchar('-');	int cnt = 0;	while (tmp > 0) { F[cnt++] = tmp % 10 + '0';		tmp /= 10; }	while (cnt > 0)putchar(F[--cnt]);	if (op)	putchar(op); }
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;	while (b) { if (b & 1)	ans *= a;		b >>= 1;		a *= a; }	return ans; }	ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline int lowbit(int x) { return x & (-x); }
const int dir[][2] = { {0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1} };
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

const int N = 3e4 + 7;
const int M = 500 + 7;
int dp[N][M], vis[N];

int main() {
	// vis[i] 第i座岛上的gems数量
	// dp[i][j] 用走j步的办法从前一个岛跳到第i个岛收集到的gems数量
	// 1 + 2 + 3 +……+ n = n*(n+1)/2 <= 30000
	// 最大增加的步长 n < 250
	int n = read(), d = read();
	for (int i = 1; i <= n; ++i) {
		int x = read();
		++vis[x];
	}
	ms(dp, -1);
	dp[d][250] = vis[d]; //把负数补正，250代表0步
	int ans = vis[d];
	for (int i = d; i <= 30000; ++i) {
		for (int j = 1; j <= 500; ++j) {
			if (dp[i][j] == -1)	continue; //无法到达直接跳过
			int ed = i + d + j - 250;
			if (ed <= 30000) {
				dp[ed][j] = max(dp[ed][j], dp[i][j] + vis[ed]);
				ans = max(ans, dp[ed][j]);
			}
			if (ed + 1 <= 30000) {
				dp[ed + 1][j + 1] = max(dp[ed + 1][j + 1], dp[i][j] + vis[ed + 1]);
				ans = max(ans, dp[ed + 1][j + 1]);
			}
			if (ed - 1 <= 30000 and ed - 1 > i) {
				dp[ed - 1][j - 1] = max(dp[ed - 1][j - 1], dp[i][j] + vis[ed - 1]);
				ans = max(ans, dp[ed - 1][j - 1]);
			}
		}
	}
	print(ans);
	return 0;
}


#include<iostream>
#include<map>
#include<cassert>
#include<vector>

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf_s("%d %d", &n, &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf_s("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf_s("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<stdio.h>
#include<map>
#include<cassert>
#include<vector>

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf("%d", &n);
    scanf("%d", &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<iostream>
#include<map>
#include<cassert>
#include<vector>

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf("%d %d", &n, &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<map>
#include<cassert>
#include<vector>
#include<cstdio>
using namespace std;

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf_s("%d", &n);
    scanf_s("%d", &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf_s("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf_s("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<stdio.h>
#include<iostream>
#include <iomanip>
#include<map>
#include<cassert>
#include<vector>

int begin = -1;
int max = 10000;
std::map<int, int> gems;
//std::map<int, std::map<int, long>> dp;
int dp[30001][501];

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current][l - begin] != -1)
        return dp[current][l - begin];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        //if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
        //  temp = dp[current + i][i];
        //}
        //else {
            temp = calc(current + i, i);
        //}

        if (temp > found2)
            found2 = temp;
    }
    //dp[current].emplace(l, (found + found2));
    return dp[current][l - begin ] = (found + found2);
}

int main() {

    ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0);
    int n, d;
    //scanf("%d", &n);
    //scanf("%d", &d);
    std::cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        int x;
        //scanf("%d", &x);
        std::cin >> x;
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < 30001; i++) {
        for (int j = 0; j < 501; j++) {
            dp[i][j] = -1;
        }
    }

    begin = d - 250;
    //printf("%d\n", calc(d, d));
    std::cout << calc(d, d) << std::endl;

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<stdio.h>
#include<map>
#include<cassert>
#include<vector>

int begin = -1;
int max = 10000;
std::map<int, int> gems;
//std::map<int, std::map<int, long>> dp;
int dp[30001][491];

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current][l - begin] != -1)
        return dp[current][l - begin];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        //if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
        //  temp = dp[current + i][i];
        //}
        //else {
            temp = calc(current + i, i);
        //}

        if (temp > found2)
            found2 = temp;
    }
    //dp[current].emplace(l, (found + found2));
    return dp[current][l - begin ] = (found + found2);
}

int main() {

    int n, d;
    scanf("%d", &n);
    scanf("%d", &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < 30001; i++) {
        for (int j = 0; j < 491; j++) {
            dp[i][j] = -1;
        }
    }

    begin = d - 245;
    printf("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<map>
#include<cassert>
#include<vector>
#include<cstdio>

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf_s("%d", &n);
    scanf_s("%d", &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf_s("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf_s("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<stdio.h>
#include<map>
#include<cassert>
#include<vector>

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf_s("%d", &n);
    scanf_s("%d", &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf_s("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf_s("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<map>
#include<cassert>
#include<vector>

int max = 10000;
std::map<int, int> gems;
std::map<int, std::map<int, long>> dp;

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current].find(l) != dp[current].end())
        return dp[current][l];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
            temp = dp[current + i][i];
        }
        else {
            temp = calc(current + i, i);
        }

        if (temp > found2)
            found2 = temp;
    }
    dp[current].emplace(l, (found + found2));
    return (found + found2);
}

int main() {

    int n, d;
    scanf_s("%d %d", &n, &d);
    for (int i = 1; i <= n; i++) {
        int x;
        scanf_s("%d", &x);
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < max + 1; i++) {
        std::map<int, long> data;
        dp.emplace(i, data);
    }

    printf_s("%d\n", calc(d, d));

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<map>
#include<cassert>
#include<vector>

int begin = -1;
int max = 10000;
std::map<int, int> gems;
//std::map<int, std::map<int, long>> dp;
int dp[30001][501];

long long calc(int current, int l) {
    if (current > max)
        return 0;
    if (dp[current][l - begin] != -1)
        return dp[current][l - begin];
    long long found = 0;
    if (gems.find(current) != gems.end())
        found += gems[current];
    long long found2 = 0;
    for (int i = l - 1; i <= l + 1; i++) {
        if (i == 0)
            continue;
        long long temp;
        //if (dp.find(current + i) != dp.end() && dp[current + i].find(i) != dp[current + i].end()) {
        //  temp = dp[current + i][i];
        //}
        //else {
            temp = calc(current + i, i);
        //}

        if (temp > found2)
            found2 = temp;
    }
    //dp[current].emplace(l, (found + found2));
    return dp[current][l - begin ] = (found + found2);
}

int main() {

    ios_base::sync_with_stdio(0); cout.precision(15); cout << fixed; cout.tie(0);
    int n, d;
    //scanf("%d", &n);
    //scanf("%d", &d);
    std::cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        int x;
        //scanf("%d", &x);
        std::cin >> x;
        if (gems.find(x) != gems.end()) {
            int v = gems[x];
            gems[x] = ++v;
        }
        else {
            gems[x] = 1;
        }
        if (i == n)
            max = x;
    }

    for (int i = 0; i < 30001; i++) {
        for (int j = 0; j < 501; j++) {
            dp[i][j] = -1;
        }
    }

    begin = d - 250;
    //printf("%d\n", calc(d, d));
    std::cout << calc(d, d) << std::endl;

    // check if key is present
    //if (m.find("world") != m.end())
    //cout << m["hello"] << '\n';
    //std::map<std::string, int>::iterator i = m.find("hello");
    //assert(i != m.end());
    //cout << "Value: " << i->second << '\n';

    //system("pause");
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 30000+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][400];
bool seen[MAX_N][400];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    int k = max(1,d-180);
    dp[d][d-k] = cnt[d];
    seen[d][d-k] = true;
    for(int i = 1;i<=mx;++i)
    {
        for(int j = 0;j<400;++j)
        {
            int m = j + k;
            if (!seen[i][j])
                continue;
            ans = max(ans,dp[i][j]);
            if (i+m-1>mx)
                break;
            dp[i+m][j] = max(dp[i+m][j],dp[i][j]+cnt[i+m]);
            ans = max(ans,dp[i+m][j]);
            seen[i+m][j] = true;
            dp[i+m+1][j+1] = max(dp[i+m+1][j+1],dp[i][j]+cnt[i+m+1]);
            if (i+m-1>0)
                seen[i+m-1][j-1] = true;
            if (i+m-1>0)
                ans = max(ans,dp[i+m-1][j-1]);
            if (i+m-1>0)
                dp[i+m-1][j-1] = max(dp[i+m-1][j-1],dp[i][j]+cnt[i+m-1]);
            seen[i+m+1][j+1] = true;
            ans = max(ans,dp[i+m+1][j+1]);
        }
    }
    cout << ans;
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 30000+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][400];
bool seen[MAX_N][400];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    int k = max(1,d-180);
    dp[d][d-k] = cnt[d];
    seen[d][d-k] = true;
    for(int i = 1;i<=mx;++i)
    {
        for(int j = 0;j<400;++j)
        {
            int m = j + k;
            if (!seen[i][j])
                continue;
            ans = max(ans,dp[i][j]);
            if (i+m-1>mx)
                break;
            dp[i+m][j] = max(dp[i+m][j],dp[i][j]+cnt[i+m]);
            ans = max(ans,dp[i+m][j]);
            seen[i+m][j] = true;
            dp[i+m+1][j+1] = max(dp[i+m+1][j+1],dp[i][j]+cnt[i+m+1]);
            if (i+m-1>0 and j-1>=0)
                seen[i+m-1][j-1] = true;
            if (i+m-1>0 and j-1>=0)
                ans = max(ans,dp[i+m-1][j-1]);
            if (i+m-1>0 and j-1>=0)
                dp[i+m-1][j-1] = max(dp[i+m-1][j-1],dp[i][j]+cnt[i+m-1]);
            seen[i+m+1][j+1] = true;
            ans = max(ans,dp[i+m+1][j+1]);
        }
    }
    cout << ans;
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 40000+100;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][610];
bool seen[MAX_N][610];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    int k = max(1,d-300);
    dp[d][d-k] = cnt[d];
    seen[d][d-k] = true;
    for(int i = 1;i<=mx;++i)
    {
        for(int j = 0;j<600;++j)
        {
            int m = j + k;
            if (!seen[i][j])
                continue;
            ans = max(ans,dp[i][j]);
            if (i+m-1>mx)
                break;
            dp[i+m][j] = max(dp[i+m][j],dp[i][j]+cnt[i+m]);
            ans = max(ans,dp[i+m][j]);
            seen[i+m][j] = true;
            dp[i+m+1][j+1] = max(dp[i+m+1][j+1],dp[i][j]+cnt[i+m+1]);
            if (i+m-1>0 and j-1>=0)
                seen[i+m-1][j-1] = true;
            if (i+m-1>0 and j-1>=0)
                ans = max(ans,dp[i+m-1][j-1]);
            if (i+m-1>0 and j-1>=0)
                dp[i+m-1][j-1] = max(dp[i+m-1][j-1],dp[i][j]+cnt[i+m-1]);
            seen[i+m+1][j+1] = true;
            ans = max(ans,dp[i+m+1][j+1]);
        }
    }
    cout << ans;
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 30000+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][400];
bool seen[MAX_N][400];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    int k = max(1,d-180);
    dp[d][d-k] = cnt[d];
    seen[d][d-k] = true;
    for(int i = 1;i<=mx;++i)
    {
        for(int j = 0;j<400;++j)
        {
            int m = j + k;
            if (!seen[i][j])
                continue;
            ans = max(ans,dp[i][j]);
            if (i+m-1>mx)
                break;
            dp[i+m][j] = max(dp[i+m][j],dp[i][j]+cnt[i+m]);
            ans = max(ans,dp[i+m][j]);
            seen[i+m][j] = true;
            dp[i+m+1][j+1] = max(dp[i+m+1][j+1],dp[i][j]+cnt[i+m+1]);
            seen[i+m+1][j+1] = true;
            ans = max(ans,dp[i+m+1][j+1]);
            if (i+m-1>0)
            {
                dp[i+m-1][j-1] = max(dp[i+m-1][j-1],dp[i][j]+cnt[i+m-1]);
                seen[i+m-1][j-1] = true;
                ans = max(ans,dp[i+m-1][j-1]);
            }
        }
    }
    cout << ans;
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 1e5+5;
const ll MOD = 1e9+7;
using namespace std;

map<int,int> dp[MAX_N];
set<int> st[MAX_N];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    dp[d][d] = cnt[d];
    st[d].insert(d);
    for(int i = 1;i<=mx;++i)
    {
        if (!st[i].size())
            continue;
        for(auto x:st[i])
        {
            ans = max(ans,dp[i][x]);
            int a1 = x-1;
            int a2 = a1+1;
            int a3 = a2+1;
            if (!st[i+a1].count(a1))
                st[i+a1].insert(a1);
            if (!st[i+a2].count(a2))
                st[i+a2].insert(a2);
            if (!st[i+a3].count(a3))
                st[i+a3].insert(a3);
            dp[i+a1][a1] = max(dp[i+a1][a1],dp[i][x]+cnt[i+a1]);
            dp[i+a2][a2] = max(dp[i+a2][a2],dp[i][x]+cnt[i+a2]);
            dp[i+a3][a3] = max(dp[i+a3][a3],dp[i][x]+cnt[i+a3]);
        }
        st[i].clear();
    }
    cout << ans;
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 30000+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][400];
bool seen[MAX_N][400];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    int k = max(1,d-180);
    dp[d][d-k] = cnt[d];
    seen[d][d-k] = true;
    for(int i = 1;i<=mx;++i)
    {
        for(int j = 0;j<400;++j)
        {
            int m = j + k;
            if (!seen[i][j])
                continue;
            ans = max(ans,dp[i][j]);
            if (i+m-1>mx)
                break;
            dp[i+m][j] = max(dp[i+m][j],dp[i][j]+cnt[i+m]);
            ans = max(ans,dp[i+m][j]);
            seen[i+m][j] = true;
            dp[i+m+1][j+1] = max(dp[i+m+1][j+1],dp[i][j]+cnt[i+m+1]);
            if (i+m-1>0 and j-1>0)
                seen[i+m-1][j-1] = true;
            if (i+m-1>0 and j-1>0)
                ans = max(ans,dp[i+m-1][j-1]);
            if (i+m-1>0 and j-1>0)
                dp[i+m-1][j-1] = max(dp[i+m-1][j-1],dp[i][j]+cnt[i+m-1]);
            seen[i+m+1][j+1] = true;
            ans = max(ans,dp[i+m+1][j+1]);
        }
    }
    cout << ans;
    return 0;
}


// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 30000+5;
const ll MOD = 1e9+7;
using namespace std;

int dp[MAX_N][400];
bool seen[MAX_N][400];
int n;
int d;
int cnt[MAX_N];
int ans;

int main()
{
    cin >> n >> d;
    int mx = 0;
    for(int i = 1;i<=n;++i)
    {
        int p;
        cin >> p;
        cnt[p]++;
        mx = max(mx,p);
    }
    int k = max(1,d-180);
    dp[d][d-k] = cnt[d];
    seen[d][d-k] = true;
    for(int i = 1;i<=mx;++i)
    {
        for(int j = 0;j<400;++j)
        {
            int m = j + k;
            if (!seen[i][j])
                continue;
            ans = max(ans,dp[i][j]);
            if (i+m-1>mx)
                break;
            dp[i+m][j] = max(dp[i+m][j],dp[i][j]+cnt[i+m]);
            ans = max(ans,dp[i+m][j]);
            seen[i+m][j] = true;
            dp[i+m+1][j+1] = max(dp[i+m+1][j+1],dp[i][j]+cnt[i+m+1]);
            seen[i+m-1][j-1] = true;
            ans = max(ans,dp[i+m-1][j-1]);
            dp[i+m-1][j-1] = max(dp[i+m-1][j-1],dp[i][j]+cnt[i+m-1]);
            seen[i+m+1][j+1] = true;
            ans = max(ans,dp[i+m+1][j+1]);
        }
    }
    cout << ans;
    return 0;
}