eolymp
bolt
Try our new interface for solving problems
Məsələlər

Poodle and Bolonka

Poodle and Bolonka

Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB

Poodle walks along the line segment parallel to the axis Ox (coordinates of one end-point are (x_1, y), coordinates of the other end-point are (x_2, y)). Initially, he is in the point (x_1, y) and goes to other end-point of the segment with velocity 1. When Poodle reaches the end-point (x_2, y), he immediately turns around and goes in the opposite direction with the same velocity 1 until he reaches the point (x_1, y). There he turns around again, goes in the direction of (x_2, y) again, etc.

Similarly, Bolonka walks along the line segment parallel to the axis Oy with end-points (x, y_1) and (x, y_2), starting from the point (x, y_1). She goes with velocity 1 as well and changes walking direction after reaching any end-point. They walk until they meet, i.e. come to same point at same time.

Your task is to determine how much time it will take (from start until the meeting moment).

Giriş verilənləri

First line of input contains 3 integers x_1, x_2, y, and second line contains 3 integers x, y_1, y_2. All numbers do not exceed 5×10^8 by absolute value.

Çıxış verilənləri

Output only one number, time when Poodle and Bolonka meet for the first time. If they cannot met ever, output number −1.

Nümunə

Giriş verilənləri #1
0 2 5
1 0 10
Çıxış verilənləri #1
5
Mənbə ACM-ICPC Ukraine 2012, 2nd Stage Ukraine, September 6, 2012