{"problem":{"name":"A. The Monster","description":{"content":"A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times _b_, _b_ + _a_, _b_ + 2_a_, _b_ + 3_a_, ... and Mo","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF787A"},"statements":[{"statement_type":"Markdown","content":"A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times _b_, _b_ + _a_, _b_ + 2_a_, _b_ + 3_a_, ... and Morty screams at times _d_, _d_ + _c_, _d_ + 2_c_, _d_ + 3_c_, ....\n\n<center>![image](https://espresso.codeforces.com/fa87bf740de4111cfce3f7bda62866ec8e2470d0.png)</center>The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.\n\n## Input\n\nThe first line of input contains two integers _a_ and _b_ (1 ≤ _a_, _b_ ≤ 100).\n\nThe second line contains two integers _c_ and _d_ (1 ≤ _c_, _d_ ≤ 100).\n\n## Output\n\nPrint the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.\n\n[samples]\n\n## Note\n\nIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.\n\nIn the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.","is_translate":false,"language":"English"}],"meta":{"iden":"CF787A","tags":["brute force","math","number theory"],"sample_group":[["20 2\n9 19","82"],["2 1\n16 12","\\-1"]],"created_at":"2026-03-03 11:00:39"}}