Paradox of time travel A man has two devices.


A time machine - He can control this machine by thinking. It allows him to travel from any point in time to another point in time in the past or future (or even the present point in time) in no time at all. Note that if he travels to the past from B to A, then all normal events (time machines, alternators excluded) from A to B must repeat in the exact same way. Then from point B, he is taken back to point A. Thus, a single time travel creates an infinite loop.
Alternator - Realising this problem, he creates another machine. He notices that, even though all physical events get repeated in a loop, his thoughts may be different. Hence this machine was designed to be controllable by thought as well. The machine can be used at any time to provide an alternate future (but not past) with respect to the time he used it.


Example

I'll explain all the details using a lengthy example.

1000 T+250 250 T+0 500 T-200 100 T-50 125 A 225 T-400 500 A 100 T-200 150 T-25 100 T+100 50 A 25



1000 years pass. It is year 1000 now.
He travels from 1000 to 1250.
250 years pass. It is year 1500 now.
He travels from 1500 to 1500. This has no effect (and can be ignored).
500 years pass. It is now year 2000
He travels from 2000 to 1800.
100 years pass. It is year 1900 now.
He travels from 1900 to 1850.
125 years pass: However, this time, as he is in a loop, things are different. 50 years pass from 1850 to 1900. He loops back to 1850. Another 50 years pass from 1850 to 1900. He loops back again. 25 years pass and it is 1875, thus completing 125 years.
He uses the alternator. Now there exists an alternate future to the year 1875, which he is now in. The past has not changed.
225 years pass. It is now year 2100.
He travels from 2100 to 1700.
500 years pass: 175 years from 1700 to 1875 pass normally. No he encounters the alternator again, which means that now a 3rd future has been created post-1875. 325 years pass normally, making it year 2200.
Using an alternator now has no effect (and can be ignored) since there exists only one future to 2200 which has not yet been defined.
100 years pass. It is now 2300.
He travels from 2300 to 2100.
150 years pass: 100 years from 2100 to 2200 pass normally. A second future gets created from 2200. 50 years pass and it is now year 2250.
He is supposed to go from 2250 to 2225. However, there now exist two 2225s in two different timelines. Hence this leads to a paradox, since we cannot determine which point in time he will reach. (We will not assume that he goes to the more recent timeline) Hence this terminates our simulation.
Anything further 100 T+100 50 A 25 is completely ignored since a paradox has occured and our simulation has stopped running.


Hint: If you are struggling to understand the example, imagine time to be like a path you are digging in the earth. If you are time travelling, you are creating a teleporter. If you are using the alternator, you are digging a new path into the wall of an existing path.

Paradox

Assume A, B and C are three points in time (one after another). A paradox is said to have occurred iff:


you are at a point C, there exists an alternator at a point B, there exists more than one future to point B (and you are in one of them), and you attempt to access any point between B and C via time travel.
you are at a point A, there exists an alternator at a point B, there exists more than one future to point B, and you try to access a point C (after B) via time travel.


Input

A series of events, similar to the example. (Format is flexible.)

Output

A truthy/falsey value, indicating whether a paradox has occured.

Challenge

Shortest code (in bytes) wins.
Ruby, 510 460 bytes

p=[0];w=[n=x=0]
i=gets.split.map{|s|
if x!=1
if s[0]=="A"
w&lt;&lt;n
else
if s[0..1]=="T+"
t=n
q=s[2..-1].to_i
if w[-1]==t||(w[-1]&gt;t&amp;&amp;w[-1]&lt;n+q)
w&lt;&lt;w[-1]
n+=q
else
n+=(t&lt;p[-1]&amp;&amp;n+q&gt;p[-1])?q%(p[-1]-n):q
end
elsif s[0..1]=="T-"
t=n
p&lt;&lt;n
n-=s[2..-1].to_i
x=(x==0&amp;&amp;w[-1]&gt;0&amp;&amp;t&gt;w[-1]&amp;&amp;n&gt;w[-1])?1:0
else
t=n
q=s.to_i
if w[-1]==t||(w[-1]&gt;t&amp;&amp;w[-1]&lt;n+q)
w&lt;&lt;w[-1]
n+=q
else
n+=(t&lt;p[-1]&amp;&amp;n+q&gt;p[-1])?q%(p[-1]-n):q
end
end
end
else
break
end}
p x


Input

As per example

Output

0 = No Paradox, 1 = Paradox

Sample

The sample input provided: 1000 T+250 250 T+0 500 T-200 100 T-50 125 A 225 T-400 500 A 100 T-200 150 T-25 100 T+100 50 A 25
returns 1, indicating a paradox occurred.

Notes

This is not only the first codegolf exercise I attempt, but it is also the first Ruby program I have written. Hence, it could probably be even shorter.

Brief Explanation

p: Infinite loops
w: Alternate timelines
n: Now (regardless of timeline)
x: Paradox


Infinite loops will only occur while traveling forward in time. I am happy for any feedback - especially if it is pointing out a better way to solve this.