#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+P)%P; q=q+((y-Y)%Q+Q)%Q; if(p>P)p-=P; if(q>Q)q-=Q; cout<