## CCC '17 J3 - Exactly Electrical

View as PDF

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

You live in Grid City, which is composed of integer-numbered streets which run east-west (parallel to the -axis) and integer-numbered avenues which run north-south (parallel to the -axis). The streets and avenues have infinite length, and there is a street for every integer -coordinate and an avenue for every -coordinate. All intersections are labelled by their integer coordinates: for example, avenue and street intersect at .

You drive a special electric car which uses up one unit of electrical charge moving between adjacent intersections: that is, moving either north or south to the next street, or moving east or west to the next avenue). Until your battery runs out, at each intersection, your car can turn left, turn right, go straight through, or make a U-turn. You may visit the same intersection multiple times on the same trip.

Suppose you know your starting intersection, your destination intersection and the number of units of electrical charge in your battery. Determine whether you can travel from the starting intersection to the destination intersection using the charge available to you in such a way that your battery is empty when you reach your destination.

#### Input Specification

The input consists of three lines. The first line contains followed by , indicating the starting coordinate .

The second line contains followed by , indicating the destination coordinate .

The third line contains an integer indicating the initial number of units of electrical charge of your battery.

For 3 of the 15 available marks, .

For an additional 3 of the 15 marks available, .

#### Output Specification

Output Y if it is possible to move from the starting coordinate to the destination coordinate using exactly units of electrical charge. Otherwise output N.

#### Sample Input 1

3 4
3 3
3

#### Sample Output 1

Y

#### Explanation for Sample Output 1

One possibility is to travel from to to to .

#### Sample Input 2

10 2
10 4
5

#### Sample Output 2

N

#### Explanation for Sample Output 2

It is possible to get from to using exactly units of electricity, by going north units.

It is also possible to travel using units of electricity as in the following sequence:

It is also possible to travel using units of electricity from to by the following sequence:

It is not possible to move via any path of length from to , however.