#include using namespace std; #define rep(i, a, b) for(int i=a; i<(b); i++) #define all(x) begin(x), end(x) #define sz(x) (int) (x).size() #define fo(i, n) rep(i, 0, n) #define F first #define S second #define MP make_pair typedef long long ll; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vll; using uc = unsigned char; const int NMAX = 112345; const int LOGMAX = 25; int ra[NMAX]; int hb[NMAX]; int na, nb, m; int lens[2<<8][2<<8]; int counts[2<<8]; ll out=0; const int S = 1<<8; int pc[1<<8]; bool edge(int a, int b) { if((a>>8) == (b>>8)) return false; if((a>>8)) return edge(b, a); return pc[a & b]%2; } const int MAX = 10000; void calc() { out = 0; fo(i,2<<8) { fo(j,2<<8) lens[i][j]=MAX; fo(len,2<<8) { fo(j, 2<<8) if(len==0?i==j:lens[i][j]==len) { fo(k, 2<<8) { if(edge(j, k) && counts[j] && counts[k]) lens[i][k] = min(lens[i][k], len+1); } } } fo(j,2<<8) if(lens[i][j]==MAX) lens[i][j]=0; fo(j,i) out += counts[i]*counts[j]*lens[i][j]; out += counts[i]*(counts[i]-1)/2*lens[i][i]; } } void add(int i) { if(counts[i]) { fo(j, 2<<8) { out += counts[j] * lens[i][j]; } counts[i]++; } else { counts[i]++; calc(); } } int main() { fo(i, 1<<8) pc[i] = (i>>0)%2 + (i>>1)%2 + (i>>2)%2 + (i>>3)%2 + (i>>4)%2 + (i>>5)%2 + (i>>6)%2 + (i>>7)%2 + (i>>8)%2; scanf("%d%d%d", &na, &nb,&m); fo(i,na) ra[i] = 1<