Parallel Universes (Easy) (Codeforces 1184D1)
Tags: Implement, implementation

The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.Heidi recently got her hands on a multiverse observation tool. She was able to see all $$$n$$$ universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the $$$k$$$-th universe.The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed $$$m$$$.Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.More specifically,   When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.   When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. Heidi wants to perform a simulation of $$$t$$$ decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.

Input: The first line contains four integers $$$n$$$, $$$k$$$, $$$m$$$ and $$$t$$$ ($$$2 \le k \le n \le m \le 250$$$, $$$1 \le t \le 1000$$$).Each of the following $$$t$$$ lines is in one of the following formats:   "$$$1$$$ $$$i$$$" — meaning that a universe is inserted at the position $$$i$$$ ($$$1 \le i \le l + 1$$$), where $$$l$$$ denotes the current length of the multiverse.  "$$$0$$$ $$$i$$$" — meaning that the $$$i$$$-th link is broken ($$$1 \le i \le l - 1$$$), where $$$l$$$ denotes the current length of the multiverse. 

Output: Output $$$t$$$ lines. Each line should contain $$$l$$$, the current length of the multiverse and $$$k$$$, the current position of the Doctor.It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most $$$m$$$ and when the link breaking is performed, there will be at least one universe in the multiverse.

Note: The multiverse initially consisted of 5 universes, with the Doctor being in the second.First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.Then, the rightmost link was broken.Finally, a universe was added between the first and the second universe.

Sample Inputs:
5 2 10 4
0 1
1 1
0 4
1 2

Sample Outputs:
4 1
5 2
4 2
5 3

Solution (Python):
(n, k, m, t) = map(int, input().split())
for _ in range(t):
    (c, p) = map(int, input().split())
    if c == 0:
        if p < k:
            n -= p
            k -= p
        else:
            n = p
    elif c == 1:
        n += 1
        if p <= k:
            k += 1
    print(n, k)

Solution (Python):
(n, k, m, t) = map(int, input().split())
for i in range(t):
    (a, b) = map(int, input().split())
    if a == 0:
        if k > b:
            k = k - b
            n -= b
        else:
            n -= n - b
    elif k >= b:
        k += 1
        n += 1
    else:
        n += 1
    print(n, k)

Solution (Python):
(n, k, m, t) = map(int, input().split())
for i in range(0, t):
    (t1, t2) = map(int, input().split())
    if t1 == 1:
        if t2 <= k:
            k += 1
        n += 1
    elif t2 < k:
        n -= t2
        k -= t2
    else:
        n -= n - t2
    print(n, k)