线性基+贪心。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1050
using namespace std;
struct person
{
    long long a,b;
}p[maxn];
long long n,ins[65],ans=0;
bool cmp(person x,person y)
{
    return x.b>y.b;
}
int main()
{
    scanf("%lld",&n);
    for (long long i=1;i<=n;i++)
        scanf("%lld%lld",&p[i].a,&p[i].b);
    sort(p+1,p+n+1,cmp);
    for (long long i=1;i<=n;i++)
    {
        for (long long j=63;j>=0;j--)
        {
            if ((p[i].a>>j)&1)
            {
                if (!ins[j])
                {
                    ins[j]=p[i].a;
                    break;
                }
                else p[i].a^=ins[j];
            }
        }
        if (p[i].a) ans+=p[i].b;
    }
    printf("%lld\n",ans);
    return 0;
}