#include<iostream> using namespace std; int main(){ long long x,y; cin>>x>>y; long long sum=0; long long tx=x,ty=y; for(;;){ if(tx>ty){ sum=sum+ty*4; tx=tx-ty; } else{ sum=sum+tx*4; ty=ty-tx; } if(tx==0||ty==0) break; } cout<<sum; }