a,b,c=map(int,raw_input().split())
print 'YES' if a==b or (c and (not (b-a)%c) and (b>a)==(c>0)) else 'NO'

# -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 01:42:31 2019

@author: KIIT
"""

import math
import os
import random
import re
import sys
if __name__ == '__main__':
    x = list(map(int, input().rstrip().split()))
    a,b,c=x[0],x[1],x[2]

    if(c==0):
        if((b-a)==0):
            print("YES")
        else:
            print("NO")
    else:
        k=(b-a)%c
        if(k==0 and (b-a)/c>=0):
            print("YES")
        else:
            print("NO")

a,b,c=[int(e) for e in raw_input().split()]
t=a
present=False
if (c>0 and b<a) or (c<0 and a<b):
	pass
elif c==0:
	if a==b:
		present=True
else:
	if (b-a)%c==0:
		present=True
if present:
	print "YES"
else :
	print "NO"

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
if c == 0:
        if a == b:
                print("YES")
        else:
                print("NO")
else:
        if b % c == a % c:
                if b < a:
                        if c < 0:
                                print("YES")
                        else:
                                print("NO")
                elif b > a:
                        if c >= 0:
                                print("YES")
                        else:
                                print("NO")
                else:
                        print("YES")

        else:
                print("NO")

a,s,d = map(int,input().split())
def check(a,s,d):
    if(d!=0):
        n = ((s-a)/d+1)
        j = n%1
        if(j==0.0):
            if(n>0):
                return ("YES")
    if(d==0):
        if(a==s):
            return ("YES")
    return "NO"
print(check(a,s,d))

a, b, c = map(int, raw_input().split())

if c == 0:
	if a == b:
		print 'YES'
	else:
		print 'NO'
else:
	x = (b-a)/c
	# print x
	if a + x*c  == b and x >= 0:
		print 'YES'
	else:
		print 'NO'

a, b, c = map(int, raw_input().split())

if c == 0:
	if a == b:
		print 'YES'
	else:
		print 'NO'
else:
	if (b-a)%c == 0 and (b-a)/c >= 0:
		print 'YES'
	else:
		print 'NO'

a,b,c = map(int,raw_input().split());
if (c == 0 and a==b) or (c != 0 and (b-a) % c == 0 and (b-a) / c >=0) :
    print "YES"
else :
    print "NO"

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

if(a == b):
    print("YES")
else:
    if(c > 0 and c != 1):
        while(a < b):
            a = c + a
        if(a == b):
            print("YES")
        else:
            print("NO")
    elif(c < 0 and c != -1):
        while(a > b):
            a = c + a
        if (a == b):
            print("YES")
        else:
            print("NO")
    elif(c == 0):
        print("NO")
    elif(c == 1 and a < b):
        print("YES")
    elif(c == -1 and a > b):
        print("YES")
    else:
        print("NO")

#@author: behradm

def main():
    a, b, c = list(map(int, input().split()))

    if(c == 0):
        if(a == b):
            print("YES")
        else:
            print("NO")
    else:
        if((c < 0 and b > a) or (c > 0 and b < a)):
            print("NO")
            return 0;

        if(a % c == b % c):
            print("YES")
        else:
            print("NO")

if(__name__ == "__main__"):
    main()

a, b, c = map(int, input().split())
if c > 0 and b < a or c < 0 and b > a:
    print('NO')
else:
    try:
        if (b - a) % c == 0:
            print('YES')
        else:
            print('NO')
    except ZeroDivisionError:
        if a == b:
            print('YES')
        else:
            print('NO')

a,b,c = map(int, input().split())
if (a!=b and c==0):
	print ("NO")
else:
	print ("YES") if (a==b or ((b-a)%c==0 and (abs(b-a)/abs(c))==((b-a)/c))) else print ("NO")

a,b,c=map(int,raw_input().split())
if c==0:
    print 'YES' if a==b else 'NO'
else:
    if (b-a)%c==0:
        print 'YES' if (c<0 and b<=a) or (c>0 and a<=b) else 'NO'
    else:
        print 'NO'

from sys import stdin
input = stdin.readline
a, b, c = map(int, input().split())
print(["NO", "YES"][ c > 0 and b >= a and not (b - a)%c or c < 0 and a >= b and not (b - a)%c or c == 0 and a == b])

from re import *
from sys import stderr
def readint():
    return int(input())
def readfloat():
    return float(input())
def readarray(N, foo=input):
    return [foo() for i in range(N)]
def readlinearray(foo=int):
    return map(foo, input().split())

def NOD(a, b):
    while b:
        a,b = b, a%b
    return a

def gen_primes(max):
    primes = [1]*(max+1)
    for i in range(2, max+1):
        if primes[i]:
            for j in range(i+i, max+1, i):
                primes[j] = 0
    primes[0] = 0
    return [x for x in range(max+1) if primes[x]]

def is_prime(N):
    i = 3
    if not(N % 2):
        return 0
    while i*i < N:
        if not(N % i):
            return 0
        i += 3
    return 1

a, b, c = readlinearray()
b -= a

if b == 0 or (c != 0 and c * b > 0 and b % c == 0):
    print("YES")
else:
    print("NO")

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

if a == b and c == 0 or (c != 0 and (b - a ) // c >= 0 and (b - a) % c == 0 ):
    print('YES')

else:
    print('NO')

a,b,c=map(int,raw_input().split())
if c==0:
	if a==b:print "YES"
	else:print "NO"
elif ((b-a)==0) or (((b-a)%c==0) and (b-a)/c>0 ):print "YES"
else:print "NO"

[a, b, c] = [int(item) for item in input().split(' ')]

YES = "YES"
NO = "NO"

diff = b - a

if c:
    if diff == 0:
        print("YES")
        exit()
    print("YES" if diff // abs(diff) == c // abs(c) and diff % c == 0 else "NO")
else:
    print("YES" if a == b else "NO")

a,b,c=map(int,raw_input().split())
if c==0 :
    if a==b:
        print "YES"
    else:
        print "NO"
elif (b-a)%c==0:
    if (b-a)/c>=0:
        print "YES"
    else:
        print "NO"
else:
    print "NO"

a, b, c = map(int, input().split())
if c == 0:
    if a==b:
        print("YES")
    else:
        print('NO')
elif (b-a) % c == 0 and (b-a)//c >= 0:
    print("YES")
else:
    print("NO")

a, b, c = map(int, raw_input().split())
if c == 0:
	print 'NO' if a != b else 'YES'
elif c > 0:
	print 'YES' if (a <= b and (b - a) % c == 0) else 'NO'
else:
	print 'YES' if (a >= b and (a - b) % c == 0) else 'NO'

def readInt(): return int(raw_input())
def readList(): return map(int, raw_input().split(' '))

a, b, c = readList()

if c == 0 and a == b:
    print 'YES'
    exit()
elif c == 0 and a != b:
    print 'NO'
    exit()
if (b - a) % c  == 0 and ((b-a)/c >= 0): print 'YES'
else: print 'NO'

def f(l):
    a,b,c = l
    if c==0:
        return a==b
    return (b-a)%c==0 and (b-a)//c>=0

l = list(map(int,input().split()))
print('YES' if f(l) else 'NO')

a, b, c = map(int, raw_input().split())
print 'YES' if (a == b) or (c != 0 and (b-a)%c == 0 and (a < b)^(c>0) == 0) else 'NO'

a, b, c = map(int, raw_input().split())
if a == b:
    print "YES"
elif a > b:
    if c >= 0:
        print "NO"
    else:
        print "YES" if (a - b) % c == 0 else "NO"
else:
    if c <= 0:
        print "NO"
    else:
        print "YES" if (b - a) % c == 0 else "NO"

a, b, c = map(int, input().split())
if c == 0 and b == a:
    print("YES")
elif c != 0 and (b-a)%c == 0 and (b>=a and c > 0 or b<=a and c <0):
    print("YES")
else:
    print("NO")

from math import ceil,floor
a,b,c = map(int,input().split())
if(c==0):
    print("YES" if a==b else "NO")
    exit(0)
i = (b-a)/c
if(i>=0 and ceil(i)==floor(i)):
    print("YES")
else:
    print("NO")

a, b, c = map(int, raw_input().split())
print (b == a or (c and (b - a) % c == 0 and (b - a) / c > 0)) and "YES" or "NO"

x = raw_input().strip().split(" ")
s = int(x[0])
t = int(x[1])
d = int(x[2])

if d==0:
    if s==t:
        print "YES"
    else:
        print "NO"
elif (t-s)%d==0 and (t-s)/d>=0:
    print "YES"
else:
    print "NO"

a, b, c = map(int, input().split())
if c == 0:
	if a == b:
		print("YES")
	else:
		print("NO")
else:
	d, r = divmod(b - a, c)
	if a == b:
		print("YES")
	else:
		if d < 1 or r != 0:
			print("NO")
		else:
			print("YES")

[a,b,c]=[int(x) for x in raw_input().split()]
if c==0 :
    if a==b:
        print "YES"
    else:
        print "NO"
elif (b-a)%c==0:
    if c >=0 and b>=a:
        print "YES"
    elif c<0 and b<=a:
        print "YES"
    else:
        print "NO"
else:
    print "NO"

a, b, c = map(int, input().split()); print(['NO', 'YES'][a == b or ( c != 0 and (b-a)%c == 0 and (b-a)//c >= 0)])

if __name__ == '__main__':
	a,b,c = map(int,raw_input().split())
	t = b-a
	if a == b:
		print 'YES'
	else:
		if c == 0:
			if a == b:
				print 'YES'
			else:
				print 'NO'
		elif c < 0:
			if b > a:
				print 'NO'
			else:
				if t % c == 0:
					print 'YES'
				else:
					print 'NO'
		elif c > 0:
			if t % c == 0 and b > a:
				print 'YES'
			else:
				print 'NO'

read = lambda: map(int, input().split())
a, b, c = read()
if c == 0 and (b == a): ans = 'YES'
elif c != 0 and (b - a) % c == 0:
    if c > 0 and b >= a: ans = 'YES'
    elif c < 0 and b <= a: ans = 'YES'
    else: ans = 'NO'
else: ans = 'NO'
print(ans)

a, b, c = map(int, input().split())
def solve(a, b, c):
    if c == 0:
        return a == b
    elif c < 0:
        a, b, c = -a, -b, -c
    return b >= a and b%c == a%c

print('YES' if solve(a, b, c) else 'NO')

from collections import *
a,b,c = list(map(int,input().split()))
if(c == 0):
	if(a == b): print("YES")
	else: print("NO")
elif(a%c == b%c):
	if (a >= b and c < 0) or (a <= b and c > 0): print("YES")
	else: print("NO")
else: print("NO")

def IsInt(n):
    if n==int(n):
        return True
    else:
        return False

inputs=raw_input().split()

a=int(inputs[0])
b=int(inputs[1])
c=int(inputs[2])

if c!=0:
    n=float(b-a)/c
else:
    n=b-a

if IsInt(n) and c!=0 and n>=0:
    print 'YES'
elif IsInt(n) and c==0 and b==a and n>=0:
    print 'YES'
else:
    print 'NO'

a, b, c = [int(i) for i in input().split()]

if (c == 0):
    if (a == b):
        print("YES")
    else:
        print("NO")
elif ((b - a) % c == 0):
    if ((b - a) / c >= 0):
        print("YES")
    else:
        print("NO")
else:
    print("NO")

from collections import Counter,defaultdict
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
for _ in range(1):
    a,b,c=M()
    if c==0 or a==b:
        if a==b:
            print("YES")
        else:
            print("NO")
    else:
        d=abs(a-b)
        if a>b:
            if d%c==0 and c<0:
                print("YES")
            else:
                print("NO")
        else:
            if d%c==0 and c>0:
                print("YES")
            else:
                print("NO")

a,b,c = map(int,raw_input().split())
if c ==0:
    if b==a:
        print 'YES'
    else:
        print 'NO'
else:
    if (b-a)%c ==0 and (b-a)/c >=0 :
        print 'YES'
    else:
        print 'NO'

def foo ():
    input = map(lambda x: int(x), raw_input().split())
    a1 = input[0]
    favourite = input[1]
    d = input[2]
    if d == 0:
        if a1 == favourite: print 'YES'
        else: print 'NO'
    else:
        k = float(favourite - a1)/float(d)
        if int(k) == k and k>=0: print 'YES'
        else: print 'NO'

foo()

a, b, c = map(int, raw_input().split())

if c == 0 and a != b:
	print 'NO'
elif a == b:
	print 'YES'
elif (b-a)%c == 0 and a > b and c < 0:
	print 'YES'
elif (b-a)%c == 0 and a < b and c > 0:
	print 'YES'
else:
	print 'NO'

a, b, c = raw_input().split()
a = int(a)
b = int(b)
c = int(c)

if (b < a) and (c > 0):
	print("NO")
elif (b > a) and (c < 0):
	print("NO")
elif (c == 0):
	if (a == b):
		print("YES")
	else:
		print("NO")
else:
	b = b - a
	if (b % c == 0):
		print("YES")
	else:
		print("NO")

a, b, c = map(int, raw_input().split())

if (c == 0 and a == b):
    print "YES"
elif (c == 0 and a != b):
    print "NO"
elif (c != 0 and (b - a) / c >= 0 and (b-a) % c == 0):
    print "YES"
else:
    print "NO"

a,b,c=map(int, input().split())
if (c==0 and a==b) or (c!=0 and (b-a)%c==0 and (b-a)/c>=0) :
    print('YES')
else:
    print('NO')

line = raw_input()

a, b, c = [int(i) for i in line.split()]

if c == 0:
	print "YES" if a == b else "NO"
else:
	div = (b - a) / float(c)
	print "YES" if int(div) == div and div >= 0 else "NO"

from sys import stdin, stdout
import math

a,b,c = map(int, stdin.readline().split())

if a==b:
    print('YES')
else:
    if c==0:
        print('NO')
    else:
        if (b-a)*c<0 or abs(a-b)%abs(c)!=0:
            print('NO')
        else:
            print('YES')

#n = int(input())
a, b, c = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
k = (a < b) * (c > 0) + (a > b) * (c < 0)
if a == b:
    print('YES')
else:
    if c == 0:
        print('NO')
    else:
        if (c == 0 and a == b) or (k and (b - a) % c == 0):
            print('YES')
        else:
            print('NO')

string = [int(i) for i in input().split()]
a, b, c = string[0], string[1], string[2]
if c == 0:
    if a == b:
        print('YES')
    else:
        print('NO')
else:
    if (b - a) / c + 1 != 0 and ((b - a) / c + 1) > 0 and ((b - a) / c + 1) % 1 == 0:
        print('YES')
    else:
        print('NO')

a, b, c = list(map(int, input().split()))

if a == b:
    print("YES")
#elif b <= 0 and a < 0 and c < 0 and (a + c)  < b:
#    print("NO")
#elif b >= 0 and a > 0 and c > 0 and (a + c) > b:
#    print("NO")
#elif b < 0 and a > 0 and c > 0:
#    print("NO")
#elif b > 0 and a < 0 and c < 0:
#    print("NO")
elif c == 0 and a != b:
    print("NO")
else:
    match = (b - a) % c
    match_div = (b -a ) / c
    if match == 0 and match_div > 0:
        print("YES")
    else:
        print("NO")

Seq_Element, myNum, incr = [int(x) for x in input().split()]
if incr == 0: print("YES") if Seq_Element == myNum else print("NO")
elif (incr < 0 and Seq_Element < myNum) or (incr > 0 and Seq_Element > myNum):
    print("NO")
else:
    if (myNum - Seq_Element)%incr != 0:
        print("NO")
    else: print("YES")

if __name__ == "__main__":
    #n, m = list(map(int, input().split()))
    a, b, c = map(int, input().split())
    if c == 0:
        if a == b:
            print("YES")
        else:
            print("NO")
    elif (b - a) // c >= 0 and (b - a) % c == 0:
        print("YES")
    else:
        print("NO")

z = input().split()
x = list(map(int, z))
a, b, c = x[0], x[1], x[2]

if a < b and c < 0:
    print("NO")
    exit(0)
if a > b and c > 0:
    print("NO")
    exit(0)
if (a != b) and c == 0:
    print("NO")
    exit(0)
if a == b:
    print("YES")
    exit(0)
if (b - a) % c == 0:
    print("YES")
else:
    print("NO")

def main():
    a, b, c = map(int, input().split())
    if c == 0:
        if b == a:
            print('YES')
        else:
            print('NO')
        return
    print('YES' if ((b - a) % c == 0 and
                    ((c > 0 and b >= a) or (c < 0 and b <= a))) else 'NO')

if __name__ == '__main__':
    main()

inpt=input().split()
a=int(inpt[0])
b=int(inpt[1])
c=int(inpt[2])
res=b-a
#print (res)
if c==0:
    if a==b:
        print("YES")
    else:
        print("NO")
elif b<a and c>0:
    print("NO")
elif a<b and c<0:
    print("NO")
else:
    x=res%c
    if x==0:
        print("YES")
    else:
        print("NO")

a,b,c=list(map(int,input().split()))
if (c==0 and b-a==0) or (c!=0 and (b-a)%c==0 and (b-a)*c>=0):
    print('YES')
else:
    print('NO')

import math
a, b, c = map(int, input().split())
if a == b:
    print('YES')
elif c == 0:
    print('NO')
else:
    if (b - a) > 0 and c > 0:
        if (b - a) % c == 0:
            print('YES')
        else:
            print('NO')
    elif (b - a) < 0 and c < 0:
        if (b - a) % c == 0:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')

a, b, c = str(input()).split()
a = int(a)
b = int(b)
c = int(c)

if c == 0:
    if a == b:
        print("YES")
        exit()
    else:
        print("NO")
        exit()

if (b-a) % c == 0:
    if b > a and c>0:
        print("YES")
    elif b < a and c<0:
        print("YES")
    elif a == b:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

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

if c == 0:
    if a == b:
        print("YES")
    else:
        print("NO")
    exit(0)

k = (b - a) / c

if k == int(k) and k >= 0:
    print("YES")
else:
    print("NO")

from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

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

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

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

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    l[0]=0
    l[1]=0
    prime=[2]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(3,limit+1,2):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

def solve():
    a,b,c=mp()
    if c==0:
        if a!=b:
            print("NO")
        else:
            print("YES")
        return
    x=(b-a+c)/c
    if x==math.floor(x) and x>0 :
        print("YES")
    else:
        print("NO")

for _ in range(1):
    solve()

a, b, c = list(map(int,input().split()))

if c == 0:
    if b == a:
        print('YES')
    else:
        print('NO')
elif (b-a)/c == (b-a) // c >= 0:
    print('YES')
else:
    print('NO')

a,b,c=[int(x) for x in input().split()]

if (c!=0 and (b-a)/c>=0 and (b-a)%c==0) or (c==0 and a==b):
	print('YES')
else:
	print('NO')

def InSequence(a,b, c):
    if c == 0:
        if a == b:
            return "YES"
        else:
            return "NO"
    elif c > 0:
        k = (b-a) % c
        # print("k = ",k)
        if k == 0 and b >= a :
            return "YES"
        else:
            return "NO"
    else:
        k = (b-a) % c
        # print("k = ",k)
        if k == 0 and b <= a :
            return "YES"
        else:
            return "NO"

a,b,c = [int(x) for x in input().split() ]
print(InSequence(a,b,c) )

a, b, c = map(int, input().split(' '))
if (b < a and c > 0) or (b > a and c < 0):
    print('NO')
else:
    if c == 0:
        if a == b:
            print('YES')
        else:
            print('NO')
    else:
        if (b - a) % c == 0:
            print('YES')
        else:
            print('NO')

a,b,c=map(int,raw_input().split())
d=b-a
print ['NO','YES'][d==0 or(d*c>0 and d%c==0)]

f,r,d=list(map(int,input().split()))
if f==r:
    print("YES")
elif d==0 and f==r:
    print("YES")
elif d==0 and f!=r:
    print("NO")
elif (r-f)//d==(r-f)/d and (r-f)/d>0:
    print("YES")
else:
    print("NO")

a,b,c=map(int,input().split())
if a==b: print('YES')
elif c==0: print('NO')
elif (b-a)//c==(b-a)/c and (b-a)//c>0: print('YES')
else: print('NO')

inp=input().split()
a=int(inp[0])
b=int(inp[1])
c=int(inp[2])
if c==0:
    if b!=a:
        print("NO")
    else:
        print("YES")
elif c>0:
    if b<a or (b-a)%c!=0:
        print("NO")
    else:
        print("YES")
else:
    if b>a or (a-b)%(-c)!=0:
        print("NO")
    else:
        print("YES")

import sys

li = raw_input()
lis = li.split(' ')
a = int(lis[0])
b = int(lis[1])
c = int(lis[2])

x = b - a

if x == 0:
    print "YES"
elif c == 0:
    if a != b:
        print "NO"
    else:
        print "YES"
else:
    if x % c == 0:
        xx = x / c
        if xx + 1 > 0:
            print "YES"
        else:
            print "NO"
    else:
        print "NO"

exit

a, b, c = map(int, input().split())
if c == 0 and a == b:
        print("YES")
elif c == 0 and a != b:
        print("NO")
elif (b >= a and (b - a) % c == 0 and c > 0) or (b <= a and c < 0 and (b - a)  % c == 0):
        print("YES")
else:
        print("NO")

a,b,c=map(int,input().split());s=0
if c==0 :
    if a==b :
        print("YES")
    else :
        print("NO")
elif c<0 :
    if a<b :
        print("NO")
    else :
        if abs(a-b)%c==0 :
            print("YES")
        else :
            print("NO")
else :
    if a>b :
        print("NO")
    else :
        if abs(a-b)%c==0 :
            print("YES")
        else :
            print("NO")

a,b,c = map(int,input().split())
if a == b:
    print("YES")
elif a > b and c < 0 and (a-b)%c == 0:
    print("YES")
elif a < b and c >0 and (b-a)%c == 0:
    print("YES")
else:
    print("NO")

a, b, c = map(int, input().split())
if c < 0 and a < b:
    print("NO")
    exit(0)
if c > 0 and a > b:
    print("NO")
    exit(0)
if c == 0 and a == b:
    print("YES")
    exit(0)
if c == 0 and a != b:
    print("NO")
    exit(0)

if abs(a-b)%abs(c) != 0:
    print("NO")
else:
    print("YES")

a,b,c=map(int,input().split())
if a==b:
    print("YES")
elif (a==b and c==0):
    print("YES")
elif ((b-a)>=0 and c>0) and (b-a)%c==0:
    print("YES")
elif ((b-a)<0 and c<0) and (b-a)%c==0:
    print("YES")
else:
    print("NO")

# -*- coding: utf-8 -*-
a,b,c=input("").split(" ")
a=int(a)
b=int(b)
c=int(c)
if c==0:
	if a==b:
		print("YES")
	else:
		print("NO")
else:
	if (b-a)%c==0 and (b-a)/c>=0:
		print("YES")
	else:
		print("NO")

def main():
    inpt = input().split()
    start = int(inpt[0])
    fav = int(inpt[1])
    diff = int(inpt[2])
    if diff == 0 :
        if start == fav :
            print("YES")
        else:
            print("NO")
    else:
        y = (fav - start) / diff
        isint = False

        if y == int(y):
            isint = True

        if isint == True:
            if y >= 0:
                print("YES")
            else:
                print("NO")
        else:
            print("NO")

if __name__ == '__main__': main()

a=(list(map(int, input().split())))
c=a[1]-a[0]
if c==0 and a[2]==0:
    print('YES')
elif (a[2]>0 and c>=0) or (a[2]<0 and c<=0) :
    if c<0:
        c=c*-1
        a[2]=a[2]*-1
    d=c%a[2]
    if d == 0:
        print('YES')
    else:
        print('NO')

else:
    print('NO')

import sys

input1 = [int(elem) for elem in sys.stdin.readline().strip().split()]

if input1[1] == input1[0]:
  print ("YES")

elif input1[1] > input1[0] and input1[2] > 0 and input1[1]%input1[2] == input1[0]%input1[2]:
  print ("YES")

elif input1[1] < input1[0] and input1[2] < 0 and input1[1]%input1[2] == input1[0]%input1[2]:
  print ("YES")

else:
  print("NO")
# 1488583300073

x=list(map(int,input().split()))
y=x[1]-x[0]
if(y==0):
   print('YES')
elif(x[2]==0):
  print('NO')
else:
  z=y%x[2]
  if(z==0):
    if((y//x[2])>0):
      print('YES')
    elif((y//x[2])>0 and x[2]<0):
      print('YES')
    else:
      print('NO')
  else:
    print('NO')

a,b,c = [int(z) for z in input().split()]
if(c == 0):
	if(a == b):
		print('YES')
	else:
		print('NO')
elif (b-a == 0):
	print('YES')
elif( (b-a) == c or ((b-a)%c == 0)):
	if( (a < b and c > 0 ) or (a > b and c < 0)):
		print('YES')
	else:
		print('NO')
else:
	print('NO')

a, b, c = map(int, input().split())
ba = b - a
try:
    print(('NO', 'YES')[ba % c == 0 and ba // c >= 0])
except:
    print(('YES', 'NO')[b != a])

# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out1.out",'w')
a,b,c=map(int,input().split())
if c==0:
	if a==b:
		print("YES")
	else:
		print("NO")
else:
	if (b-a)//c>=0 and (b-a)%c==0 :
		print("YES")
	else:
		print("NO")

a, b, c = map(int, input().split())
if c==0:
    if a==b:
        print('YES')
    else:
        print('NO')
elif a==b:
    print('YES')
elif (c<0 and b-a>0)or (c>0 and b-a<0) or (b-a)%c != 0:
    print('NO')
elif (b-a)%c == 0 :
    print('YES')

a, b, c = map(int, raw_input().split())

def solve():
    if a == b:
        return 'YES'

    if c == 0:
        return 'NO'

    t = (b - a) / c
    if t < 0:
        return 'NO'

    return {True: 'YES', False: 'NO'}[t * c == b - a]

print solve()

a = []

for i in input().split():
	a.append(int(i))

if a[2] == 0:
	if a[0] == a[1]:
		print('YES')
		exit()
	else:
		print('NO')
		exit()

if (a[0] > a[1] and a[2] > 0) or (a[0] < a[1] and a[2] < 0):
	print('NO')
	exit()

if (a[1] - a[0]) % a[2] == 0:
	print('YES')
	exit()

print('NO')

a, b, c = map(int, input().split(' '))
if b > a and c > 0:
    if (b-a) % c == 0:
        print("YES")
    else:
        print("NO")
elif b <= a and c < 0:
    if (a-b) % -c == 0:
        print("YES")
    else:
        print("NO")
elif b == a:
    print("YES")
else:
    print("NO")

a,b,c = map(int,raw_input().split())
if c ==0:
    if b==a:
        print 'YES'
    else:
        print 'NO'
else:
    if (b-a)%c ==0 and (b-a)/c >0 :
        print 'YES'
    else:
        print 'NO'

sequence = list(map(int, input().split()))
a = sequence[0]
b = sequence[1]
c = sequence[2]

while a < b:
    a += c
    if a == b:
        print("YES")
        break
if a > b:
    print("NO")

import string

a, b, c=map(int,raw_input().split())

print a, b, c
while a<b :
	a = a + c
	print a

if a == b : print 'YES'
else : print 'NO'

inpt=input().split()
a=int(inpt[0])
b=int(inpt[1])
c=int(inpt[2])
res=b-a
#print (res)
if c==0:
    if a==b:
        print("YES")
    else:
        print("NO")
else:
    x=res%c
    if x==0:
        print("YES")
    else:
        print("NO")

a, b, c = map(int, raw_input().split())

if c == 0 and a == b:
    print 'YES'
elif c == 0:
    print 'NO'
elif (b - a) % c == 0 and (b - a) / c > 0:
    print 'YES'
else:
    print 'NO'

# -*- coding: utf-8 -*-
"""
Created on Sat Jan 19 01:42:31 2019

@author: KIIT
"""

import math
import os
import random
import re
import sys
if __name__ == '__main__':
    x = list(map(int, input().rstrip().split()))
    a,b,c=x[0],x[1],x[2]

    if(c==0):
        if((b-a)==0):
            print("YES")
        else:
            print("NO")
    else:
        k=(b-a)%c
        if(k==0 and (b-a)/c>0):
            print("YES")
        else:
            print("NO")

#########			##	##     ##    	  ####  #####  ##     #  ##     #		##
	#			   # #	# #   # #		 #	  #	#	#  # #    #  # #    #	   # #
	#			  #  #	#  ###  #	    #		#	#  #  #   #  #  #   #	  #  #
	#			 #####	#	#	#	   #    ###	#	#  #   #  #  #   #  #    #####
	#			#    #	#		#	   #    # #	#	#  #	# #  #	  # #   #    #
######### 	   #     # 	#		#		##### #	#####  #	 ##  #	   ##  #     #

"""

PPPPPPP       RRRRRRR		    OOOO	  VV        VV    EEEEEEEEEE
PPPPPPPP      RRRRRRRR         OOOOOO     VV       VV	  EE
PPPPPPPPP     RRRRRRRRR       OOOOOOOO    VV      VV	  EE
PPPPPPPP      RRRRRRRR        OOOOOOOO    VV     VV    	  EEEEEE
PPPPPPP       RRRRRRR         OOOOOOOO    VV    VV        EEEEEEE
PP  		  RRRR			  OOOOOOOO    VV   VV         EEEEEE
PP			  RR  RR          OOOOOOOO    VV  VV          EE
PP			  RR    RR         OOOOOO     VV VV           EE
PP			  RR      RR        OOOO      VVVV            EEEEEEEEEE

"""

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
import sys
input = sys.stdin.readline
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

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

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0, hi = None):
    if hi == None:
        hi = len(a);
    while lo < hi:
        mid = (lo+hi)//2;
        if a[mid] < x:
            lo = mid+1;
        else:
            hi = mid;
    return lo;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math

from bisect import bisect_left
def check(n, m, k):
	print("inside", (n + (k - 1) * m), k * (k + 1) // 2, (n + (k - 1) * m) // k * k)
	if (n + (k - 1) * m) // k * k  <= k * (k + 1) // 2:
		return True
	return False

def solve():
	a, b, c = map(int,input().split())
	if a != b and c == 0:
		print("NO")
		return
	elif c == 0 and a == b:
		print("YES")
		return
	print(["YES", "NO"][min(abs(b - a) % abs(c), 1)])

if __name__ == '__main__':
	for _ in range(1):
		solve()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))

def main():
    x = input().split()
    a = int(x[0])
    b = int(x[1])
    c = int(x[2])
    if c==0 and b == a:
        print("YES")
    elif c!=0:
        if (b - a) / c > 0 and (b - a) / c == int((b - a) / c):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

if __name__ == '__main__':
    main()

if __name__ == '__main__':
	a,b,c = map(int,raw_input().split())
	t = b-a
	if c == 0:
		if a == b:
			print 'YES'
		else:
			print 'NO'
	elif c < 0:
		if b > a:
			print 'NO'
		else:
			if t % c == 0:
				print 'YES'
			else:
				print 'NO'
	elif c > 0:
		if t % c == 0:
			print 'YES'
		else:
			print 'NO'

a, b, c = map(int, input().split())
try:
    print(('YES', 'NO')[bool((b - a) % c) or min(a, c) > b > max(a, c)])
except:
    print(('YES', 'NO')[b != a])

a,b,c = map(int,input().split())
if a==b:
    print('YES')
elif c==0 and a!=b:
    print('NO')
elif b%abs(c)==a and ((a<b and c>0) or (a>b and c<0)):
    print('YES')
else:
    print('NO')

a,b,c=map(int,raw_input().split())
if c==0:
    if(a==b):
        print "YES"
    else:
        print "NO"
elif(type((b-a)/c)==int and ((b-a)/c)>0):
    print "YES"
else:
    print "NO"

a,b,c=map(int,input().split());s=0
if c==0 :
    if a==b :
        print("YES")
    else :
        print("NO")
elif c<0 :
    if abs(a-b)%c==0 and  a>b:
        print("YES")
    else :
        print("NO")
else :
    if abs(a-b)%c==0 and a<b :
        print("YES")
    else :
        print("NO")

def infinite(a,b,c):
    if c==0:
        return("YES")
    if b-a<0:
        return("NO")
    if (b-a)%c==0:
        return("YES")
    else:
        return("NO")
a,b,c = input().strip().split()
print(infinite(int(a),int(b),int(c)))

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

if c == 0:
	print('YES')
elif (b - a) % c == 0 and (b - a) // c > 0:
	print('YES')
else:
	print('NO')

a, b, c = list(map(int, input().split()))

if a == b:
    print("YES")
elif b <= 0 and a < 0 and c < 0 and (a + c)  < b:
    print("NO")
elif b >= 0 and a > 0 and c > 0 and (a + c) > b:
    print("NO")
elif b < 0 and a > 0 and c > 0:
    print("NO")
elif b > 0 and a < 0 and c < 0:
    print("NO")
elif c == 0 and a != b:
    print("NO")
else:
    match = (b - a) % c
    if match == 0:
        print("YES")
    else:
        print("NO")

def gank(a,b,c):
    d = b - a
    if(d==0):
        return True
    if(c==0):
        return False
    if(c<0):
        d*=-1
        c*=-1
    if(d%c==0):
        return True
    else:
        return False

a,b,c = map(int , raw_input().split(' '))
if(gank(a,b,c)):
    print "YES"
else:
    print "NO"

def favourite_number(a, b, c):
    if a - b == 0:
        return "YES"
    elif c == 0:
        return "NO"
    elif (a - b) % c == 0 or (a - b) * c < 0:
        return "NO"
    return "YES"

A, B, C = [int(i) for i in input().split()]
print(favourite_number(A, B, C))

#-*-coding:utf-8-*-
import math
import string
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

# s , a = s1

# 서로간 이웃한 값 c (si-si-1 = c)
# b가 이 시퀸스에 포함
# si = b
#

a, b, c=map(int,raw_input().split())

while a<b :
	a = a + c

if a == b : print "YES"
else : print "NO"

a,b,c=map(int,input().split())
for i in range(1,10000000000):
    if((b<0 and c<0) or (b>0 and c>0)):
        if((b-a)%(c*i)==0):
            print("YES")
            exit()
        elif((c*i)>(b-a)):
            print("NO")
            exit()
    else:
        print("NO")
        exit()

a,b,c = map(int , raw_input().split())
ans = ""
if c == 0:
    if a == b: ans = "YES"
    else:      ans = "NO"
elif c > 0:
    if (b-a)%c == 0 and (b-a) > 0: ans = "YES"
    else:            ans = "NO"
else:
    if (a-b)%(-c) == 0 and (a-b) > 0: ans = "YES"
    else:           ans = "NO"
print ans

# -*- coding: utf-8 -*-
a,b,c=input("").split(" ")
a=int(a)
b=int(b)
c=int(c)
if c==0:
	if a==b:
		print("YES")
	else:
		print("NO")
else:
	if b in range(a,10**18,c):
		print("YES")
	else:
		print("NO")

a, b, c = map(int, input().split(' '))
if c == 0:
    if a == b:
        print('YES')
    else:
        print('NO')
else:
    if (b - a) % c == 0:
        print('YES')
    else:
        print('NO')

import math
a, b, c = map(int, input().split())
if a == b:
    print('YES')
elif a == 0:
    if b > 0 and c > 0:
        print('NO')
    elif b > 0 and c < 0:
        c = int(math.fabs(c))
        if b % c == 0:
            print('YES')
        else:
            print('NO')
    elif b < 0 and c < 0:
        print('NO')
    elif b < 0 and c > 0:
        b = int(math.fabs(b))
        if b % c == 0:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')
elif b == 0:
    if int(math.fabs(a)) % int(math.fabs(a)) == 0:
        print('YES')
    else:
        print('NO')
elif c == 0:
    print('NO')
else:
    a = int(math.fabs(a))
    b = int(math.fabs(b))
    c = int(math.fabs(c))
    if (b - a) % c == 0:
        print('YES')
    else:
        print('NO')

a, b, c = map( int, input().split() );
#a -first
#b -like
#c -difference
if a == b:
    print ('YES');
elif c == 0:
    print ('NO');
elif b < a:
    if c < a:
        if (b - a)%c == 0:
            print ('YES');
        else:
            print ('NO');
    else:
        print('NO');
else:
    if (b - a)%c == 0:
        print ('YES');
    else:
        print ('NO');

from sys import stdin
a,b,c = map(int,stdin.readline().split())

if(a != b and c == 0):
    print("NO")
elif( (a == b ) or (a > b and c < 0) or ( b > a and ((b-a)% c == 0)) ):
    print("YES")
else:
    print("NO")

a,b,c=map(int,raw_input().split())
if c==0:
    print 'YES' if a==b else 'NO'
else:
    print 'YES' if (b-a)%c==0 and (b-c)*c>0 else 'NO'

a,s,d = map(int,input().split())
if(d!=0):
    n = ((s-a)/d+1)
    j = n%1
    if(j==0.0):
        if(n>0):
            print("YES")
    if(d==0):
        if(a==s):
            print("YES")
    else:
        print("NO")

inpt=input().split()
a=int(inpt[0])
b=int(inpt[1])
c=int(inpt[2])
res=b-a
#print (res)
if c==0:
    if a==b:
        print("YES")
    else:
        print("NO")
elif b<a:
    print("NO")
else:
    x=res%c
    if x==0:
        print("YES")
    else:
        print("NO")

read = lambda: map(int, input().split())
a, b, c = read()
if c == 0 and (b == a): ans = 'YES'
elif c != 0 and (b - a) % c == 0 and (b - a) // c > 0: ans = 'YES'
else: ans = 'NO'
print(ans)

l = map(int, raw_input().split())
a = l[0]
b = l[1]
c = l[2]

if c!=0 and (b-a)!=0 and b>a:
    if (b-a)%c==0:
        print "YES"
    else:
        print "NO"
elif c==0 and (b-a)!=0:
    print "NO"
elif a==b:
    print "YES"
else:
    print "NO"

from collections import *
a,b,c = list(map(int,input().split()))
if((c == 0 and a == b) or a%c == b%c):
	if (a >= b and c < 0) or (a <= b and c > 0): print("YES")
	else: print("NO")
else: print("NO")

a,b,c=map(int,raw_input().split())

if c==0:
	if  a==b:
		print "YES"
	else:
		print "NO"
else:
	if (b-a)%c:
		print "NO"
	else:
		print "YES"

a, b, c = map(int, input().split())
if c == 0:
    if a == b:
        print('YES')
    else:
        print('NO')
else:
    if (b - a) % c == 0 and (b - 1) / c > 0:
        print('YES')
    else:
        print('NO')

a, b, c = map(int, input().split())
if a == b:
    print('YES')
elif c == 0:
    print('NO')
else:
    if c <= 0:
        print('NO')
    elif b >= a:
        if (b - a) % c == 0:
            print('YES')
        else:
            print('NO')
    else:
        if c >= 0:
            print('NO')
        else:
            if (a - b) % c == 0:
                print('YES')
            else:
                print('NO')

import sys
x=input().split()
a=int(x[0])
b=int(x[1])
c=int(x[2])
if c==0:
    if a==b:
        print('YES')
else:
    p=((b-a)/(c))+1
    if int(p)==float(p) and p>0:
        print('YES')
        sys.exit(0)
print('NO')

d=list(map(int,input().split()))
if(d[1]<d[0]):
    print("NO")
elif(d[0]==d[1]):
    print("YES")
elif(d[2]==0):
    print("NO")
else:
    n=(d[1]-d[0])/d[2]+1
    if(n%1==0):
        print("YES")
    else:
        print("NO")

a, b, c = [int(x) for x in input("").split(" ")]

out = "NO"
if c != 0:
    if (b - a) % c == 0:
        out = "YES"
else:
    if a == b:
        out = "YES"

print(out)

string = [int(i) for i in input().split()]
a, b, c = string[0], string[1], string[2]
if c == 0:
    if a == b:
        print('YES')
    else:
        print('NO')
else:
    if ((b - a) / c + 1) % 1.0 == 0:
        print('YES')
    else:
        print('NO')

a,b,c = list(map(int,input().rstrip().split()))
if c==0:
    if a==b:
        print("YES")
    else:
        print("NO")
else:
    if (b-a)%c==0 and b-a>0 and c>0:
        print("YES")
    elif (b-a)%c==0 and b-a<0 and c<0:
        print("YES")
    else:
        print("NO")

a, b, c = map(int, input().split(' '))
if b < a and c > 0:
    print('NO')
else:
    if c == 0:
        if a == b:
            print('YES')
        else:
            print('NO')
    else:
        if (b - a) % c == 0:
            print('YES')
        else:
            print('NO')

a, b, c = map( int, input().split() );
#a -first
#b -like
#c -difference
if a == b:
    print ('YES');
elif b < a:
    print ('NO');
elif c == 0:
    print ('NO');
else:
    if (b - a)%c == 0:
        print ('YES');
    else:
        print ('NO');

a, b, c = map(int, input().split())
if  c==0:
    if a==b:print("YES")
    else:print("NO")
else:
    if b >=a:
        if (a>=0 and b>=0) or (b<0 and a<0) :
            if a%c == b%c:
                print("YES")
            else:
                print("NO")
        else:
            if a%c + b%c == c:
                print("YES")
            else:
                print("NO")
    else:
        print("NO")

a, b, c = map(long, raw_input().split())

if b == a: print "YES"
elif c == 0: print "NO"
elif c < 0 and b > a: print "NO"
elif c > 0 and b < a: print "NO"
else:
    if c == 1 and b > a: print "YES"
    elif c == -1 and b < a: print "YES"
    elif c > b and c > 0: print "NO"
    elif c < b and c < 0: print "NO"
    else:
        flag = False
        if b > a:
            temp = b - a
            if temp % c == 0: flag = True
        elif b < a:
            temp = a - b
            if temp % c == 0: flag = True

        if flag: print "YES"
        else: print "NO"

a,b,c = [int(z) for z in input().split()]
if(c == 0):
	if(a == b):
		print('YES')
	else:
		print('NO')
elif((b-a) == 0 or (b-a) == c or ((b-a)%c == 0 and b >= c )):
	print('YES')
else:
	print('NO')

def InSequence(a,b, c):
    if c == 0:
        if a == b:
            return "YES"
        else:
            return "NO"
    elif c > 0:
        k = (b-a) % c
        # print("k = ",k)
        if k == 0 and b > a :
            return "YES"
        else:
            return "NO"
    else:
        k = (b-a) % c
        # print("k = ",k)
        if k == 0 and b < a :
            return "YES"
        else:
            return "NO"

a,b,c = [int(x) for x in input().split() ]
print(InSequence(a,b,c) )

a, b, c = map(int, raw_input().split())

if (c == 0 and a == b):
    print "YES"
elif (c == 0 and a != b):
    print "NO"
elif ((b - a > 0) and (c != 0 and (b - a) % c == 0)):
    print "YES"
else:
    print "NO"

a,b,c=map(int,input().split())
if(c==0 and a==b):
    print('YES')
elif(c==0 and a!=b):
    print('NO')
else:
    while(1):
        a=a+c
        if(b==a):
            print('YES')
            break
        elif(a>b):
            print('NO')
            break

inpt=input().split()
a=int(inpt[0])
b=int(inpt[1])
c=int(inpt[2])
res=b-a
#print (res)
if c==0:
    if a==b:
        print("YES")
    else:
        print("NO")
elif b<a:
    print("NO")
else:
    x=res%c
    if x==0:
        print("YES")
    else:
        print("NO")

def task_1():
	result = 'YES'
	a, b, c = map(lambda x: int(x), input().split(' '))

	if c == 0 and a == b:
		return 'YES'
	elif c == 0 and a != b:
		return 'NO'

	d = float(b - a) / c

	if d > 0 and d == int(d):
		result = 'YES'
	else:
		result = 'NO'

	return result

print(task_1())

import sys
start, value, increment = map(int, sys.stdin.readline().strip().split())

if start == value:
    print ("YES")
    exit()

if increment == 0:
    if value == start:
        print ("YES")
    else:
        print("NO")
    exit()

if start < 0:
    value = value + abs(start)
else:
    value = value - start
start = 0

print(start, value, increment)
#if start == 0:
#
#if value == 0:
#
#
#if value < 0:
#    if increment > 0:
#        if start > 0:
#            print ("NO")
#        else:
#            if start < value:
#
#            else:
#                print ("NO")
#
#
#    if increment < 0:
#        if start < 0:
#
#        else:
#
#if value > 0:
#
#
#
#
#    if (start > 0 and increment > 0) or  (start < 0 and increment > 0:
#        print ("NO")
#        # start is neg and increment is neg
#
#
#        print ("YES")
#    else:
#        if
#
#    else:
#        print ("YES")
#    exit()
#
#if start == 0:
#    if value % increment == 0 and value >= start:
#        print ("YES")
#    else:
#        print ("NO")
#    exit()
#
#
#
#value = value - start
#start = 0

if value % increment == 0 and value >= start:
    print ("YES")
else:
    print ("NO")
# 1488583250099

#-*-coding:utf-8-*-
import math
import string
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

# s , a = s1

# 서로간 이웃한 값 c (si-si-1 = c)
# b가 이 시퀸스에 포함
# si = b
#

a, b, c=map(int,raw_input().split())

if a == b and c == 0 : print "YES"
elif a <= b and c !=0 :
	if (b - a) % c == 0 :  print "YES"
	else : print "NO"
else : print "NO"

a, b , c = map(int, input().split())
flag = 1
for i in range(100000):
    if a + c*i == b :
        print("YES")
        flag = 0
        break

if flag == 1:
    print("NO")
else:
    print("YES")

a,b,c=map(int,input().split())
if a==b:
    print('YES')
else:
    if c==0:
        print('NO')
    else:
        n=((b-1)/c)+1
        if (int(n)==n) and (n>0):
            print('YES')
        else:
            print('NO')

def infinite(a,b,c):
    if c==0:
        return("YES")
    if (b-a)%c==0:
        return("YES")
    else:
        return("NO")
a,b,c = input().strip().split()
print(infinite(int(a),int(b),int(c)))

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

while(a < b):
    a = c + a
if(a == b):
    print("YES")
else:
    print("NO")

a,b,c=map(int,input().split());s=0
if c==0 :
    if a==b :
        print("YES")
    else :
        print("NO")
else :
    if abs(a-b)%c==0 and (a>0 and b>0) :
        print("YES")
    if abs(a-b)%c==0 and (a<0 and b<0) :
        print("YES")
    else :
        print("NO")

import math

a,b,c=map(int,input().split())
r=0
if c==0 and b==a:
    print('YES')
    r=1

if c==0 and b!=a:
    print('NO')
    r=1
k=0
if (a<0 and c<0 and b>a) or( a>0 and c>0 and b<0):
    print('NO')
    k=1
if r==0 and k==0:
    if b-a+c!=0:
        if (b-a+c)%c==0  :
            print('YES')
        else:
            print('NO')
    else:
        print('NO')

a, b, c = map(int, input().split())
ans = 0
if (c == 0):ans = 1
elif ((b-a) % c == 0 and (b-a) >= 0 and c > 0):ans = 1
elif ((b-a) % c == 0 and (b-a) <= 0 and c < 0):ans = 1
print('YES' if ans else 'NO')

def task_1():
	result = 'YES'
	a, b, c = map(lambda x: int(x), input().split(' '))

	if c == 0 and a == b:
		return 'YES'
	elif c == 0 and a != b:
		return 'NO'

	if (b - a) % c == 0 and (c > 0 and a > 0 and b > 0):
		result = 'YES'
	elif (b - a) % c == 0 and (c > 0 and a > 0 and b < 0):
		result = 'NO'
	elif (b - a) % c == 0 and (c > 0 and a < 0 and b > 0):
		result = 'YES'
	else:
		result = 'NO'

	return result

print(task_1())

import sys

input = list(map(int,sys.stdin.readline().strip().split()))

if input[2] == 0 and input[1] == input[0]:
  print("YES")
elif input[1] % input[2] == input[0] and input[1] >= input[0]:
  print("YES")
else:
  print("NO")
# 1488579638772

a=(list(map(int, input().split())))
c=a[1]-a[0]
if c==0 and a[2]==0:
    print('YES')
elif (a[2]>0 and c>=0) or (a[2]<0 and c<0) :
    if c<0:
        c=c*-1
        a[2]=a[2]*-1
    d=c%a[2]
    print('l')
    if d == 0:
        print('YES')
    else:
        print('NO')

else:
    print('NO')

from sys import stdin
a,b,c = map(int,stdin.readline().split())

if((a != b and c == 0) or (b > a and c < 0) ):
    print("NO")
elif( (a == b ) or (a > b and c < 0) or ( b > a and ((b-a)% c == 0)) ):
    print("YES")
else:
    print("NO")

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

k = a
found = False
while k <= b:
	if k == b:
		print('YES')
		found = True
		break
	k += c

if not found:
	print('NO')

string = input()
numbers = string.split(" ")
a = int(numbers[0])
b = int(numbers[1])
c = int(numbers[2])
while a >= b:
    a += c
if a == b:
    results = "YES"
else:
    results = "NO"
print(results)

line = input()
lin = list(map(int, line.split()))
flag = 1

tmp = (lin[1] - lin[0])
if lin[2] == 0:
	if tmp == 0:
		flag = 0
elif tmp >=0:
	flag = tmp %lin[2]
if flag == 0:
	print("YES")
else:
	print("NO")

a,b,c = map(int, raw_input().split())
if c!= 0 and (b-a)%c == 0:
	print "YES"
elif c==0 and b-a == 0:
	print "YES"
else:
	print "NO"

a,b,c = map(int,input().split())
if a==b:
    print('YES')
elif b%c==a and ((a<b and c>0) or (a>b and c<0)):
    print('YES')
else:
    print('NO')

lis=input().split()
lis[0]=int(lis[0])
lis[1]=int(lis[1])
lis[2]=int(lis[2])
if(lis[2]==0):
	if(lis[0]==lis[1]):
		print('YES')
	else:
		print('NO')
elif(lis[1]-lis[0]==0):
	print('NO')
elif(lis[1]-lis[0]<0):
	d=lis[1]-lis[0]
	if(lis[2]<0 and (-d)%-lis[2]==0):
		print ('YES')
	else:
		print ('NO')
elif((lis[1]-lis[0])%lis[2]==0):
	print('YES')
else:
	print('NO')

a,b,c = map(int,raw_input().split())

if(c == 0):
	if(a ==b):
		print "YES"
	else:
		print "NO"
else:
	if((b-a)% c == 0):
		print "YES"
	else:
		print "NO"

a, b, c = map(int, input().split(' '))
i = a
l = list()

if a == b and c == 0:
	print('YES')
elif a != b and c == 0:
	print('NO')
else:
	if b >= 0:
		while i <= b:
			print(i)
			l.append(i)
			i += c
	else:
		while i >= b:
			print(i)
			l.append(i)
			i += c
	if b in l:
		print('YES')
	else:
		print('NO')

a,b,c = map(int, raw_input().split())
ans = 'NO'
if c == 0:
	if a == b:
		ans = 'YES'
else:
	if (b-a)%c == 0 and (b-a)/c > 0:
		ans = 'YES'
print ans

a, b, c = map(int, input().split())
if b >= a:
    if a == b:
        print('YES')
    elif c == 0:
        print('NO')
    elif (b - a) % c == 0:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

a, b, c = list(map(int, input().split()))
if (a == b) and (c == 0):
    print('YES')
elif c == 0:
    print('NO')
elif (b - a) % c == 0:
    if (c > 0) and (b > a):
        print('YES')
    elif (c < 0) and (b < a):
        print('YES')
    else:
        print('NO')
else:
    print('NO')

a, b, c= map(int,raw_input().split())

print "YES" if  (c==0 and a==b) or (c!=0 and (b-a)%c==0 and (b-a)/c>0)  else "NO"

#n = int(input())
a, b, c = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
if (c == 0 and a == b) or (((a < b) * (c > 0)) and (b - a) % c == 0):
    print('YES')
else:
    print('NO')

a,b,c=map(int,raw_input().split())
print 'NO' if c and (b-a)%c or not c and a==b else 'YES'

a,b,c=map(int,input().split())
if c!=0:
    r=(b-a)/c
    if r-int(r)==0 and r>0:
        print('YES')
    else:
        print('NO')
elif c==0and b==a:
    print('YES')

a,b,c = map(int,input().split())
if c==0 and a==b:
    print('YES')
elif c==0 and a!=b:
    print('NO')
elif b%abs(c)==a and ((a<b and c>0) or (a>b and c<0)):
    print('YES')
else:
    print('NO')

a,b,c=map(int,input().split())
if c!=0:
    r=(b-a)/c
    if r-int(r)==0 and r>0:
        print('YES')
    else:
        print('NO')
elif c==0and b==a:
    print('YES')
elif c==0and b!=a:
    print('NO')
elif b==a:
    print('YES')

s = input().split()
a = int(s[0])
b = int(s[1])
c = int(s[2])

def test(a,b,c):
	if (a==b):
		return("YES")
	elif (b<a):
		return("NO")
	else:
		a = a + c
		return(test(a,b,c))

print(test(a,b,c))

#-*-coding:utf-8-*-
import math
import string
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

a, b, c=map(int,raw_input().split())

print a, b, c
while a<b :
	a = a + c
	print a

if a == b : print "YES"
else : print "NO"

a, b, c = map(int, input().split())
if c == 0:
    if a == b:
        print('YES')
    else:
        print('NO')
else:
    x = (b - a) / c
    y = (b - a) // c
    if float(y) == x and x > 0:
        print('YES')
    else:
        print('NO')

a, b, c = map(int, input().split(' '))
i = a
l = list()

if a == b and c == 0:
	print('YES')
elif a != b and c == 0:
	print('NO')
else:
	while i < b:
		l.append(i)
		i += c

	if b in l:
		print('YES')
	else:
		print('NO')

a,b,c = map(int, raw_input().split())
if a>b:
	print "NO"
else:
	if c!= 0 and (b-a)%c == 0:
		print "YES"
	elif c==0 and b-a == 0:
		print "YES"
	else:
		print "NO"

a,fav,sec=map(int,input().split())
if a ==fav:
    print('YES')
elif (sec==0) or (sec>fav)  :
    print('NO')
elif (fav-a)%sec or ((fav>0)and ((sec<0)and (a<0))) :
    print('NO')
else:
    print('YES')

a,b,c = map(int,input().split())
if a==b:
    print('YES')
elif c==0 and a!=b:
    print('NO')
elif b%abs(c)==a and ((a<b and c>0) or (a>b and c<0)):
    print('YES')
else:
    print('NO')

a, b, c = list(map(int, input().split()))
if c == 0 and a != b:
	print("NO")
	exit()
elif c == 0 and a == b:
	print("YES")
	exit()
out = (b-a)/c
if int(out) == out:
	print("YES")
else:
	print("NO")

import sys
start, value, increment = map(int, sys.stdin.readline().strip().split())

if increment == 0:
    if value == start:
        print ("YES")
    else:
        print("NO")
    exit()

if value % increment == start and value >= start:
    print ("YES")
else:
    print ("NO")
# 1488580479863

x=list(map(int,input().split()))
y=x[1]-x[0]
if(y==0):
   print('YES')
elif(x[2]==0):
  print('NO')
elif(x[2]>y):
  print('NO')
else:
  z=y%x[2]
  if(z==0):
    print('YES')
  else:
    print('NO')

a, b, c = map(int,raw_input().split())

print 'YES' if (c == 0 and a == b) or (c > 0 and b > a and (b - a) % c == 0) or (c < 0 and b < a and (b - a) % c == 0) else 'NO'

a,b,c = [int(z) for z in input().split()]
if(c == 0):
	if(a == b):
		print('YES')
	else:
		print('NO')
elif (b-a == 0):
	print('YES')
elif( (b-a) == c or ((b-a)%c == 0 and b >= c )):
	if( (a < b and c > 0 ) or (a > b and c < 0)):
		print('YES')
	else:
		print('NO')
else:
	print('NO')

a,b,c=list(map(int,input().split()))
b=b-a;
if c==0:
    if b==0:
        print("YES");
else:
    b=b/c
    if int(b)==b:
        print("YES")
    else:
        print("NO")

a, b, c = map(int, input().split())
try:
    print(('YES', 'NO')[bool((b - a) % c) or min(a, c) > b > max(a, c)])
except:
    print(('YES', 'NO')[b != a])


import sys

import itertools

from collections import defaultdict

factorials = [1] * 19

for i in range(1, 19):
    factorials[i] = i * factorials[i - 1]

def cumsum(l):
    n = len(l)
    for i in range(1, n):
        l[i] += l[i-1]

def enum(l):

    global K, S

    options = itertools.product(*([(0, 1, 2)] * len(l)))

    d = defaultdict(lambda: [0] * (25 + 1))

    for opts in options:

        s = 0
        marks = 0
        for i, opt in enumerate(opts):

            if s > S:
                break

            if opt == 1:
                s += l[i]
            elif opt == 2:
                if l[i] <= 18:
                    s += factorials[l[i]]
                    marks += 1
                else:
                    s = S + 1

        if s <= S:
            d[s][marks] += 1

    return d

[n, K, S] = map(int, sys.stdin.next().split(' '))
l = sorted(map(int, sys.stdin.next().split(' ')))

p1 = enum(l[:(len(l) / 2)][::-1])
p2 = enum(l[(len(l) / 2):][::-1])

variants = 0
for s in p1:
    if S - s in p2:
        m1 = p1[s]
        m2 = p2[S - s]
        cumsum(m2)
        for (k1, c1) in enumerate(m1[:(K + 1)]):
            c2 = m2[(K - k1)]
            variants += c1 * c2

print(variants)

import sys

import itertools

from collections import defaultdict

factorials = [1] * 19

for i in range(1, 19):
    factorials[i] = i * factorials[i - 1]

def cumsum(l):
    n = len(l)
    for i in range(1, n):
        l[i] += l[i-1]

def enum(l):

    global K, S

    options = itertools.product(*([(0, 1, 2)] * len(l)))

    d = defaultdict(lambda: [0] * (25 + 1))

    for opts in options:

        s = 0
        marks = 0
        for i, opt in enumerate(opts):

            if s > S:
                break

            if opt == 1:
                s += l[i]
            elif opt == 2:
                if l[i] <= 18:
                    s += factorials[l[i]]
                    marks += 1
                else:
                    s = S + 1

        if s <= S:
            d[s][marks] += 1

    return d

[n, K, S] = map(int, sys.stdin.next().split(' '))
l = sorted(map(int, sys.stdin.next().split(' ')))

p1 = enum(l[:(len(l) / 2)][::-1])
p2 = enum(l[(len(l) / 2):][::-1])

variants = 0
for s in p1:
    if S - s in p2:
        m1 = p1[s]
        m2 = p2[S - s]
        for (k1, c1) in enumerate(m1[:(K + 1)]):
            for (k2, c2) in enumerate(m2[:(K + 1 - k1)]):
                if k1 + k2 <= K:
                    variants += c1 * c2

print(variants)

fact = [ 1 ]
for i in range( 1, 20, 1 ):
  fact.append( fact[ i - 1 ] * i )

from collections import defaultdict

N, K, S = map( int, input().split() )
A = list( map( int, input().split() ) )

ldp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]
ldp[ 0 ][ 0 ][ 0 ] = 1
for i in range( N // 2 ):
  for j in range( K + 1 ):
    ldp[ ~ i & 1 ][ j ].clear()
  for j in range( K + 1 ):
    for key in ldp[ i & 1 ][ j ]:
      ldp[ ~ i & 1 ][ j ][ key ] += ldp[ i & 1 ][ j ][ key ] # toranai
      ldp[ ~ i & 1 ][ j ][ key + A[ i ] ] += ldp[ i & 1 ][ j ][ key ] # toru
      if j + 1 <= K and A[ i ] <= 18:
        ldp[ ~ i & 1 ][ j + 1 ][ key + fact[ A[ i ] ] ] += ldp[ i & 1 ][ j ][ key ] # kaijyou totte toru

rdp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]
rdp[ 0 ][ 0 ][ 0 ] = 1
for i in range( N - N // 2 ):
  for j in range( K + 1 ):
    rdp[ ~ i & 1 ][ j ].clear()
  for j in range( K + 1 ):
    for key in rdp[ i & 1 ][ j ]:
      rdp[ ~ i & 1 ][ j ][ key ] += rdp[ i & 1 ][ j ][ key ]
      rdp[ ~ i & 1 ][ j ][ key + A[ N // 2 + i ] ] += rdp[ i & 1 ][ j ][ key ]
      if j + 1 <= K and A[ N // 2 + i ] <= 18:
        rdp[ ~ i & 1 ][ j + 1 ][ key + fact[ A[ N // 2 + i ] ] ] += rdp[ i & 1 ][ j ][ key ]

ans = 0
for i in range( K + 1 ):
  for key in ldp[ N // 2 & 1 ][ i ]:
    for j in range( 0, K - i + 1, 1 ):
      ans += ldp[ N // 2 & 1 ][ i ][ key ] * rdp[ N - N // 2 & 1 ][ j ][ S - key ]

print( ans )

from math import factorial
from collections import defaultdict
def main():
    n, k, s = map(int, raw_input().split())
    a = map(int, raw_input().split())
    def f(b):
        res = [defaultdict(int) for _ in xrange(k + 1)]
        res[k][0] = 1
        for x in b:
            nr = [defaultdict(int) for _ in xrange(k + 1)]
            for j in xrange(k + 1):
                for y, t in res[j].viewitems():
                    if j and x <= 18 and factorial(x) + y <= s:
                        nr[j-1][factorial(x) + y] += t
                    if x + y <= s:
                        nr[j][x + y] += t
                    nr[j][y] += t
            res = nr
        return res
    def g(b):
        res = [defaultdict(int) for _ in xrange(k + 1)]
        res[k][s] = 1
        for x in b:
            nr = [defaultdict(int) for _ in xrange(k + 1)]
            for j in xrange(k + 1):
                for y, t in res[j].viewitems():
                    if j and x <= 18 and y - factorial(x) >= 0:
                        nr[j-1][y - factorial(x)] += t
                    if y - x >= 0:
                        nr[j][y - x] += t
                    nr[j][y] += t
            res = nr
        return res
    dl = f(a[:n/2])
    dr = g(a[n/2:])
    ans = 0
    for i, d in enumerate(dl):
        for x, t in d.viewitems():
            for j in xrange(k - i, k + 1):
                ans += t * dr[j][x]
    print ans
main()

from math import factorial
fac = factorial

def dfs(lst):
    sums = [{} for i in xrange(k+1)]
    sums[0][0]=1
    while len(lst)>0:
        cur = lst.pop(0)
        temp = [item.copy() for item in sums]
        for i in xrange(k+1):
            for j in temp[i]:
                if j + cur <=s:
                    if j + cur not in sums[i]:
                        sums[i][j + cur] = temp[i][j]
                    else:
                        sums[i][j + cur] += temp[i][j]
                    if cur<19 and i<k and j+fac(cur)<=s:
                        if j+fac(cur) not in sums[i+1]:
                            sums[i+1][j+fac(cur)] = temp[i][j]
                        else:
                            sums[i+1][j+fac(cur)] += temp[i][j]
    return sums

n, k, s = map(int, raw_input().split())
a = [int(item) for item in raw_input().split()]
a.sort()

first = dfs(a[:n/2])
second = dfs(a[n/2:])

count = 0
for i in xrange(k+1):
    for sum1 in first[i]:
        for kk in xrange(k-i+1):
            if s-sum1 in second[kk]:
                count += first[i][sum1]*second[kk][s-sum1]
print count

from sys import stdin, stdout
import math
from collections import defaultdict

def Comb(nn,rr):
    f = math.factorial
    return f(nn) / f(rr) / f(nn-rr)

n,k,S = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]

aset = set(a)
alist = list(aset)
alist.sort()

plist = []
for i in alist:
	plist.append((i,a.count(i)))

oplist = []
for x,c in plist:
	tlist = []
	if x > 18:
		for i in xrange(c+1):
			tlist.append((i*x,0,Comb(c,i)))  # (amount added, stickers used, multiplier)
	else:
		xfact = math.factorial(x)
		for nf in xrange(c+1):
			for i in xrange(nf,c+1):
				tlist.append((nf*xfact+(i-nf)*x, nf, Comb(c,i)*Comb(i,nf)))
	oplist.append(tlist)

def rec(mult,d,l,i,f,nn,s=0):
	if i < nn:
		for add, nf, mm in oplist[i]:
			x = s + add
			ff = f + nf
			if x <= S and ff <= k:
				if add > 0:
					l.add(x)
					d[ff][x] += mult*mm
				rec(mult*mm, d, l, i+1, ff, nn, x)

n = len(alist)

halflist1 = []
halflist2 = []
oplist.reverse()
hl1 = 1
hl2 = 1
for i in xrange(n):
	if hl1 <= hl2:
		hl1 *= len(oplist[i])
		halflist1.append(oplist[i])
	else:
		hl2 *= len(oplist[i])
		halflist2.append(oplist[i])

oplist = halflist1 + halflist2

dl1 = [defaultdict(int) for i in xrange(k+1)]
dl1[0][0] = 1
nn = n/2
s = set()
rec(1,dl1,s,0,0,nn)
l1 = list(s)
l1.append(0)
dl2 = [defaultdict(int) for i in xrange(k+1)]
dl2[0][0] = 1
s = s = set()
rec(1,dl2,s,nn,0,n)
l2 = list(s)
l2.append(0)

count = 0
l1.sort()
l2.sort(reverse=True)
i = 0
j = 0

while i < len(l1):
	while l2[j] > S - l1[i]:
		j += 1
	if l1[i] + l2[j] == S:
		for m in xrange(k+1):
			for r in xrange(m+1):
				count += dl1[r][l1[i]] * dl2[m-r][l2[j]]
	i += 1

print count

from sys import stdin, stdout
import math
from collections import defaultdict

def Comb(nn,rr):
    f = math.factorial
    return f(nn) / f(rr) / f(nn-rr)

n,k,S = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]

aset = set(a)
alist = list(aset)
alist.sort()

plist = []
for i in alist:
	plist.append((i,a.count(i)))

oplist = []
for x,c in plist:
	tlist = []
	if x > 18:
		for i in xrange(c+1):
			tlist.append((i*x,0,Comb(c,i)))  # (amount added, stickers used, multiplier)
	else:
		xfact = math.factorial(x)
		for nf in xrange(c+1):
			for i in xrange(nf,c+1):
				tlist.append((nf*xfact+(i-nf)*x, nf, Comb(c,i)*Comb(i,nf)))
	oplist.append(tlist)

'''
print plist
for tlist in oplist:
	print tlist

b = list(a)
c = [False for x in a]
for i in xrange(len(b)):
	if b[i] < 19:
		b[i] = math.factorial(b[i])
		c[i] = True
'''

def rec(mult,d,l,i,f,nn,s=0):
	if i < nn:
		for add, nf, mm in oplist[i]:
			x = s + add
			ff = f + nf
			if x <= S and ff <= k:
				if add > 0:
					l.add(x)
					d[ff][x] += mult*mm
				rec(mult*mm, d, l, i+1, ff, nn, x)

'''
def rec(d,l,i,f,nn,s=0):
	if i < nn:
		rec(d,l,i+1,f,nn,s)
		x = s+a[i]
		if x <= S:
			rec(d,l,i+1,f,nn,x)
			l.add(x)
			d[f][x] += 1
		if c[i] and f < k:
			x = s+b[i]
			if x <= S:
				rec(d,l,i+1,f+1,nn,x)
				l.add(x)
				d[f+1][x] += 1
'''

n = len(alist)

dl1 = [defaultdict(int) for i in xrange(k+1)]
dl1[0][0] = 1
nn = n/2
s = set()
rec(1,dl1,s,0,0,nn)
l1 = list(s)
l1.append(0)
dl2 = [defaultdict(int) for i in xrange(k+1)]
dl2[0][0] = 1
s = s = set()
rec(1,dl2,s,nn,0,n)
l2 = list(s)
l2.append(0)

count = 0
l1.sort()
l2.sort(reverse=True)
i = 0
j = 0

while i < len(l1):
	while l2[j] > S - l1[i]:
		j += 1
	if l1[i] + l2[j] == S:
		for m in xrange(k+1):
			for r in xrange(m+1):
				count += dl1[r][l1[i]] * dl2[m-r][l2[j]]
	i += 1

print count

from math import factorial
from collections import defaultdict
def main():
    n, k, s = map(int, raw_input().split())
    a = map(int, raw_input().split())
    def f(b):
        res = defaultdict(int)
        res[0] = 1
        for x in b:
            nr = defaultdict(int)
            for y, t in res.viewitems():
                if x <= 18:
                    nr[factorial(x) + y] += t
                nr[x + y] += t
                nr[y] += t
            res = nr
        return res
    def g(b):
        res = defaultdict(int)
        res[s] = 1
        for x in b:
            nr = defaultdict(int)
            for y, t in res.viewitems():
                if x <= 18:
                    nr[y - factorial(x)] += t
                nr[y - x] += t
                nr[y] += t
            res = nr
        return res
    dl = f(a[:n/2])
    dr = g(a[n/2:])
    b = set(dl.keys() + dr.keys())
    ans = 0
    for x in b:
        ans += dl[x] * dr[x]
    print ans
main()

from math import factorial
from collections import defaultdict
def main():
    n, k, s = map(int, raw_input().split())
    a = map(int, raw_input().split())
    def f(b):
        res = [defaultdict(int) for _ in xrange(k + 1)]
        res[k][0] = 1
        for x in b:
            nr = [defaultdict(int) for _ in xrange(k + 1)]
            for j in xrange(k + 1):
                for y, t in res[j].viewitems():
                    if j and x <= 18:
                        nr[j-1][factorial(x) + y] += t
                    nr[j][x + y] += t
                    nr[j][y] += t
            res = nr
        return res
    def g(b):
        res = [defaultdict(int) for _ in xrange(k + 1)]
        res[k][s] = 1
        for x in b:
            nr = [defaultdict(int) for _ in xrange(k + 1)]
            for j in xrange(k + 1):
                for y, t in res[j].viewitems():
                    if j and x <= 18:
                        nr[j-1][y - factorial(x)] += t
                    nr[j][y - x] += t
                    nr[j][y] += t
            res = nr
        return res
    dl = f(a[:n/2])
    dr = g(a[n/2:])
    b = set()
    for i in xrange(k + 1):
        b.update(dl[i].keys())
        b.update(dr[i].keys())
    ans = 0
    for x in b:
        for i in xrange(k + 1):
            for j in xrange(k + 1):
                if i + j <= k:
                    ans += dl[i][x] * dr[j][x]
    print ans
main()

import sys

import itertools

from collections import defaultdict, Counter

factorials = [1] * 19

for i in range(1, 19):
    factorials[i] = i * factorials[i - 1]

def enum(l):

    global S

    options = itertools.product(*([(0, 1, 2)] * len(l)))

    d = defaultdict(Counter)

    for opts in options:

        s = 0
        marks = 0
        for i, opt in enumerate(opts):

            if s > S:
                break

            if opt == 1:
                s += l[i]
            elif opt == 2:
                if l[i] <= 18:
                    s += factorials[l[i]]
                    marks += 1
                else:
                    continue

        if s <= S:
            d[s].update([marks])

    return d

[n, K, S] = map(int, sys.stdin.next().split(' '))
l = sorted(map(int, sys.stdin.next().split(' ')))

p1 = enum(l[:(len(l) / 2)][::-1])
p2 = enum(l[(len(l) / 2):][::-1])

variants = 0
for s, c in p1.items():
    if S - s in p2:
        m1 = p1[s]
        m2 = p2[S - s]
        for (k1, c1), (k2, c2) in zip(m1.items(), m2.items()):
            if k1 + k2 <= K:
                variants += c1 * c2

print(variants)

import sys

import itertools

from collections import defaultdict, Counter

factorials = [1] * 19

for i in range(1, 19):
    factorials[i] = i * factorials[i - 1]

def enum(l):

    global S

    options = itertools.product(*([(0, 1, 2)] * len(l)))

    d = defaultdict(Counter)

    for opts in options:

        s = 0
        marks = 0
        for i, opt in enumerate(opts):

            if s > S:
                break

            if opt == 1:
                s += l[i]
            elif opt == 2:
                if l[i] <= 18:
                    s += factorials[l[i]]
                    marks += 1
                else:
                    continue

        if s <= S:
            d[s].update([marks])

    return d

[n, K, S] = map(int, sys.stdin.next().split(' '))
l = sorted(map(int, sys.stdin.next().split(' ')))

p1 = enum(l[:(len(l) / 2)][::-1])
p2 = enum(l[(len(l) / 2):][::-1])

variants = 0
for s, c in p1.items():
    if S - s in p2:
        m1 = p1[s]
        m2 = p2[S - s]
        for (k1, c1) in m1.items():
            for (k2, c2) in m2.items():
                if k1 + k2 <= K:
                    variants += c1 * c2

print(variants)

from collections import defaultdict

N, K, S = map( int, input().split() )
A = list( map( int, input().split() ) )

fact = [ 1 ]
for i in range( 1, 20, 1 ):
  fact.append( fact[ i - 1 ] * i )

ldp = [ [ defaultdict( int ) for i in range( 1 << N // 2 ) ] for j in range( K + 1 ) ]
ldp[ 0 ][ 0 ][ 0 ] = 1
for i in range( K + 1 ):
  for s in range( 1 << N // 2 ):
    for j in range( N // 2 ):
      if ~s >> j & 1:
        for key in ldp[ i ][ s ]:
          ldp[ i ][ s | 1 << j ][ key + A[ j ] ] += ldp[ i ][ s ][ key ]
          if i + 1 <= K and A[ j ] <= 18:
            ldp[ i + 1 ][ s | 1 << j ][ key + fact[ A[ j ] ] ] += ldp[ i ][ s ][ key ]

lbag = [ defaultdict( int ) for i in range( K + 1 ) ]
for i in range( K + 1 ):
  for j in range( 1 << N // 2 ):
    for key in ldp[ i ][ j ]:
      lbag[ i ][ key ] += ldp[ i ][ j ][ key ]

rdp = [ [ defaultdict( int ) for i in range( 1 << N - N // 2 ) ] for j in range( K + 1 ) ]
rdp[ 0 ][ 0 ][ 0 ] = 1
for i in range( K + 1 ):
  for s in range( 1 << N - N // 2 ):
    for j in range( N - N // 2 ):
      if ~s >> j & 1:
        for key in rdp[ i ][ s ]:
          rdp[ i ][ s | 1 << j ][ key + A[ N // 2 + j ] ] += rdp[ i ][ s ][ key ]
          if i + 1 <= K and A[ N // 2 + j ] <= 18:
            rdp[ i + 1 ][ s | 1 << j ][ key + fact[ A[ N // 2 + j ] ] ] += rdp[ i ][ s ][ key ]

ans = 0
for i in range( K + 1 ):
  for s in range( 1 << N - N // 2 ):
    for key in rdp[ i ][ s ]:
      for j in range( 0, K - i + 1, 1 ):
        ans += lbag[ j ][ S - key ]

print( ans )


def DFS(x):
    for i in range(x):
        if(Seen[i][x]):
            continue
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Parent[x]=i
            Children[i].append(x)
            return True
    for i in range(x):
        if(Seen[i][x]):
            continue
        Y=[]
        for j in range(len(Children[i])):
            child=Children[i][j]
            Parent[child]=-1
            Rem[i]+=C[child]
            Seen[i][child]=True
            Seen[child][i]=True
            if(DFS(child)):
                Seen[i][child]=False
                Seen[child][i]=False
                continue
            Seen[i][child]=False
            Seen[child][i]=False
            Parent[child]=i
            Rem[i]-=C[child]
            Y.append(child)
        Children[i]=list(Y)
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Children[i].append(x)
            Parent[x]=i
            return True
    return False

n=int(input())

C=list(map(int,input().split()))
Rem=[-1]*n
Parent=[-1]*n
Children=[]
Seen=[]
for i in range(n):
    Seen.append([False]*n)
C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):
    print("NO")

else:
    for i in range(n):
        Rem[i]=C[i]-1
        Children.append([])
    Parent[0]=0
    Ans="YES"
    for i in range(1,n):
        if(DFS(i)==False):
            Ans="NO"
            break
    for i in range(n):
        if(Rem[i]!=0 and C[i]!=1):
            Ans="NO"
            break
    print(Ans)

def DFS(x):

    for i in range(x):

        if(Seen[i][x]):

            continue

        if(Rem[i]>=C[x]):

            if(Rem[i]==C[x] and len(Children[i])==0):

                continue

            Rem[i]-=C[x]

            Parent[x]=i

            Children[i].append(x)

            return True

    for i in range(x):

        if(Seen[i][x]):

            continue

        Y=[]

        for j in range(len(Children[i])):

            child=Children[i][j]

            if(Seen[i][child]):

                continue

            Parent[child]=-1

            Rem[i]+=C[child]

            Seen[i][child]=True

            Seen[child][i]=True

            if(DFS(child)):

                Seen[i][child]=False

                Seen[child][i]=False

                continue

            Seen[i][child]=False

            Seen[child][i]=False

            Parent[child]=i

            Rem[i]-=C[child]

            Y.append(child)

        Children[i]=list(Y)

        if(Rem[i]>=C[x]):

            if(Rem[i]==C[x] and len(Children[i])==0):

                continue

            Rem[i]-=C[x]

            Children[i].append(x)

            Parent[x]=i

            return True

    return False

n=int(input())

C=list(map(int,input().split()))

Rem=[-1]*n

Parent=[-1]*n

Children=[]

Seen=[]

for i in range(n):

    Seen.append([False]*n)

C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):

    print("NO")

else:

    for i in range(n):

        Rem[i]=C[i]-1

        Children.append([])

    Parent[0]=0

    Ans="YES"

    for i in range(1,n):

        if(DFS(i)==False):

            Ans="NO"

            break

    for i in range(n):

        if(Rem[i]!=0 and C[i]!=1):

            Ans="NO"

            break

    print(Ans)

# Made By Mostafa_Khaled

#!/usr/bin/python

import sys

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

n = Ni()[0]
c = Ni()

avail = [c.count(i) for i in range(n+1)]

def backtrack(stack, sumleft):
    #print stack, avail, sumleft
    if len(stack) == 1 and sumleft == 0:
        print "YES"
        sys.exit(0)

    # try to shift a 1
    if avail[1] > 0:
        avail[1] -= 1
        backtrack(stack + [1], sumleft - 1)
        avail[1] += 1

    # reduce if possible
    if len(stack) < 2:
        return

    s = 1 + stack[-1]
    for i in range(2, len(stack) + 1):
        s += stack[-i]
        if s >= n + 1:
            break

        if avail[s] > 0:
            avail[s] -= 1
            backtrack(stack[:-i] + [s], sumleft - s)
            avail[s] += 1

backtrack([], sum(c))
print "NO"

#!/usr/bin/python

import sys

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

n = Ni()[0]
c = Ni()
c = sorted(c)

F = [0] * (n+1)
for _c in c:
    F[_c] += 1

#print n, c, F
answer = "NO"

def backtrack(stack, avail, sumleft):
    #print stack, avail, sumleft
    if len(stack) == 1 and sumleft == 0:
        print "YES"
        sys.exit(0)

    # shift
    if avail[1] > 0:
        avail[1] -= 1
        #print "shift", i
        backtrack(stack + [1], avail, sumleft - 1)
        avail[1] += 1

    # reduce
    if len(stack) < 2:
        return

    s = 1 + stack[-1]
    for i in range(2, len(stack) + 1):
        s += stack[-i]
        if s >= n + 1:
            break

        if avail[s] > 0:
            avail[s] -= 1
            #print "reduce", s
            backtrack(stack[:-i] + [s], avail, sumleft - s)
            avail[s] += 1

backtrack([], F, sum(c))
print "NO"

#!/usr/bin/python

import sys

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

n = Ni()[0]
c = Ni()

freq = [c.count(i) for i in range(n+1)]

answer = "NO"

def backtrack(stack, avail, sumleft):
    #print stack, avail, sumleft
    if len(stack) == 1 and sumleft == 0:
        print "YES"
        sys.exit(0)

    # try to shift a 1
    if avail[1] > 0:
        avail[1] -= 1
        backtrack(stack + [1], avail, sumleft - 1)
        avail[1] += 1

    # reduce if possible
    if len(stack) < 2:
        return

    s = 1 + stack[-1]
    for i in range(2, len(stack) + 1):
        s += stack[-i]
        if s >= n + 1:
            break

        if avail[s] > 0:
            avail[s] -= 1
            backtrack(stack[:-i] + [s], avail, sumleft - s)
            avail[s] += 1

backtrack([], freq, sum(c))
print "NO"

def DFS(x):
    for i in range(x):
        if(Seen[i]):
            continue
        if(Rem[i]>=C[x]):
            Rem[i]-=C[x]
            Parent[x]=i
            Children[i].append(x)
            return True
    for i in range(x):
        if(Seen[i]):
            continue
        Y=[]
        Seen[i]=True
        for j in range(len(Children[i])):
            child=Children[i][j]
            Parent[child]=-1
            Rem[i]+=C[child]
            if(DFS(child)):
                continue
            Parent[child]=i
            Rem[i]-=C[child]
            Y.append(child)
        Seen[i]=False
        Children[i]=list(Y)
        if(Rem[i]>=C[x]):
            Rem[i]-=C[x]
            Children[i].append(x)
            Parent[x]=i
            return True
    return False

n=int(input())

C=list(map(int,input().split()))
Rem=[-1]*n
Parent=[-1]*n
Children=[]
Seen=[False]*n
C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):
    print("NO")

else:
    for i in range(n):
        Rem[i]=C[i]-1
        Children.append([])
    Parent[0]=0
    Ans="YES"
    for i in range(1,n):
        if(DFS(i)==False):
            Ans="NO"
            break
    for i in range(n):
        if(Rem[i]!=0 and C[i]!=1):
            Ans="NO"
            break
    print(Ans)

def DFS(x):
    for i in range(x):
        if(Seen[i]):
            continue
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Parent[x]=i
            Children[i].append(x)
            return True
    for i in range(x):
        if(Seen[i]):
            continue
        Y=[]
        Seen[i]=True
        for j in range(len(Children[i])):
            child=Children[i][j]
            Parent[child]=-1
            Rem[i]+=C[child]
            if(DFS(child)):
                continue
            Parent[child]=i
            Rem[i]-=C[child]
            Y.append(child)
        Seen[i]=False
        Children[i]=list(Y)
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Children[i].append(x)
            Parent[x]=i
            return True
    return False

n=int(input())

C=list(map(int,input().split()))
Rem=[-1]*n
Parent=[-1]*n
Children=[]
Seen=[False]*n
C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):
    print("NO")

else:
    for i in range(n):
        Rem[i]=C[i]-1
        Children.append([])
    Parent[0]=0
    Ans="YES"
    for i in range(1,n):
        if(DFS(i)==False):
            Ans="NO"
            break
    for i in range(n):
        if(Rem[i]!=0 and C[i]!=1):
            Ans="NO"
            break
    print(Ans)


M = 10 ** 9 + 7

n, k = map(int, input().split())
a = list(map(int, input().split()))

z, o = a.count(0), a.count(1)
d = pow(n * (n - 1) // 2, M - 2, M)

if z > o:
    o, z = z, o
    a = [1 - x for x in a][::-1]

res = [[0] * (z + 1) for i in range(z + 1)]
tf = [[0] * (z + 1) for i in range(z + 1)]
for i in range(z + 1):
    res[i][i] = 1
    tf[i][i] = (z * (z - 1) // 2 + o * (o - 1) // 2 + i * (z - i) + (z - i) * (o - z + i)) * d % M
    if i < z: tf[i + 1][i] = (z - i) * (z - i) * d % M
    if i: tf[i - 1][i] = i * (o - z + i) * d % M

def mul(a, b):
    t = [[0] * (z + 1) for i in range(z + 1)]
    for i in range(z + 1):
        for k in range(z + 1):
            for j in range(z + 1):
                t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % M
    return t

while k:
    if k & 1:
        res = mul(res, tf)
    tf = mul(tf, tf)
    k >>= 1

print(res[-1][a[:z].count(0)])

N, T = map(int, raw_input().split())
A = [int(a) for a in raw_input().split()]
if sum(A) > N//2:
    A = [1-a for a in A][::-1]
K = sum(A)
S = sum(A[-K:])
M = K + 1
P = 10**9+7
inv = pow(N*(N-1)//2, P-2, P)
X = [[0]*M for _ in range(M)]
for i in range(M):
    if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P
    if i < M-1: X[i+1][i] = (N-2*K+i+1)*(i+1)*inv%P
    X[i][i] = (1-((K-i)**2*inv)-(N-2*K+i)*(i)*inv)%P
def ddd(n):
    for i in range(1, 100):
        if (n*i%P) < 100:
            return (n*i%P), i
    return -1, -1
def poww(MM, n):
    if n == 1:
        return MM
    if n % 2:
        return mult(poww(MM, n-1), MM)
    return poww(mult(MM,MM), n//2)
def mult(M1, M2):
    Y = [[0] * M for _ in range(M)]
    for i in range(M):
        for j in range(M):
            for k in range(M):
                Y[i][j] += M1[i][k] * M2[k][j]
                Y[i][j] %= P
    return Y
X = poww(X, T)
print(X[S][K])

import sys; input=sys.stdin.readline
# print(input())
N, T = map(int, input().split())
A = [int(a) for a in input().split()]
if sum(A) > N//2:
    A = [1-a for a in A][::-1]
K = sum(A)
S = sum(A[-K:])
M = K + 1
P = 10**9+7
inv = pow(N*(N-1)//2, P-2, P)
X = [[0]*M for _ in range(M)]
for i in range(M):
    if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P
    if i < M-1: X[i+1][i] = (N-2*K+i+1)*(i+1)*inv%P
    X[i][i] = (1-((K-i)**2*inv)-(N-2*K+i)*(i)*inv)%P

# def ddd(n):
#     for i in range(1, 100):
#         if (n*i%P) < 100:
#             return (n*i%P), i
#     return -1, -1
def poww(MM, n):
    if n == 1:
        return MM
    if n % 2:
        return mult(poww(MM, n-1), MM)
    return poww(mult(MM,MM), n//2)
def mult(M1, M2):
    Y = [[0] * M for _ in range(M)]
    for i in range(M):
        for j in range(M):
            for k in range(M):
                Y[i][j] += M1[i][k] * M2[k][j]
                Y[i][j] %= P
    return Y

X = poww(X, T)

print(X[S][K])

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Codeforces Round #553 (Div. 2)

Problem F. Sonya and Informatics

:author:         Kitchen Tong
:mail:    kctong529@gmail.com

Please feel free to contact me if you have any question
regarding the implementation below.
"""

__version__ = '1.8'
__date__ = '2019-04-21'

import sys

def binom_dp():
    dp = [[-1 for j in range(110)] for i in range(110)]
    def calculate(n, k):
        if n < k:
            return 0
        if n == k or k == 0:
            return 1
        if dp[n][k] > 0:
            return dp[n][k]
        else:
            dp[n][k] = calculate(n-1, k-1) + calculate(n-1, k)
        return dp[n][k]
    return calculate

def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def multiply(A, B, mod):
    if not hasattr(B[0], '__len__'):
        C = [sum(aij * B[j] % mod for j, aij in enumerate(ai)) for ai in A]
    else:
        C = [[0 for col in range(len(B[0]))] for row in range(len(A))]
        len_A = len(A)
        len_B = len(B)
        for row in range(len_A):
            if sum(A[row]) == 0:
                continue
            for col in range(len_B):
                C[row][col] = sum(A[row][k] * B[k][col]
                                  for k in range(len_B)) % mod
    return C

def memoize(func):
    memo = {}
    def wrapper(*args):
        M, n, mod = args
        if n not in memo:
            memo[n] = func(M, n, mod)
        return memo[n]
    return wrapper

@memoize
def matrix_pow(M, n, mod):
    # print(f'n is {n}')
    if n == 2:
        return multiply(M, M, mod)
    if n == 1:
        return M
    sub_M = matrix_pow(M, n//2, mod)
    if n % 2 == 0:
        return multiply(sub_M, sub_M, mod)
    return multiply(sub_M, matrix_pow(M, n - n//2, mod), mod)

def solve(n, k, a, binom, mod):
    ones = sum(a)
    zeros = n - ones
    M = [[0 for col in range(zeros+1)] for row in range(zeros+1)]
    for row in range(max(0, zeros-ones), zeros+1):
        pre_zeros = row
        pre_ones = zeros - pre_zeros
        post_zeros = pre_ones
        post_ones = ones - pre_ones
        M[row][row] = (pre_ones * post_ones + pre_zeros * post_zeros
                       + binom(zeros, 2) + binom(ones, 2))
        if row > max(0, zeros-ones):
            M[row-1][row] = pre_zeros * post_ones
        if row < zeros:
            M[row+1][row] = post_zeros * pre_ones
    M = [matrix_pow(M, k, mod)[-1]]
    b = [0] * (zeros + 1)
    b[zeros - sum(a[:zeros])] = 1
    C = multiply(M, b, mod)
    return C[-1]

def main(argv=None):
    mod = int(1e9) + 7
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    binom = binom_dp()
    P = solve(n, k, a, binom, mod)
    if P == 0:
        print(0)
    else:
        Q = pow(binom(n, 2), k, mod)
        print(P * modinv(Q, mod) % mod)
    return 0

if __name__ == "__main__":
    STATUS = main()
    sys.exit(STATUS)

N, T = map(int, input().split())
A = [int(a) for a in input().split()]
if sum(A) > N//2:
    A = [1-a for a in A][::-1]
K = sum(A)
S = sum(A[-K:])
M = K + 1
P = 10**9+7
inv = pow(N*(N-1)//2, P-2, P)
X = [[0]*M for _ in range(M)]
for i in range(M):
    if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P
    if i < M-1: X[i+1][i] = (N-2*K+i+1)*(i+1)*inv%P
    X[i][i] = (1-((K-i)**2*inv)-(N-2*K+i)*(i)*inv)%P

def ddd(n):
    for i in range(1, 100):
        if (n*i%P) < 100:
            return (n*i%P), i
    return -1, -1
def poww(MM, n):
    if n == 1:
        return MM
    if n % 2:
        return mult(poww(MM, n-1), MM)
    return poww(mult(MM,MM), n//2)
def mult(M1, M2):
    Y = [[0] * M for _ in range(M)]
    for i in range(M):
        for j in range(M):
            for k in range(M):
                Y[i][j] += M1[i][k] * M2[k][j]
                Y[i][j] %= P
    return Y

X = poww(X, T)

print(X[S][K])