#include using namespace std; using ll=long long; #include using namespace atcoder; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll P,Q,Y,p,q,y; cin>>P>>Q>>Y>>p>>q>>y; p=p+(y-Y)%P; q=q+(y-Y)%Q; if(p>P)p-=P; if(q>Q)q-=Q; cout<