import sys input = sys.stdin.buffer.readline n,k,p = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = [0]*p for i in range(n): c[b[i]] += 1 for i in range(p-1): c[i+1] += c[i] l,r = -1,p while r-l>1: m = (l+r)//2 cnt = 0 for i in range(n): cnt += c[min(p-1,m+p-a[i]-1)]-c[p-a[i]-1] if m>=a[i]+1: cnt += c[m-a[i]-1] if cnt