1 /************************************************************** 2 Problem: 2460 3 User: idy002 4 Language: C++ 5 Result: Accepted 6 Time:68 ms 7 Memory:832 kb 8 ****************************************************************/ 9 10 #include <cstdio> 11 #include <algorithm> 12 #define N 1010 13 using namespace std; 14 15 typedef unsigned long long dnt; 16 17 struct Pair { 18 dnt v; 19 int w; 20 void read() { scanf( "%llu%d", &v, &w ); } 21 bool operator<( const Pair &p ) const { return w<p.w; } 22 }; 23 24 int n; 25 Pair prs[N]; 26 dnt a[N], b[N]; int tot; 27 28 bool ok() { 29 for( int i=0; i<tot; i++ ) 30 b[i] = a[i]; 31 for( int i=60,j=0; i>=0 && j<tot; i-- ) { 32 for( int k=j; k<tot; k++ ) 33 if( (b[k]>>i) & 1 ) { 34 swap( b[k], b[j] ); 35 break; 36 } 37 if( (b[j]>>i)==1 ) { 38 for( int k=j+1; k<tot; k++ ) 39 if( (b[k]>>i) & 1 ) { 40 b[k] ^= b[j]; 41 if( b[k]==0 ) return false; 42 } 43 j++; 44 } 45 } 46 return true; 47 } 48 int main() { 49 scanf( "%d", &n ); 50 for( int i=1; i<=n; i++ ) 51 prs[i].read(); 52 sort( prs+1, prs+1+n ); 53 int ans = 0; 54 for( int i=n; i>=1; i-- ) { 55 a[tot++] = prs[i].v; 56 if( ok() ) { 57 ans += prs[i].w; 58 } else { 59 tot--; 60 } 61 } 62 printf( "%d ", ans ); 63 }