It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.

You are given two polynomials $f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1}$ and $g(x) = b_0 + b_1x + \dots + b_{m-1}x^{m-1}$, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to $1$ for both the given polynomials. In other words, $gcd(a_0, a_1, \dots, a_{n-1}) = gcd(b_0, b_1, \dots, b_{m-1}) = 1$. Let $h(x) = f(x)\cdot g(x)$. Suppose that $h(x) = c_0 + c_1x + \dots + c_{n+m-2}x^{n+m-2}$. 

You are also given a prime number $p$. Professor R challenges you to find any $t$ such that $c_t$ isn't divisible by $p$. He guarantees you that under these conditions such $t$ always exists. If there are several such $t$, output any of them.

As the input is quite large, please use fast input reading methods.


-----Input-----

The first line of the input contains three integers, $n$, $m$ and $p$ ($1 \leq n, m \leq 10^6, 2 \leq p \leq 10^9$),  — $n$ and $m$ are the number of terms in $f(x)$ and $g(x)$ respectively (one more than the degrees of the respective polynomials) and $p$ is the given prime number.

It is guaranteed that $p$ is prime.

The second line contains $n$ integers $a_0, a_1, \dots, a_{n-1}$ ($1 \leq a_{i} \leq 10^{9}$) — $a_i$ is the coefficient of $x^{i}$ in $f(x)$.

The third line contains $m$ integers $b_0, b_1, \dots, b_{m-1}$ ($1 \leq b_{i} \leq 10^{9}$)  — $b_i$ is the coefficient of $x^{i}$ in $g(x)$.


-----Output-----

Print a single integer $t$ ($0\le t \le n+m-2$)  — the appropriate power of $x$ in $h(x)$ whose coefficient isn't divisible by the given prime $p$. If there are multiple powers of $x$ that satisfy the condition, print any.


-----Examples-----
Input
3 2 2
1 1 2
2 1

Output
1

Input
2 2 999999937
2 1
3 1

Output
2


-----Note-----

In the first test case, $f(x)$ is $2x^2 + x + 1$ and $g(x)$ is $x + 2$, their product $h(x)$ being $2x^3 + 5x^2 + 3x + 2$, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.

In the second test case, $f(x)$ is $x + 2$ and $g(x)$ is $x + 3$, their product $h(x)$ being $x^2 + 5x + 6$, so the answer can be any of the powers as no coefficient is divisible by the given prime.

Difficulty: MEDIUM_HARD
Tags: Sorting

Mathematics

Constructive algorithms
Skill types: Sorting

Starter code:

Solutions:
import os
import sys
from atexit import register
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = list(map(int, input().split()))
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
k = 0
for a in As:
	if a % p:
		break
	k += 1
l = 0
for b in Bs:
	if b % p:
		break
	l += 1
print(l + k)


import sys
input = sys.stdin.buffer.readline

def main():
	(n, m, p) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	for (i, a) in enumerate(A):
		if a % p != 0:
			break
	for (j, b) in enumerate(B):
		if b % p != 0:
			break
	print(i + j)
main()


(n, m, p) = map(int, input().split(' '))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
while a[i] % p == 0:
	i += 1
while b[j] % p == 0:
	j += 1
print(i + j)


(n, m, p) = map(int, input().split())
arr_1 = list(map(int, input().split()))
arr_2 = list(map(int, input().split()))
for i in range(n):
	if arr_1[i] % p != 0:
		d1 = i
		break
for j in range(m):
	if arr_2[j] % p != 0:
		d2 = j
		break
print(d1 + d2)


import sys

def neo():
	return list(map(int, sys.stdin.readline().strip().split()))

def neo1():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m, p) = neo1()
(A, B) = (neo(), neo())
i = 0
j = 0
while A[i] % p == 0:
	i += 1
while B[j] % p == 0:
	j += 1
print(i + j)


(m, n, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k1 = 0
k2 = 0
for i in range(len(a)):
	if a[i] % p != 0:
		k1 = i
		break
for i in range(len(b)):
	if b[i] % p != 0:
		k2 = i
		break
print(k1 + k2)


import sys
input = sys.stdin.readline

def main():
	(N, M, P) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = 0
	for (i, a) in enumerate(A):
		if a % P != 0:
			ans = i
			break
	for (i, b) in enumerate(B):
		if b % P != 0:
			ans += i
			break
	print(ans)
main()


import sys
(n, m, p) = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
for i in range(n):
	if a[i] % p != 0:
		temp1 = i
		break
for j in range(m):
	if b[j] % p != 0:
		temp2 = j
		break
print(temp1 + temp2)


(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	if a[i] % p != 0:
		break
for j in range(m):
	if b[j] % p != 0:
		break
print(i + j)


import sys
input = sys.stdin.buffer.readline
(n, m, p) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
i = j = 0
while x[i] % p == 0:
	i += 1
while y[j] % p == 0:
	j += 1
print(i + j)


import io, os
inp = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = map(int, inp().split())
a = list(map(int, inp().split()))
b = list(map(int, inp().split()))
ans = 0
for i in range(n):
	if a[i] % p != 0:
		ans += i
		break
for i in range(m):
	if b[i] % p != 0:
		ans += i
		break
print(ans)


from sys import stdin, stdout

def main():
	(n, m, p) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(n):
		if a[i] % p != 0:
			ind1 = i
			break
	for i in range(m):
		if b[i] % p != 0:
			ind2 = i
			break
	print(ind1 + ind2)
main()


(n, m, p) = map(int, input().split())
i = -1
fi = 0
j = -1
ji = 0

def func(s):
	global i, fi
	if fi == 0:
		i += 1
		if int(s) % p:
			fi = 1

def func2(s):
	global j, ji
	if ji == 0:
		j += 1
		if int(s) % p:
			ji = 1
list(map(func, input().split()))
list(map(func2, input().split()))
print(i + j)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	(n, m, p) = [int(s) for s in input().strip().split()]
	A = [int(s) for s in input().strip().split()]
	B = [int(s) for s in input().strip().split()]
	j = 0
	for i in range(n):
		while j < m and B[j] % p == 0:
			j += 1
		if A[i] % p != 0:
			print(i + j)
			return
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys

def input():
	return sys.stdin.readline().strip()
(n, m, p) = map(int, input().split())
i = 0
for v in map(int, input().split()):
	if v % p != 0:
		break
	i += 1
for v in map(int, input().split()):
	if v % p != 0:
		break
	i += 1
print(i)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
from math import gcd
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
(n, m, p) = Ri()
a = Ri()
b = Ri()
flag1 = -1
flag2 = -1
for i in range(n):
	if gcd(a[i], p) == 1:
		flag1 = i
		break
for i in range(m):
	if gcd(b[i], p) == 1:
		flag2 = i
		break
print(flag1 + flag2)


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	(n, m, p) = RL()
	arra = list(RL())
	arrb = list(RL())
	ta = tb = 0
	for i in range(len(arra)):
		if arra[i] % p != 0:
			ta = i
			break
	for j in range(len(arrb)):
		if arrb[j] % p != 0:
			tb = j
			break
	print(ta + tb)
main()


import os, sys
from io import BytesIO, IOBase

def main():
	(n, m, p) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	st = -1
	for i in range(min(n, m)):
		if not a[i] % p and (not b[i] % p):
			continue
		elif not a[i] % p:
			st = 0
			break
		elif not b[i] % p:
			st = 1
			break
		else:
			return 2 * i
	if st:
		for j in range(i + 1, m):
			if b[j] % p:
				return i + j
	else:
		for j in range(i + 1, n):
			if a[j] % p:
				return i + j
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
print(main())


import math
(n, m, p) = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
ans = 0
for i in range(len(arr)):
	if arr[i] % p:
		ans = i
		break
for i in range(len(brr)):
	if brr[i] % p:
		ans += i
		break
print(ans)


(n, m, p) = map(int, input().split())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
n1 = -1
n2 = -1
for i in range(n):
	if ar[i] % p != 0:
		n1 = i
		break
for i in range(m):
	if br[i] % p != 0:
		n2 = i
		break
print(n1 + n2)


(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
for i in range(n):
	if a[i] % p == 0:
		cnt1 = cnt1 + 1
	else:
		break
for i in range(m):
	if b[i] % p == 0:
		cnt2 = cnt2 + 1
	else:
		break
print(cnt1 + cnt2)


(n, m, p) = map(int, input().split())
ar1 = list(map(int, input().split()))
ar2 = list(map(int, input().split()))
(p1, p2) = (0, 0)
for i in range(len(ar1)):
	if ar1[i] % p != 0:
		p1 = i
		break
for i in range(len(ar2)):
	if ar2[i] % p != 0:
		p2 = i
		break
print(p1 + p2)


from math import *
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
k = a[0]
r = b[0]
for i in range(n):
	if a[i] % p != 0:
		k = i
		break
for i in range(m):
	if b[i] % p != 0:
		l = i
		break
print(k + l)


import sys
import math
import itertools
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ida = 0
idb = 0
for i in range(n):
	if a[i] % p != 0:
		ida = i
		break
for i in range(m):
	if b[i] % p != 0:
		idb = i
		break
print(ida + idb)


(n, m, p) = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
ans = 0
for i in range(n):
	if P[i] % p:
		ans += i
		break
for i in range(m):
	if Q[i] % p:
		ans += i
		break
print(ans)


(n, m, p) = list(map(int, input().strip().split(' ')))
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
ans = -1
for i in range(n):
	if a[i] % p != 0:
		ans = i
		break
for i in range(m):
	if b[i] % p != 0:
		ans += i
		break
print(ans)


def main():
	(n, m, p) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	i = 0
	j = 0
	for k in range(n):
		if a[k] % p != 0:
			i = k
			break
	for k in range(m):
		if b[k] % p != 0:
			j = k
			break
	ans = i + j
	print(ans)
main()


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return map(int, input().split())

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, M, P, A, B):
	for (i, a) in enumerate(A):
		if a % P != 0:
			break
	andi = i
	for (i, b) in enumerate(B):
		if b % P != 0:
			break
	bndi = i
	error_print(andi, bndi)
	return andi + bndi

def main():
	(N, M, P) = read_int_n()
	A = read_int_n()
	B = read_int_n()
	print(slv(N, M, P, A, B))
main()


import sys
all = [int(x) for x in sys.stdin.buffer.read().split()]
n = all[0]
m = all[1]
p = all[2]
f = all[3:n + 3]
g = all[n + 3:]
ansi = 0
ansj = 0
for i in range(n):
	if f[i] % p != 0:
		ansi = i
		break
for j in range(m):
	if g[j] % p != 0:
		ansj = j
		break
print(ansi + ansj)


(n, m, p) = tuple(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
while i < n:
	if a[i] % p != 0:
		break
	i += 1
j = 0
while j < m:
	if b[j] % p != 0:
		break
	j += 1
print(i + j)


(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ok = True
ans = 0
for i in range(n):
	if a[i] % p != 0 and ok == True:
		ok = False
		ans += i
ok = True
for i in range(m):
	if b[i] % p != 0 and ok == True:
		ok = False
		ans += i
print(ans)


from bisect import bisect_left, bisect_right, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
(n, m, p) = mdata()
a = list(mdata())
b = list(mdata())
for i in range(min(n, m)):
	if a[i] % p != 0 or b[i] % p != 0:
		if a[i] % p != 0:
			if b[i] % p != 0:
				print(i + i)
			else:
				ind = 0
				for j in range(i + 1, m):
					if b[j] % p != 0:
						ind = j
						break
				print(i + ind)
		else:
			ind = 0
			for j in range(i + 1, n):
				if a[j] % p != 0:
					ind = j
					break
			print(i + ind)
		break


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def rint():
	return map(int, input().split())

def oint():
	return int(input())
(n, m, p) = rint()
ans = 0
for c in range(2):
	a = rint()
	for (i, aa) in enumerate(a):
		if aa % p:
			ans += i
			break
print(ans)


import sys

def input():
	return sys.stdin.buffer.readline()[:-1]

def main():
	(n, m, p) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]

	def get(x):
		for (i, e) in enumerate(x):
			if e % p:
				return i
	print(get(a) + get(b))
main()


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(input())

def In():
	return map(int, input().split())

def main():
	try:
		(n, m, p) = In()
		a = list(In())
		b = list(In())
		for x in range(n):
			if a[x] % p != 0:
				break
		for y in range(m):
			if b[y] % p != 0:
				break
		print(x + y)
	except:
		pass
M = 998244353
P = 1000000007
main()


(n, m, p) = map(int, input().split())
aa = [int(i) % p for i in input().split()]
bb = [int(i) % p for i in input().split()]
(aaa, bbb) = (-1, -1)
for i in range(0, n):
	if aa[i]:
		aaa = i
		break
for i in range(0, m):
	if bb[i]:
		bbb = i
		break
print(aaa + bbb)


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
(n, m, p) = sp()
a = l()
b = l()
for i in range(n):
	if a[i] % p != 0:
		break
for j in range(m):
	if b[j] % p != 0:
		break
out(str(i + j))


from sys import stdin
input = stdin.readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = j = 0
for i in range(n):
	if a[i] % p != 0:
		break
for j in range(m):
	if b[j] % p != 0:
		break
print(i + j)


import sys
input = lambda : sys.stdin.readline().rstrip()
(N, M, P) = list(map(int, input().split()))
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
for (i, a) in enumerate(A):
	if a % P:
		for (j, b) in enumerate(B):
			if b % P:
				print(i + j)
				return


import io
import os
import sys

def solve(N, M, P, A, B):
	ii = next((i for (i, a) in enumerate(A) if a % P != 0))
	jj = next((j for (j, b) in enumerate(B) if b % P != 0))
	k = ii + jj
	if False:
		Ck = 0
		for i in range(N):
			j = k - i
			if 0 <= i < N and 0 <= j < M:
				val = A[i] * B[j]
				if (i, j) == (ii, jj):
					assert val % P != 0
				else:
					assert i < ii or j < jj
					assert val % P == 0
				Ck += val
		assert Ck % P != 0
	return k
input = sys.stdin.readline
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, M, P) = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = solve(N, M, P, A, B)
print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
(a, b) = (0, 0)
while x[a] % p == 0:
	a += 1
while y[b] % p == 0:
	b += 1
print(a + b)


import math
import sys
input = sys.stdin.readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
new = []
for i in range(n - 1, -1, -1):
	new.append(a[i])
for i in range(n):
	if a[i] % p != 0:
		index1 = i
		break
for i in range(m):
	if b[i] % p != 0:
		index2 = i
		break
print(index1 + index2)


import sys
input = sys.stdin.readline
(n, m, p) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(n):
	if A[i] % p != 0:
		s = i
		break
for i in range(m):
	if B[i] % p != 0:
		t = i
		break
print(s + t)


from sys import stdin
(n, m, p) = map(int, input().split())
arr = list(map(int, input().strip().split()))[:n]
arr1 = list(map(int, input().strip().split()))[:m]
arr2 = [n + m]
ai = 0
bi = 0
for i in range(n):
	if arr[i] % p != 0:
		ai = i
		break
for j in range(m):
	if arr1[j] % p != 0:
		bi = j
		break
print(ai + bi)


(n, m, p) = map(int, input().split())
f = list(map(int, input().split()))
g = list(map(int, input().split()))
(fi, gi) = (0, 0)
for i in range(n):
	if f[i] % p:
		fi = i
		break
for i in range(m):
	if g[i] % p:
		gi = i
		break
print(fi + gi)


(N, M, P) = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
for (i, x) in enumerate(X):
	if x % P != 0:
		break
for (j, y) in enumerate(Y):
	if y % P != 0:
		break
print(i + j)


(a, b, p) = map(int, input().split())

def k(x):
	return bool(int(x) % p)
(x, y) = (list(map(k, input().split())), list(map(k, input().split())))
print(x.index(True) + y.index(True))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	if a[i] % p:
		x = i
		break
for j in range(m):
	if b[j] % p:
		y = j
		break
print(x + y)


import math
q = 1
for _ in range(q):
	(n, m, p) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	x = -1
	for i in range(n):
		if a[i] % p != 0:
			x = i
			break
	for i in range(m):
		if b[i] % p != 0:
			x += i
			break
	print(x)


ints = [int(x) for x in input().split()]
n = ints[0]
m = ints[1]
p = ints[2]
t = [int(x) % p for x in input().split()]
u = [int(x) % p for x in input().split()]
ans = 0
for i in range(n):
	if t[i] != 0:
		ans += i
		break
for i in range(m):
	if u[i] != 0:
		ans += i
		break
print(ans)


from sys import stdin
(n, m, p) = map(int, stdin.readline().split())
f_coeff = list(map(int, stdin.readline().split()))
g_coeff = list(map(int, stdin.readline().split()))
for i in range(n - 1, -1, -1):
	if f_coeff[i] % p != 0:
		break
for j in range(m - 1, -1, -1):
	if g_coeff[j] % p != 0:
		break
print(i + j)


(n, m, p) = map(int, input().strip().split())
(a, b) = [list(map(int, input().strip().split())) for i in range(2)]
(s1, s2) = (0, 0)
for i in range(n):
	if a[i] % p:
		s1 = i
		break
for i in range(m):
	if b[i] % p:
		s2 = i
		break
print(s1 + s2)


def main_function():
	(n, m, p) = list(map(int, input().split(' ')))
	first_sequence = list(map(int, input().split(' ')))
	second_sequence = list(map(int, input().split(' ')))
	coefficient = 0
	for i in range(len(first_sequence)):
		if first_sequence[i] % p != 0:
			coefficient = i
			break
	for i in range(len(second_sequence)):
		if second_sequence[i] % p != 0:
			coefficient += i
			break
	return coefficient
print(main_function())


from sys import stdin, gettrace
if not gettrace():

	def input():
		return stdin.buffer.readline()

def main():
	(n, m, p) = map(int, input().split())
	aa = (int(a) for a in input().split())
	bb = (int(a) for a in input().split())
	for (i, a) in enumerate(aa):
		if a % p != 0:
			ap = i
			break
	for (i, b) in enumerate(bb):
		if b % p != 0:
			bp = i
			break
	print(ap + bp)
main()


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def rint():
	return map(int, input().split())

def oint():
	return int(input())
(n, m, p) = rint()
a = list(rint())
b = list(rint())
ans = 0
for i in range(n):
	if a[i] % p:
		ans += i
		break
for i in range(m):
	if b[i] % p:
		ans += i
		break
print(ans)


(n, m, p) = map(int, input().split())
a = map(int, input().split())
b = map(int, input().split())

def f(arr):
	for (i, x) in enumerate(arr):
		if x % p != 0:
			return i
print(f(a) + f(b))


from sys import stdin

def input():
	return stdin.buffer.readline()
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
while i < n:
	if a[i] % p != 0:
		break
	i += 1
j = 0
while j < m:
	if b[j] % p != 0:
		break
	j += 1
print(i + j)


(n, m, p) = map(int, input().split())
f = tuple(map(int, input().split()))
g = tuple(map(int, input().split()))
for i in range(n):
	if f[i] % p != 0:
		ind1 = i
		break
for i in range(m):
	if g[i] % p != 0:
		ind2 = i
		break
print(ind1 + ind2)


from math import ceil, sqrt, gcd, log, floor
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())

def msi():
	return map(str, input().strip().split(' '))

def lsi():
	return list(msi())
(n, m, p) = mi()
a = li()
b = li()
for i in range(n):
	if gcd(a[i], p) == 1:
		x = i
		break
for i in range(m):
	if gcd(b[i], p) == 1:
		y = i
		break
print(x + y)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def case():
	(n, m, p) = li()
	a = li()
	b = li()
	(x, y) = (-1, -1)
	for i in range(n):
		if a[i] % p != 0:
			x = i
			break
	for i in range(m):
		if b[i] % p != 0:
			y = i
			break
	print(x + y)
for _ in range(1):
	case()


(n, m, p) = map(int, input().split())
A = [int(i) % p == 0 for i in input().split()]
B = [int(i) % p == 0 for i in input().split()]
for (i, a) in enumerate(A):
	if not a:
		ans = i
		break
for (i, b) in enumerate(B):
	if not b:
		ans += i
		break
print(ans)


import sys
(n, m, p) = map(int, sys.stdin.readline().split(' '))
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
i = j = 0
while a[i] % p == 0:
	i += 1
while b[j] % p == 0:
	j += 1
print(i + j)


import io
import os
import sys

def solve(N, M, P, A, B):
	ii = next((i for (i, a) in enumerate(A) if a % P != 0))
	jj = next((j for (j, b) in enumerate(B) if b % P != 0))
	k = ii + jj
	if False:
		Ck = 0
		for i in range(N):
			j = k - i
			if 0 <= i < N and 0 <= j < M:
				val = A[i] * B[j]
				if (i, j) == (ii, jj):
					assert val % P != 0
				else:
					assert i < ii or j < jj
					assert val % P == 0
				Ck += val
		assert Ck % P != 0
	return k
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
(N, M, P) = list(map(int, input().split()))
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = solve(N, M, P, A, B)
print(ans)


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
(n, m, p) = read()
a = read()
b = read()
x = -1
y = -1
for i in range(n):
	if a[i] % p != 0:
		x = i
		break
for i in range(m):
	if b[i] % p != 0:
		y = i
		break
print(x + y)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	(n, m, p) = MI()
	aa = LI()
	bb = LI()
	for (i, a) in enumerate(aa):
		if a % p:
			break
	for (j, b) in enumerate(bb):
		if b % p:
			break
	print(i + j)
main()


R = lambda : [int(x) for x in input().split()]
[n, m, p] = R()
a = R()
b = R()
(i1, i2) = (0, 0)
for i in range(n):
	if a[i] % p != 0:
		i1 = i
		break
for j in range(m):
	if b[j] % p != 0:
		print(i1 + j)
		break


from sys import stdin
readline = stdin.readline
(n, m, p) = map(int, readline().split())
data = map(int, readline().split())
datb = map(int, readline().split())
(inda, indb) = (0, 0)
for x in data:
	if x % p != 0:
		break
	inda = inda + 1
for x in datb:
	if x % p != 0:
		break
	indb = indb + 1
print(indb + inda)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
mod = int(1000000000.0) + 7

def power(k, n):
	if n == 0:
		return 1
	if n % 2:
		return power(k, n - 1) * k % mod
	t = power(k, n // 2)
	return t * t % mod

def totalPrimeFactors(n):
	count = 0
	if n % 2 == 0:
		count += 1
		while n % 2 == 0:
			n //= 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			count += 1
			while n % i == 0:
				n //= i
		i += 2
	if n > 2:
		count += 1
	return count

def main():
	(n, m, p) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(f, s) = (-1, -1)
	for i in range(n):
		if a[i] % p:
			f = i
			break
	for i in range(m):
		if b[i] % p:
			s = i
			break
	print(f + s)
	return
main()


from bisect import bisect_left, bisect_right, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
(n, m, p) = mdata()
a = list(mdata())
b = list(mdata())
ind1 = ind2 = 0
for i in range(n):
	if a[i] % p != 0:
		ind1 = i
		break
for i in range(m):
	if b[i] % p != 0:
		ind2 = i
		break
print(ind1 + ind2)


(n, m, p) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
(r, s) = (0, 0)
for i in range(n):
	if a[i] % p != 0:
		r = i
		break
for i in range(m):
	if b[i] % p != 0:
		s = i
		break
print(r + s)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def isprime(n):
	for j in range(2, int(math.sqrt(n) + 1)):
		if n % j == 0:
			return False
	return True
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for j in range(n):
	if a[j] % p != 0:
		in1 = j
		break
for j in range(m):
	if b[j] % p != 0:
		in2 = j
		break
print(in1 + in2)


(n, m, p) = map(int, input().split())
ln = []
ln = list(map(int, input().split()))
lm = []
lm = list(map(int, input().split()))
a = 0
b = 0
for i in range(0, len(ln)):
	if ln[i] % p != 0:
		a = i
		break
for i in range(0, len(lm)):
	if lm[i] % p != 0:
		b = i
		break
print(a + b)


(n, m, p) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(n):
	if a[i] % p != 0:
		ar = i
		break
for i in range(m):
	if b[i] % p != 0:
		br = i
		break
print(ar + br)


def main():
	(n, m, p) = readIntArr()
	a = readIntArr()
	b = readIntArr()
	t = 0
	for i in range(n):
		if a[i] % p != 0:
			t += i
			break
	for i in range(m):
		if b[i] % p != 0:
			t += i
			break
	print(t)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([''.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
for _ in range(1):
	main()


(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(len(a)):
	if a[i] % p:
		x = i
for i in range(len(b)):
	if b[i] % p:
		y = i
print(x + y)


from sys import stdin
lines = stdin.readlines()
(n, m, p) = map(int, lines[0].strip().split())
a = list(map(int, lines[1].strip().split()))
b = list(map(int, lines[2].strip().split()))
(ta, tb) = (-1, -1)
for i in range(n):
	if a[i] % p != 0:
		ta = i
		break
for j in range(m):
	if b[j] % p != 0:
		tb = j
		break
print(ta + tb)


def findIndex(arr, p):
	return max(map(lambda px: px[0], filter(lambda px: px[1] % p, enumerate(arr))))
(n, m, p) = map(int, input().split())
ass = list(map(int, input().split()))
bss = list(map(int, input().split()))
print(findIndex(ass, p) + findIndex(bss, p))


import sys
inf = int(100000000.0)
(n, m, p) = map(int, sys.stdin.readline().split())
lis1 = list(map(int, sys.stdin.readline().split()))
lis2 = list(map(int, sys.stdin.readline().split()))
c1 = 0
for i in range(n):
	if lis1[i] % p:
		c1 = i
		break
c2 = 0
for i in range(m):
	if lis2[i] % p:
		c2 = i
		break
print(c1 + c2)


((n, m, p), ans) = (map(int, input().split()), 0)
a = map(lambda s: int(s) % p, input().split())
b = map(lambda s: int(s) % p, input().split())
while next(a) == 0:
	ans += 1
while next(b) == 0:
	ans += 1
print(ans)


t = list(map(int, input().split(' ')))
p = int(t[2])
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
ans = 0
t = 0
for i in a:
	if i % p != 0:
		ans += t
		break
	t += 1
t = 0
for i in b:
	if i % p != 0:
		ans += t
		break
	t += 1
print('%d' % ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, m, p) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
ans = 0
for i in range(n):
	if l[i] % p != 0:
		ans += i
		break
for i in range(m):
	if l1[i] % p != 0:
		ans += i
		break
print(ans)


import math
import sys
input = sys.stdin.buffer.readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(f, s) = (-1, -1)
for i in range(m):
	if b[i] % p != 0 and f == -1:
		f = i
for i in range(n):
	if a[i] % p != 0 and s == -1:
		s = i
print(f + s)


(n, m, p) = map(int, input().split())
c1 = 0
for i in input().split():
	if int(i) % p != 0:
		break
	c1 += 1
c2 = 0
for j in input().split():
	if int(j) % p != 0:
		break
	c2 += 1
print(c1 + c2)


(n, m, k) = map(int, input().split())
ls = list(map(int, input().split()))
arr = list(map(int, input().split()))
for i in range(len(ls)):
	if ls[i] % k != 0:
		x = i
		break
for j in range(len(arr)):
	if arr[j] % k != 0:
		y = j
		break
print(x + y)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
(n, m, p) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
(i, j) = (0, 0)
while a[i] % p == 0:
	i += 1
while b[j] % p == 0:
	j += 1
print(i + j)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf
from itertools import permutations
from copy import deepcopy
from heapq import *
from sys import setrecursionlimit

def main():
	(n, m, p) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(i, j) = (0, 0)
	while i < n and a[i] % p == 0:
		i += 1
	while j < m and b[j] % p == 0:
		j += 1
	print(i + j)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from sys import stdin, stdout
(n, m, p) = map(int, stdin.readline().split())
a = False
(arr1, arr2) = (list(map(int, stdin.readline().split())), list(map(int, stdin.readline().split())))
for i in range(n):
	if arr1[i] % p != 0 and (not a):
		a = True
		first = i
a = False
for i in range(m):
	if arr2[i] % p != 0 and (not a):
		a = True
		second = i
stdout.write('{}\n'.format(first + second))


import sys
inp = sys.stdin.readline

def input():
	return inp().strip()
flush = sys.stdout.flush

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	(n, m, p) = lin()
	a = lin()
	b = lin()
	ans = 0
	for (i, j) in enumerate(a):
		if j % p != 0:
			ans += i
			break
	for (i, j) in enumerate(b):
		if j % p != 0:
			ans += i
			break
	print(ans)
main()


(n, m, p) = map(int, input().split())
f = list(map(int, input().split()))
g = list(map(int, input().split()))
an = 0
an2 = 0
for i in range(n):
	if f[i] % p != 0:
		an = i
		break
for i in range(m):
	if g[i] % p != 0:
		an2 = i
		break
print(an + an2)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, m, p) = get_ints()
a = get_list()
b = get_list()
i = 0
while i < n:
	if a[i] % p != 0:
		break
	i += 1
j = 0
while j < m:
	if b[j] % p != 0:
		break
	j += 1
print(i + j)


def ii():
	return int(input())

def mii():
	return map(int, input().split())

def lmii():
	return list(mii())

def main():
	(x, y, m) = mii()
	a = lmii()
	b = lmii()
	ans1 = ans2 = -1
	for i in range(x):
		if a[i] % m != 0 and ans1 == -1:
			ans1 = i
	for i in range(y):
		if b[i] % m != 0 and ans2 == -1:
			ans2 = i
	print(ans2 + ans1)
main()


from sys import stdin

def func():
	return
(n, m, p) = map(int, stdin.readline().split())
arr1 = list(map(int, stdin.readline().split()))
arr2 = list(map(int, stdin.readline().split()))
(a, b) = (0, 0)
for i in range(n):
	if arr1[i] % p != 0:
		a = i
		break
for i in range(m):
	if arr2[i] % p != 0:
		b = i
		break
print(a + b)


from random import randint
import sys
(n, m, p) = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
g = list(map(int, input().strip().split()))
for i in range(len(f)):
	if f[i] % p != 0:
		break
j = 0
while g[j] % p == 0:
	j += 1
print(i + j)


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def inp():
	return sys.stdin.readline().rstrip('\n')

def mpint():
	return map(int, sys.stdin.readline().split(' '))

def itg():
	return int(sys.stdin.readline())
(n, m, p) = mpint()
f = list(mpint())
g = list(mpint())

def main():
	for i in range(n):
		if f[i] % p != 0:
			fi = i
			break
	else:
		return -1
	for j in range(m):
		if g[j] % p != 0:
			gj = j
			break
	else:
		return -1
	return fi + gj
print(main())


import math

def main():
	(n, m, p) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	gcd_a = a[0]
	idx = 0
	for i in range(1, n):
		gcd_a = math.gcd(gcd_a, a[i])
		if gcd_a == 1:
			idx = i
			break
	gcd_b = b[0]
	idx2 = 0
	for i in range(1, n):
		gcd_b = math.gcd(gcd_b, b[i])
		if gcd_b == 1:
			idx2 = i
			break
	if a[0] * b[0] % p != 0:
		print(0)
	elif a[n - 1] * b[m - 1] % p != 0:
		print(n + m - 2)
	else:
		print(idx + idx2)
main()


from pprint import pprint
(n, m, p) = map(int, input().split())
data = list(map(lambda x: int(x) % p, input().split()))
datb = list(map(lambda x: int(x) % p, input().split()))
for i in range(n):
	if data[i] != 0:
		inda = i
		break
for i in range(m):
	if datb[i] != 0:
		indb = i
		break
print(indb + inda)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = 0
j = 0
for k in range(n):
	if a[k] % p != 0:
		i = k
		break
for k in range(m):
	if b[k] % p != 0:
		j = k
		break
r = i + j
print(r)


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
(n, m, p) = rint()
a = list(rint())
b = list(rint())
ans = 0
for i in range(n):
	if a[i] % p:
		ans += i
		break
for i in range(m):
	if b[i] % p:
		ans += i
		break
print(ans)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from functools import *
from itertools import permutations, combinations, groupby
import sys
import bisect
import string
import math
import time
import random

def Golf():
	(*a,) = map(int, open(0))

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}):
	mp = [1] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [1] + [mp_def[j] for j in s] + [1]
	mp += [1] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

def ran_input():
	import random
	n = random.randint(4, 16)
	(rmin, rmax) = (1, 10)
	a = [random.randint(rmin, rmax) for _ in range(n)]
	return (n, a)
show_flg = False
show_flg = True
(n, m, p) = LI()
a = LI()
b = LI()
for i in range(n):
	if a[i] % p != 0:
		s = i
		break
for i in range(m):
	if b[i] % p != 0:
		t = i
		break
print(s + t)


from sys import stdin
input = stdin.buffer.readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(x, y) = (0, 0)
while a[x] % p == 0:
	x += 1
while b[y] % p == 0:
	y += 1
print(x + y)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
(n, m, p) = R()
a = L()
b = L()
for i in range(n):
	if a[i] % p != 0:
		break
for j in range(m):
	if b[j] % p != 0:
		break
print(i + j)


import sys

def f():
	(n, m, p) = [int(s) for s in input().split()]
	A = [int(s) for s in sys.stdin.readline().split()]
	B = [int(s) for s in sys.stdin.readline().split()]
	i = 0
	while not A[i] % p:
		i += 1
	j = 0
	while not B[j] % p:
		j += 1
	s = i + j
	print(s)
f()


from sys import stdin

def inp():
	return stdin.buffer.readline()

def itg():
	return int(inp())

def mpint():
	return map(int, inp().split())
(n, m, p) = mpint()
f = list(mpint())
g = list(mpint())

def main():
	for i in range(n):
		if f[i] % p != 0:
			fi = i
			break
	else:
		return -1
	for j in range(m):
		if g[j] % p != 0:
			gj = j
			break
	else:
		return -1
	return fi + gj
print(main())


import sys
input = sys.stdin.readline
(n, m, p) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
(i, j) = (0, 0)
while a[i] % p == 0:
	i += 1
while b[j] % p == 0:
	j += 1
print(i + j)


l1 = [int(i) for i in input().split()]
l2 = [int(i) % l1[2] for i in input().split()]
l3 = [int(i) % l1[2] for i in input().split()]
m = 0
for i in range(len(l2)):
	if l2[i] != 0:
		m = i
		break
for i in range(len(l3)):
	if l3[i] != 0:
		m = m + i
		break
print(m)


import sys
import math

def alele():
	return list(map(int, sys.stdin.readline().strip().split()))

def ilele():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, m, p) = ilele()
c = 0
A = alele()
B = alele()
for i in range(n):
	if A[i] % p != 0:
		c += i
		break
for i in range(m):
	if B[i] % p != 0:
		c += i
		break
print(c)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	(n, m, p) = map(int, input().split())
	a = [i for (i, c) in enumerate(map(int, input().split())) if c % p != 0][0]
	b = [i for (i, c) in enumerate(map(int, input().split())) if c % p != 0][0]
	print(a + b)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
values = list(map(int, input().split()))
n = values[0]
m = values[1]
p = values[2]
coeff1 = list(map(int, input().split()))
coeff2 = list(map(int, input().split()))
fpos1 = 0
fpos2 = 0
cv1 = 0
cv2 = 0
answer1 = 0
answer2 = 0
while cv1 <= len(coeff1) - 1:
	if coeff1[cv1] % p != 0:
		answer1 = cv1
		break
	else:
		cv1 += 1
while cv2 <= len(coeff2) - 1:
	if coeff2[cv2] % p != 0:
		answer2 = cv2
		break
	else:
		cv2 += 1
print(answer1 + answer2)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque

def solution(n, m, p, a, b):
	for i in range(n):
		if a[i] % p != 0:
			sia = i
			break
	for i in range(m):
		if b[i] % p != 0:
			sib = i
			break
	return sia + sib

def main():
	T = 1
	for i in range(T):
		(n, m, p) = read_int_array()
		a = read_int_array()
		b = read_int_array()
		x = solution(n, m, p, a, b)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import sys, math
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
for tt in range(t):
	(n, m, p) = invr()
	a = inlt()
	b = inlt()
	for i in range(n):
		if a[i] % p != 0:
			q = i
	for i in range(m):
		if b[i] % p != 0:
			w = i
	print(q + w)


import sys
(n, m, p) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

def get(x):
	for (i, e) in enumerate(x):
		if e % p:
			return i
print(get(a) + get(b))


import sys
input = sys.stdin.buffer.readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans1 = 0
ans2 = 0
for (i, num) in enumerate(a):
	if num % p != 0:
		ans1 = i
		break
for (i, num) in enumerate(b):
	if num % p != 0:
		ans2 = i
		break
print(ans1 + ans2)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(n):
	if A[i] % p != 0:
		s = i
		break
for i in range(m):
	if B[i] % p != 0:
		t = i
		break
print(s + t)


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return len(parents)

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
(n, m, p) = mult_inp()
a = inp()
b = inp()
for i in range(n):
	if a[i] % p != 0:
		found1 = i
		break
for i in range(m):
	if b[i] % p != 0:
		found2 = i
		break
print(found1 + found2)


from pprint import pprint
import sys
read = sys.stdin.buffer.read
(n, m, p, *dat) = map(int, read().split())
data = dat[:n]
datb = dat[n:]
for i in range(n):
	if data[i] % p != 0:
		inda = i
		break
for i in range(m):
	if datb[i] % p != 0:
		indb = i
		break
print(indb + inda)


import sys
(n, m, p) = [int(i) for i in sys.stdin.readline().split()]
a = [int(i) for i in sys.stdin.readline().split()]
b = [int(i) for i in sys.stdin.readline().split()]
k = 0
while a[k] % p == 0:
	k = k + 1
l = 0
while b[l] % p == 0:
	l = l + 1
print(k + l)


INF = 10 ** 10

def main():
	print = out.append
	(n, m, p) = get_list()
	for (i, ele) in enumerate(get_list()):
		if ele % p != 0:
			ans = i
			break
	for (i, ele) in enumerate(get_list()):
		if ele % p != 0:
			ans += i
			break
	print(ans)
import sys
from collections import defaultdict, Counter, deque
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ind1 = -1
ind2 = -1
for i in range(n):
	if a[i] % p != 0:
		ind1 = i
		break
for i in range(m):
	if b[i] % p != 0:
		ind2 = i
		break
print(ind1 + ind2)


import sys
l = [int(index) for index in sys.stdin.readline().split()]
(n, m, p) = (l[0], l[1], l[2])
a = [int(index) for index in sys.stdin.readline().split()]
b = [int(index) for index in sys.stdin.readline().split()]
ans = 0
for i in range(len(a)):
	if a[i] % p != 0:
		ans += i
		break
for i in range(len(b)):
	if b[i] % p != 0:
		ans += i
		break
sys.stdout.write(str(ans))


import sys
input = sys.stdin.buffer.readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
idx1 = -1
idx2 = -1
for i in range(n):
	if a[i] % p != 0:
		idx1 = i
		break
for i in range(m):
	if b[i] % p != 0:
		idx2 = i
		break
print(idx1 + idx2)


import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, m, p) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = -1
B = -1
for i in range(n):
	if a[i] % p != 0:
		A = i
		break
for i in range(m):
	if b[i] % p != 0:
		B = i
		break
print(A + B)


import sys
from random import choice

def solve(N, M, P, A, B):
	L = N + M - 1
	I = next((i for (i, a) in enumerate(A) if a % P != 0))
	J = next((j for (j, b) in enumerate(B) if b % P != 0))
	k = I + J
	Ck = 0
	for i in range(max(k - M + 1, 0), min(k + 1, N)):
		j = k - i
		Ck += A[i] * B[j] % P
	if Ck % P != 0:
		return k
	return 0
if False:
	from random import randint
	N = 10 ** 6
	M = 10 ** 6
	A = [randint(1, 10 ** 9) for i in range(N)]
	B = [randint(1, 10 ** 9) for i in range(M)]
	P = 999999937
	ans = solve(N, M, P, A, B)
	print(ans)
	exit()
_INPUT_LINES = sys.stdin.read().splitlines()
(N, M, P) = list(map(int, _INPUT_LINES[0].split()))
A = [int(x) for x in _INPUT_LINES[1].split()]
B = [int(x) for x in _INPUT_LINES[2].split()]
ans = solve(N, M, P, A, B)
print(ans)


def main():
	import sys
	input = sys.stdin.readline
	(n, m, p) = map(int, input().split())
	A = list(map(int, input().split()))
	A += [0] * (m - 1)
	B = list(map(int, input().split()))
	B += [0] * (n - 1)
	a = 0
	b = 0
	for t in range(n + m - 1):
		if A[a] % p == 0:
			a += 1
		elif B[b] % p == 0:
			b += 1
		else:
			ans = t
			break
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m, p) = map(int, input().split())
z = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(len(z)):
	z[i] %= p
for i in range(len(t)):
	t[i] %= p
save = 0
save1 = 0
for i in range(len(z)):
	if z[i] != 0:
		save = i
		break
for i in range(len(t)):
	if t[i] != 0:
		save1 = i
		break
print(save1 + save)


from sys import stdin
input = stdin.buffer.readline
r = lambda : map(int, input().split())

def f(_):
	for (i, v) in enumerate(_):
		if v % p != 0:
			return i
	return -1
(_, _, p) = r()
print(f(r()) + f(r()))


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def modpow(b, p, m):
	res = 1
	b = b % m
	while p:
		if p & 1:
			res = res * b % m
		b = b * b % m
		p >>= 1
	return res

def mod_inv(a, m):
	return modpow(a, m - 2, m)

def ncr(n, r, m):
	res = 1
	if r == 0:
		return 1
	if n - r < r:
		r = n - r
	(p, k) = (1, 1)
	while r:
		res = res % m * (n % m * mod_inv(r, m) % m) % m
		n -= 1
		r -= 1
	return res

def ncrlis(n, r, m, fact):
	return fact[n] * (mod_inv(fact[r], m) * mod_inv(fact[n - r], m)) % m % m

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m, p) = mi()
a = li()
b = li()
(ra, rb) = (0, 0)
i = 0
while a[i] % p == 0:
	ra += 1
	i += 1
i = 0
while b[i] % p == 0:
	rb += 1
	i += 1
print(ra + rb)