user = input().split() user = list(map(int, user)) cells = (0.5*(user[0] + user[1])) % (user[2] * (1000000007)) print(int(cells))