r, y, g = input().split()
r, y, g = int(r), int(y), int(g)
n = int(input())
time = 0
stat_time_list = []
def transfer(stat_time, passedTime):
time_in_scale = 0
origi_k = stat_time[0]
origi_t = stat_time[1]
if origi_k==0:
return origi_k,origi_t
if origi_k==1:
time_in_scale = r - t
elif origi_k==3:
time_in_scale = (r+g) - t
else:
time_in_scale = (r+g+y) - t
passedTime = (passedTime+time_in_scale) % (r+y+g)
if passedTime<=r:
return 1, r-passedTime
elif passedTime>r and passedTime<=r+g:
return 3, (r+g)-passedTime
else:
return 2, (r+g+y)-passedTime
for i in range(n):
k, t = input().split()
k, t = int(k), int(t)
stat_time_list.append([k ,t])
for stat_time in stat_time_list:
k = stat_time[0]
t = stat_time[1]
#计算达到时刻的k和t
k, t = transfer(stat_time, time)
if k==0:
time += t
elif k==1:
time += t
elif k==2:
time += (t + r)
#else:
# do nothing
print(time)
网友评论