human
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow.

He knows that the receptionist starts working after ts minutes have passed after midnight and closes after tf minutes have passed after midnight (so that (tf - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves). 

Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately.

 "Reception 1"

For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them.

Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him!

Input

The first line contains three integers: the point of time when the receptionist begins to work ts, the point of time when the receptionist stops working tf and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive...
Using python3 can you solve the prior task?
assistant
#Here is the Python program you requested.

import sys
from pprint import pprint

class Fun:
    def __init__(self, tStart, intercept):
        self.tStart = tStart
        self.intercept = intercept

    def calcTime(self, time):
        return self.intercept - time

strings = sys.stdin.readlines()
ts, tf, t = [int(i) for i in strings[0].strip().split()]
n = int(strings[1].strip())
if n == 0:
    print(ts)
    exit(0)
customers = [int(i) for i in strings[2].strip().split()]

funs = dict()
funs[0] = Fun(tStart=0, intercept=ts+t)
lastFun = funs[0]
for cust in customers:
    if cust > tf:
        continue
    if lastFun.tStart == cust:
        lastFun.intercept += t
    else:
        funs[cust] = Fun(tStart=cust, intercept=lastFun.intercept + t)
    lastFun = funs[cust]

sortedTimes = sorted(customers, reverse=True)
prevIntercept = 0
for i in sortedTimes:
    if i < tf - t + 1:
        prevIntercept = funs[i].intercept
        break

if (tf - t + 1) not in funs:
    funs[tf-t+1] = Fun(tStart=tf-t+1, intercept=prevIntercept)

minWait = 10**12
minTime = 0
prevK = sorted(funs.keys())[0]
for i in sorted(funs.keys())[1:]:
    time = funs[i].tStart - 1
    wait = funs[prevK].calcTime(time)
    if wait < minWait and time + wait <= tf:
        minWait = wait
        minTime = time
    prevK = i

# pprint([(funs[f].tStart, funs[f].intercept) for f in sorted(funs)])
print(minTime)