//也算是一个小暴力吧,我是非科班,想的比较简单
“#include<”iostream”>” //运行的时候把引号去掉
“#include<”bits/stdc.h”>”
using namespace std;
using LL = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
LL lamps[3] = {0};
cin >> lamps[0] >> lamps[2] >> lamps[1];//lamps数组依次存储红绿黄
LL n,sum = 0; cin >> n;
LL lamp,time;
for(int i = 0;i < n;i){
cin >> lamp >> time;
if(lamp == 0){sum += time; continue;}
if(lamp == 3) lamp = 1; //绿
else if(lamp == 2) lamp = 2; //黄
else lamp = 0; //红
LL fuck = sum,_case = lamps[0] + lamps[1] + lamps[2];
do{
fuck = time - sum;
while(fuck < 0){
if(fabs(fuck) > _case)
fuck %= _case; //后面有的case会超时,我就想着可以先取余红黄绿灯所有的时间
lamp += 1;
lamp %= 3;
fuck += lamps[lamp];
}
time = fuck;
if(time == 0){
time += lamps[(++lamp) % 3];
lamp = lamp % 3;
}
fuck = 0;
}while(0);
if(lamp == 1) continue;
else if(lamp == 0){
sum += time;
}
else{
sum += time + lamps[0];
}
}
cout << sum;
return 0;
}