solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
a, b = input().split()
c, d = input().split()
a, b, c, d = (int(x) for x in (a, b, c, d))
Rick = {(b + a * x) for x in range(1000005)}
Morty = {(d + c * x) for x in range(1000005)}
moments = Rick.intersection(Morty)
if len(moments)==0:
print(-1)
else:
print(min(moments)) | 7 | PYTHON3 |
a,b=map(int,input().split())
c,d=map(int,input().split())
fl=0
if b==d:
print(b)
else:
for m in range(1,10010):
if (c*m+d-c-b)%a==0 and (c*m+d-c-b)//a+1>0:
print(c*m+d-c)
fl=1
break
if fl==0:
print(-1)
| 7 | PYTHON3 |
a, b = map(int, input().split())
c , d = map(int, input().split())
for i in range(0,101):
j = ((a * i) + b - d) / c
if j == int(j) and j >= 0:
print((a * i) + b)
break
else: print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
;
long long int a, b;
cin >> a >> b;
long long int c, d;
cin >> c >> d;
long long int f = 0;
long long int ans = INT_MAX;
long long int i, j;
for (i = 0; i <= 1000; i++) {
for (j = 0; j <= 1000; j++) {
long long int z = (d + (c * i)) - (b + (a * j));
if (z == 0) {
f = 1;
ans = min(b + a * j, ans);
}
}
}
if (f == 1)
cout << ans << endl;
else {
cout << "-1\n";
}
}
| 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
flag = 1
if(b==d):
print(b)
flag = 0
else:
for i in range(100):
for j in range(100):
if b+(i*a)==d+(j*c):
print(b+(i*a))
flag = 0
break
if not flag:
break
if flag:
print(-1)
| 7 | PYTHON3 |
a,b=map(int,input().split(' '))
c,d=map(int,input().split(' '))
x=False
for i in range(1000):
if (a*i+b-d)%c==0:
if (a*i+b-d)>=0:
x=True
print(a*i+b)
break
if not x:
print(-1) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = -1
for i in range(100):
for j in range(100):
if i*a+b == c*j+d:
ans = c*j+d
print(ans)
exit()
print(ans)
| 7 | PYTHON3 |
a, b = [int(i) for i in input().split()]
c, d = [int(i) for i in input().split()]
for m in range(0, 101):
if (m * c + d - b) % a == 0:
k = (m * c + d - b) // a
if (k * a + b == m * c + d) and k >= 0:
print(k * a + b)
break
else:
print(-1)
| 7 | PYTHON3 |
inp = list(map(int,input().split()))
a=inp[0]
b=inp[1]
inp = list(map(int,input().split()))
c=inp[0]
d=inp[1]
x=(d-b)
y=c
k=0
flag=0
while(k<a):
if((x+k*y)%a==0):
flag=1
break
else:
k+=1
if(flag==0):
print (-1)
else:
k1=(d-b+c*k)//a
if(k1<0):
while(k1<0):
k1+=c
print (b+a*k1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int ri[10101] = {0};
int mo[10101] = {0};
int main() {
int a, b, c, d, r, m;
scanf("%d %d", &a, &b);
scanf("%d %d", &c, &d);
for (int i = 0;; i++) {
r = b + i * a;
m = d + i * c;
ri[r] = 1;
mo[m] = 1;
if (ri[r] == mo[r]) {
printf("%d", r);
return 0;
} else if (mo[m] == ri[m]) {
printf("%d", m);
return 0;
}
if (r > 10100 || m > 10100) break;
}
printf("%d", -1);
return 0;
}
| 7 | CPP |
a, b = map(int,input().split())
c, d = map(int,input().split())
for i in range(b,10**4,a):
if i in range(d,10**4,c):
exit(print(i))
print(-1) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
sum1 = b
sum2 = d
stop = False
numLoop = 0
# if ((b % 2 == 0) and (a % 2 == 0)) and ((d % 2 != 0) and (c % 2 == 0)):
# stop = False
# elif ((b % 2 != 0) and (a % 2 == 0)) and ((d % 2 == 0) and (c % 2 == 0)):
# stop = False
# elif (a == c) and (b != d):
# stop = False
# else:
while sum1 != sum2 and numLoop < 10 ** 6:
numLoop += 1
if sum1 < sum2:
sum1 += a
else:
sum2 += c
if sum1 == sum2:
stop = True
if stop == True:
print(sum1)
else:
print(-1)
| 7 | PYTHON3 |
a,b=map(int,input().split())
c,d=map(int,input().split())
r=[]
t=[]
for i in range(b,50500,a):
r.append(i)
for j in range(d,50500,c):
t.append(j)
if set(r)&set(t)==set():
print("-1")
else:
print(min(set(t).intersection(set(r))))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int64_t a, b, c, d;
std::cin >> a >> b >> c >> d;
std::set<int> ans;
for (int k = 0; k < 1000; ++k)
for (int j = 0; j < 1000; ++j)
if (b + k * a == d + j * c) ans.insert(b + k * a);
if (ans.size() == 0)
std::cout << -1 << '\n';
else
std::cout << *ans.begin() << '\n';
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
class TheMonster {
public:
void solve(std::istream &in, std::ostream &out) {
int a, b, c, d;
in >> a >> b >> c >> d;
for (int i = 0; i < 101; i++) {
int rick = b + (a * i);
for (int j = 0; j < 101; j++) {
int morty = d + (c * j);
if (rick == morty) {
out << rick << endl;
return;
}
}
}
out << -1 << endl;
}
};
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(nullptr);
TheMonster solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
map<long long, bool> mp;
for (int i = 0; i <= 1000000; i++) {
int p = b + (a * i), q = d + (i * c);
if (mp[p]) {
cout << p << endl;
return 0;
}
mp[p] = 1;
if (mp[q]) {
cout << q << endl;
return 0;
}
mp[q] = 1;
}
cout << "-1";
return 0;
}
| 7 | CPP |
# print ("Input a and b")
a,b = [int(x) for x in input().split()]
# print("Input c and d")
c,d = [int(x) for x in input().split()]
current = min(b,d)
if current == b:
inc = a
sub = d
mod = c
else:
inc = c
sub = b
mod = a
done = False
for i in range(100000):
if (current >= sub) and (current - sub) % mod == 0:
firstanswer = current
done = True
break
else:
current += inc
if not done:
firstanswer = float('inf')
current = max(b,d)
if current == b:
inc = a
sub = d
mod = c
else:
inc = c
sub = b
mod = a
done = False
for i in range(100000):
if (current >= sub) and (current - sub) % mod == 0:
secondanswer = current
done = True
break
else:
current += inc
if not done:
secondanswer = float('inf')
if firstanswer == float('inf') and secondanswer == float('inf'):
print(-1)
else:
print(min(firstanswer, secondanswer))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= 100; j++) {
if (b + a * i == d + c * j) {
cout << b + a * i;
return 0;
}
}
}
cout << "-1" << endl;
}
| 7 | CPP |
def gcdex(a, b):
i, j, k, l = 1, 0, 0, 1
while b > 0:
a, b, i, j, k, l = b, a % b, k, l, i - (a // b) * k, j - (a // b) * l
return a, i, j
a1, b1 = map(int, input().split())
c1, d1 = map(int, input().split())
a = a1
b = -c1
c = d1 - b1
#print(a, b, c)
d, x, y = gcdex(abs(a), abs(b))
if c % d == 0:
a //= d
b //= d
c //= d
x *= c
y *= c
x %= b
y = (c - a * x) // b
#print(x, y)
while (x<0 or y < 0 or x* a1 + b1 != y*c1 + d1):
x += 1
y = (c - a * x) // b
#print(x, y)
print(x* a1 + b1)
else:
print(-1) | 7 | PYTHON3 |
def readInts():
return [int(x) for x in input().split()]
a, b = readInts()
c, d = readInts()
l = set(a*i + b for i in range(100)) & set(c*i + d for i in range(100))
print(min(l) if l else -1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (d < b) {
swap(a, c);
swap(b, d);
}
for (int i = 0; i < a; ++i) {
int t = d - b + i * c;
if (t % a == 0) {
cout << t + b << endl;
return 0;
}
}
cout << -1 << endl;
}
| 7 | CPP |
a, b = list(map(int, input().split(" ")))
c, d = list(map(int, input().split(" ")))
final = -1
for i in range(101):
soma = b+a*i
for j in range(101):
soma2 = d+c*j
if soma2 == soma:
final = soma2
break
if soma2 > soma:
break
if final > -1: break
print(final) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void swap(int &a, int &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
int gcd(int a, int b) {
int temp;
if (a > b) swap(a, b);
while (true) {
if (a == 0) return b;
temp = a;
a = b % a;
b = temp;
}
}
int main() {
int a, b, c, d;
cin >> b >> a >> d >> c;
int s = gcd(b, d);
if (abs(a - c) % s != 0) {
cout << -1 << endl;
return 0;
}
int m1 = a;
int m2 = c;
while (m1 != m2) {
m1 < m2 ? m1 += b : m2 += d;
}
cout << m1 << endl;
return 0;
}
| 7 | CPP |
import sys
a, b = map(int, sys.stdin.readline().strip().split(" "))
c, d = map(int, sys.stdin.readline().strip().split(" "))
flag = False
maximo = max([a, b, c, d]) + 1
for i in range(maximo):
auxK = b + i * a
if (auxK - d) >= 0:
if (auxK - d) % c == 0:
flag = True
break
if flag:
print(auxK)
else:
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
long int a, b, c, d, flag;
long time1, time2;
scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
for (int i = 0; i <= 100; i++) {
time1 = b + (a * i);
for (int j = 0; j <= 100; j++) {
time2 = d + (c * j);
if (time1 == time2) {
flag = time1;
break;
}
}
if (time1 == time2)
break;
else
flag = -1;
}
printf("%ld", flag);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, i, j, flag = 0, outp;
scanf("%d%d%d%d", &a, &b, &c, &d);
for (i = 1; i <= 100; i++) {
for (j = 1; j <= 200; j++) {
if (b - a + c - d == j * c - i * a) {
outp = b + (i - 1) * a;
flag = 1;
break;
}
}
if (flag == 1) break;
}
if (flag == 1)
printf("%d", outp);
else
printf("-1");
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i < 10000; i++) {
for (int j = 0; j < 10000; j++) {
if (j * c == b - d + i * a) {
cout << b + a * i;
return 0;
}
}
}
cout << "-1" << endl;
return 0;
}
| 7 | CPP |
from sys import stdin, stdout
a, b = map(int, stdin.readline().split())
c, d = map(int, stdin.readline().split())
c1, d1 = max((c, d), (a, b), key = lambda x: x[1])
a1, b1 = min((c, d), (a, b), key = lambda x: x[1])
for y in range(10 ** 6):
if (d1 + c1 * y - b1) / a1 == int((d1 + c1 * y - b1) / a1) >= 0 and (d1 + y * c1 == b1 + a1 * int((d1 + c1 * y - b1) / a1)):
stdout.write(str(d1 + c1 * y))
break
else:
stdout.write('-1') | 7 | PYTHON3 |
a,b = map(int,input().split())
m,n = map(int,input().split())
e = 9999999999
flag = True
for i in range (0,100,1):
for j in range(0,100,1):
if b + a*i == n + m*j:
if b + a*i < e:
e = b+a*i
if e != 9999999999:
print(e)
else:
print('-1')
| 7 | PYTHON3 |
a,b=map(int,input().split(' '))
c,d=map(int,input().split(' '))
flag = 0
rick = []
morty = []
for i in range(101):
rick.append(b + i*a)
morty.append(d + i*c)
for i in range(len(rick)):
if rick[i] in morty:
print(rick[i])
break
else:
flag += 1
if flag==len(rick):
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int cnt1[100001];
int cnt2[100001];
int main() {
int a, b;
cin >> a >> b;
int c, d;
cin >> c >> d;
memset(cnt1, 0, sizeof(cnt1));
memset(cnt2, 0, sizeof(cnt2));
for (int i = 0; i < 100; i++) {
cnt1[b + (i * a)]++;
cnt2[d + (i * c)]++;
}
for (int i = 0; i <= 10000; i++) {
if (cnt1[i] == cnt2[i] && cnt1[i] != 0) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
}
| 7 | CPP |
# -*- coding: utf-8 -*-
a, b = map(int, input().split(' '))
c, d = map(int, input().split(' '))
if d < b:
x = b
b = d
d = x
x = a
a = c
c = x
k = 1
r = -1
while k<=100005:
n = (d-b+c*(k-1))/a+1
if n == int(n):
n = int(n)
r = b+a*(n-1)
break
k += 1
print(r) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
count = 0
found = False
j = 0
while(count < a):
i = (d - b +c*j) // a
if i >= 0:
count += 1
if (d - b +c*j) % a == 0:
found = True
break
j += 1
if found:
print(b +a*i)
else:
print(-1) | 7 | PYTHON3 |
a,b=[int(x) for x in input().split()]
c,d=[int(x) for x in input().split()]
l=[]
for i in range(100):
l.append(b+i*a)
flag=0
for i in range(100):
if d+i*c in l:
flag=1
break
if flag==1:
print(d+i*c)
else:
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, min = 1000000, flag = 0;
cin >> a >> b >> c >> d;
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= 100; j++) {
if (((i * a + b) == (j * c + d)) && i * a + b < min) {
min = i * a + b;
flag = 1;
}
}
}
if (flag == 1) {
cout << min;
} else
cout << "-1";
return 0;
}
| 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
from collections import defaultdict
al=defaultdict(int)
import math
if(b==d):
print(b)
exit()
else:
if(b>d):
rem=[]
b=b-d
while(1):
if(b%c==0):
print(b+d)
exit()
else:
al[b%c]+=1
if(al[b%c]>1):
print(-1)
exit()
else:
b+=a
else:
rem=[]
d=d-b
while(1):
if(d%a==0):
print(b+d)
exit()
else:
al[d%a]+=1
if(al[d%a]>1):
print(-1)
exit()
else:
d+=c
| 7 | PYTHON3 |
def R(): return map(int, input().split())
def I(): return int(input())
def S(): return str(input())
def L(): return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
b,a=R()
d,c=R()
for k in range(1000000):
if a+b*k-c>=0 and (a+b*k-c)%d==0:
print(a+b*k)
exit()
print('-1')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int a, b;
int c, d;
int vis1[1000100], vis2[1000100];
int main() {
scanf("%d%d", &a, &b);
scanf("%d%d", &c, &d);
memset(vis1, 0, sizeof(vis1));
memset(vis2, 0, sizeof(vis2));
for (int i = b; i < 1000100;) {
vis1[i] = 1;
i += a;
}
for (int i = d; i < 1000100;) {
vis2[i] = 1;
i += c;
}
int ans = -1;
for (int i = 0; i < 1000100; i++) {
if (vis1[i] && vis2[i]) {
ans = i;
break;
}
}
if (ans != -1)
printf("%d\n", ans);
else
printf("-1\n");
return 0;
}
| 7 | CPP |
import math
a,b=map(int, input().split())
c,d=map(int, input().split())
hasAnswer=0
for i in range(101):
y=b+i*a
z=(y-d)/c
if math.floor(z)==z and z>=0:
hasAnswer=1
break
if hasAnswer:
print(y)
else:
print(-1)
| 7 | PYTHON3 |
def mp(): return map(int,input().split())
def lt(): return list(map(int,input().split()))
def pt(x): print(x)
def ip(): return input()
def it(): return int(input())
def sl(x): return [t for t in x]
def spl(x): return x.split()
def aj(liste, item): liste.append(item)
def bin(x): return "{0:b}".format(x)
def listring(l): return ' '.join([str(x) for x in l])
def ptlist(l): print(' '.join([str(x) for x in l]))
a,b = mp()
c,d = mp()
def pgcd(x,y):
if x > y:
return pgcd(y,x)
if y%x == 0:
return x
else:
return pgcd(y%x,x)
if (abs(b-d))%pgcd(a,c)!= 0:
pt(-1)
else:
k=b
s=d
while k != s:
if k>s:
s+=c
else:
k+=a
pt(k) | 7 | PYTHON3 |
import sys
input=sys.stdin.readline
l=input().split()
a=int(l[0])
b=int(l[1])
l=input().split()
c=int(l[0])
d=int(l[1])
if(b>d):
b,d=d,b
a,c=c,a
for i in range(105):
if((d-b+i*c)%a==0):
print(d+i*c)
quit()
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b;
cin >> c >> d;
map<int, int> my;
for (int i = 0; i < 100000; i++) my[b + a * i]++;
for (int i = 0; i < 100000; i++)
if (my[d + c * i]) {
cout << d + c * i << endl;
return 0;
}
cout << -1;
return 0;
}
| 7 | CPP |
IL = lambda: list(map(int, input().split()))
I = lambda: int(input())
a, b = IL()
c, d = IL()
e = sorted(list(set(range(b, 20000, a)).intersection(set(range(d, 20000, c)))))
if len(e):
print(e[0])
else:
print(-1) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
for i in range(100):
for j in range(100):
if b + i*a == d + j*c:
print(b+i*a)
exit()
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int Dx[] = {1, -1, 0, 0};
int Dy[] = {0, 0, 1, -1};
void fast() {
ios::sync_with_stdio(0);
cin.tie(0);
}
void file() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
bool ok1(int a, int b, int c) { return a + b > c; }
bool ok2(int a, int b, int c) { return a + b == c; }
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int i = 0;
map<int, bool> bb;
while (i < 1e4) {
int x = a * i + b;
int y = c * i + d;
if (bb[x] || x == y) return cout << x << endl, 0;
if (bb[y]) return cout << y << endl, 0;
bb[x] = bb[y] = 1;
i++;
}
cout << -1 << endl;
return 0;
}
| 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
k=0
for i in range(101):
for j in range(101):
if(b+a*i==d+c*j):
print(d+c*j)
k=1
break
if(k==1):
break
if(k==0):
print('-1')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> c >> d;
if (b < d) {
swap(b, d);
swap(a, c);
}
for (i = 0; i <= 100005; i++) {
k = b + i * a;
if ((k - d) % c == 0) {
cout << k;
return 0;
}
}
cout << -1;
return 0;
}
| 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
r=set(range(b, 10000, a))
m=set(range(d, 10000, c))
ans=r&m
if ans:
print(min(ans))
else:
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
void input() { cin >> a >> b >> c >> d; }
void solve() {
while (b <= 5000000 || d <= 5000000) {
if (b == d) {
cout << b << "\n";
return;
}
if (b < d) {
b += a;
} else {
d += c;
}
}
cout << "-1\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
char f[100000005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i <= 10000; ++i) {
f[d + i * c]++;
f[b + a * i]++;
}
int fa = -1, fc = -1;
for (int i = 0; i <= 10000; ++i) {
if (f[d + i * c] > 1) {
fc = d + i * c;
break;
}
}
for (int i = 0; i <= 10000; ++i) {
if (f[b + i * a] > 1) {
fa = b + i * a;
break;
}
}
if (fa == -1)
cout << "-1\n";
else
cout << min(fa, fc) << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e7 + 5;
const int nil = 0;
const int oo = (1 << 28);
bool g1[MAX], g2[MAX];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b, c, d;
cin >> b >> a >> d >> c;
for (int i = a; i < MAX; i += b) g1[i] = true;
for (int i = c; i < MAX; i += d) {
if (g1[i]) {
cout << i << "\n";
return 0;
}
}
cout << "-1\n";
return 0;
}
| 7 | CPP |
a,b = map(int,input().split())
c,d = map(int,input().split())
f = set()
s = set()
ans = -1
i = 0
while(ans == -1 and i<10000):
ff = (b + i*a)
ss = (d + i*c)
f.add(ff)
s.add(ss)
if(f&s):
ans = min(f & s)
i+=1
print(ans) | 7 | PYTHON3 |
import sys
def input(): return sys.stdin.readline().rstrip("\r\n")
def List(): return list(map(int, input().split()))
def Num(): return int(input())
def solve():
a, b = List()
c, d = List()
ok = False
for i in range(500):
for j in range(500):
if b + a * i == d + c * j:
return b + a * i
return -1
print(solve())
| 7 | PYTHON3 |
a,b=map(int,input().split())
c,d=map(int,input().split())
x,y=0,0
s=0
bb,dd=b,d
while(1):
s=s+1
if(s==10000):
print(-1)
break
if(bb==dd):
print(bb)
break
elif(bb>dd):
dd=d+c*x
x=x+1
elif(bb<dd):
bb=b+a*y
y=y+1
| 7 | PYTHON3 |
def inputIntegerArray():
return list( map( int, input().split(" ") ) )
(a,b) = inputIntegerArray()
(c,d) = inputIntegerArray()
values = []
for i in range(0,100):
values.append(b+ i* a )
for i in range(0,100):
if d + i*c in values:
print( d + i*c )
quit()
print ( "-1" ) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int gcdExtended(long long int a, long long int b, long long int *x,
long long int *y) {
if (a == 0) {
*x = 0;
*y = 1;
return b;
}
long long int x1, y1;
long long int gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
long long int gcd(long long int a, long long int b) {
return (a % b == 0) ? abs(b) : gcd(b, a % b);
}
bool isPossible(long long int a, long long int b, long long int c) {
return (c % gcd(a, b) == 0);
}
int main() {
ios::sync_with_stdio(0);
long long int a, b, c, d;
cin >> a >> b;
cin >> c >> d;
long long int aa = a;
long long int bb = -1 * c;
long long int res = d - b;
if (!isPossible(aa, bb, res)) {
cout << -1 << "\n";
} else {
long long int r = 0, t = 0;
long long int x = b;
long long int y = d;
while (x != y) {
if (x > y) {
y = c + y;
} else if (y > x) {
x = x + a;
}
}
cout << x;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e7 + 5;
void solve() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
for (long long i = 0; i < N; i++) {
long long x = b + i * a;
double y = ((1.0) * (x - d)) / c;
if (ceil(y) == floor(y) && y >= 0) {
cout << x << "\n";
return;
}
}
cout << -1 << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
clock_t start = clock();
long long t = 1;
while (t--) {
solve();
}
clock_t stop = clock();
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d, x, i, y;
scanf("%I64d", &a), scanf("%I64d", &b), scanf("%I64d", &c),
scanf("%I64d", &d);
x = b;
while (x <= 10000) {
if (x >= d and (x - d) % c == 0) break;
x += a;
}
if (x <= 10000)
cout << x << endl;
else
cout << -1;
return 0;
}
| 7 | CPP |
a=input().split()
c=input().split()
b=int(a[1])
a=int(a[0])
d=int(c[1])
c=int(c[0])
r=[]
t=b-d;
while(not(t in r)):
if(t==0):break
if(b<d):b=b+a
else:d=d+c
r=r+[t]
t=b-d
if(t==0):print(b)
else:print(-1)
| 7 | PYTHON3 |
def prog():
b, a = [int(i) for i in input().split()]
d, c = [int(i) for i in input().split()]
#print(a,b,c,d)
times = []
for i in range(1000):
times.append(a + i*b)
for i in range(1000):
if c + i*d in times:
print(c + i*d)
exit()
print("-1")
if __name__ == "__main__":
prog()
| 7 | PYTHON3 |
a,b = map(int,input().split())
c,d = map(int,input().split())
t = 10**5
i = 0
flag = 0
if d > b:
while i < t:
r = d - b + c*i
if r%a == 0:
flag = 1
break
i = i + 1
if flag == 0:
print(-1)
exit()
else:
print(d+c*i)
else:
while i < t:
r = b - d + a*i
if r%c == 0:
flag = 1
break
i = i + 1
if flag == 0:
print(-1)
else:
print(a*i+b)
| 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
x = [b + a * i for i in range(3 * 10**3)]
y = [d + c * i for i in range(3 * 10**3)]
for i in x:
if i in y:
print(i)
break
else:
print(-1) | 7 | PYTHON3 |
a, b = map(int,input().split())
c, d = map(int,input().split())
ONE = set()
TWO = set()
for i in range(b, 50000, a):
ONE.add(i)
for i in range(d, 50000, c):
TWO.add(i)
opt = 99999
for i in ONE:
if i in TWO:
opt = min(opt, i)
if opt == 99999:
print(-1)
else:
print(opt) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = -1
for i in range(max(b, d), max(b, d) + a * c):
if (i - b) % a == 0 and (i - d) % c == 0:
ans = i
break
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int x = 0, y = 0, p = 0;
for (int i = 0; i < 10e7; i++) {
if (b + a * x == d + c * y) {
p = 1;
break;
} else if (b + a * x > d + c * y)
y++;
else if (b + a * x < d + c * y)
x++;
}
if (p == 1)
cout << b + a * x << endl;
else
cout << -1 << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> b >> a >> d >> c;
bool flag(false);
for (int i = 0; i < 100000; i++) {
if (a == c) {
cout << a << endl;
flag = true;
break;
} else if (a > c)
c += d;
else if (a < c)
a += b;
}
if (!flag) cout << "-1" << endl;
return 0;
}
| 7 | CPP |
a, b = [int(i) for i in input().split()]
c, d = [int(i) for i in input().split()]
for m in range(0, 1000000):
if (m * c + d - b) % a == 0:
k = (m * c + d - b) // a
if (k * a + b == m * c + d) and k >= 0:
print(k * a + b)
break
else:
print(-1)
| 7 | PYTHON3 |
from typing import Callable, Iterator
read: Callable[[], Iterator[int]] = lambda: map(int, input().split())
b, a = read()
d, c = read()
ans = -1
n = int(1000005)
for i in range(n):
cur = a + i * b
if (cur - c) % d == 0 and (cur - c) // d >= 0:
ans = cur
break
print(ans)
| 7 | PYTHON3 |
def calculateTime(a, b, c, d):
ans1 = b
ans2 = d
i = 0
for i in range(1000):
for j in range(1000):
if (b + (i * a) == d + (j * c)):
return b + (i * a)
break
return -1
a, b = map(int, input().split())
c, d = map(int, input().split())
print(calculateTime(a, b, c, d))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, a, b, c, d;
cin >> a >> b >> c >> d;
for (i = 1; i < 10000000; i++) {
if ((i - b) % a == 0) {
if ((i - d) % c == 0) {
if (i >= b) {
if (i >= d) {
cout << i;
exit(0);
}
}
}
}
}
cout << -1;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, x;
int i, j, ans = INT_MAX;
cin >> a >> b >> c >> d;
for (i = 0; i <= 100000; i++) {
x = b + a * i;
if ((x - d) % c == 0 && (x - d) >= 0)
if (x < ans) ans = x;
}
if (ans == INT_MAX)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
cin >> b >> a >> d >> c;
if (a > c) swap(a, c), swap(b, d);
for (int i = c; i < 1000000; i++)
if ((i - a) % b == 0 && (i - c) % d == 0) {
cout << i << endl;
return 0;
}
cout << -1 << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
while (~scanf("%d%d%d%d", &a, &b, &c, &d)) {
int i, j;
int sum1 = b;
int flag = 0;
for (i = 1; i <= 1000; i++) {
for (j = 1; j <= 1000; j++) {
if (b + a * (i - 1) == d + c * (j - 1)) {
printf("%d\n", b + a * (i - 1));
flag = 1;
break;
}
}
if (flag) break;
}
if (!flag) printf("-1\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
int calGCD(int x, int y) {
if (y == 0)
return x;
else {
return calGCD(y, x % y);
}
}
int main() {
int a, b, c, d;
int gcd;
scanf("%d%d", &a, &b);
scanf("%d%d", &c, &d);
gcd = calGCD(a, c);
if ((b - d) % gcd != 0) {
printf("-1\n");
} else {
int screamB = b, screamD = d;
while (screamB != screamD) {
if (screamB > screamD) {
screamD += c;
} else {
screamB += a;
}
}
printf("%d\n", screamD);
}
}
| 7 | CPP |
from time import time as tm
b, a = map(int, input().split())
d, c = map(int, input().split())
cur = ma = mb = 0
stm = tm()
while tm() - stm < 0.9:
isa = (a + b * ma) == cur
isb = (c + d * mb) == cur
if isa:
ma += 1
if isb:
mb += 1
if isa and isb:
print(cur)
break
cur += 1
else:
print(-1)
| 7 | PYTHON3 |
read = lambda: map(int, input().split())
b, a = read()
d, c = read()
ans = -1
N = int(1.1e6)
for i in range(N):
cur = a + i * b
if (cur - c) % d == 0 and (cur - c) // d >= 0:
ans = cur
break
print(ans) | 7 | PYTHON3 |
line = input()
a, b = line.split()
a, b = int(a), int(b)
line = input()
c, d = line.split()
c, d = int(c), int(d)
x = b
x_count = 1
y = d
y_count = 1
while y != x and y <= 10100 and x <= 10100:
if y > x:
x = b + (x_count * a)
x_count = x_count + 1
else:
y = d + (y_count * c)
y_count = y_count + 1
if y == x:
print(y)
else:
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long INF = 1e18;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long a, b, c, d;
cin >> a >> b >> c >> d;
set<long long> s;
for (long long i = 0;; i++) {
long long val = b + a * i;
s.insert(val);
if (val > 1000000) break;
}
long long ans = INF;
for (long long i = 0;; i++) {
long long val = d + c * i;
if (s.count(val)) ans = min(ans, val);
if (val > 1000000) break;
}
if (ans == INF) ans = -1;
cout << ans << '\n';
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long c, d;
cin >> c >> d;
for (long long i = 0; i <= 1e4; i++) {
for (long long j = 0; j <= 1e4; j++) {
if (b + a * i == d + c * j) {
cout << b + a * i << "\n";
return 0;
}
}
}
cout << -1 << "\n";
}
| 7 | CPP |
a,b=[int(c) for c in input().split(' ')]
c,d=[int(c) for c in input().split(' ')]
i=0
max=pow(10,5)
while b!=d and i<max:
while d<b:
d+=c
while b<d:
b+=a
i+=1
if b!=d:
print(-1)
else:
print(d) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int main() {
int a, b;
int c, d;
while (cin >> a >> b) {
cin >> c >> d;
vector<long long> arr(maxn);
vector<long long> temp(maxn);
for (int i = 0; i < maxn; i++) {
arr[i] = b + i * a;
temp[i] = d + i * c;
}
int flag = 0;
for (int i = 0; i < maxn; i++) {
for (int j = 0; j < maxn; j++) {
if (arr[i] == temp[j]) {
cout << arr[i] << endl;
flag = 1;
break;
}
}
if (flag) break;
}
if (flag == 0) {
cout << -1 << endl;
}
}
return 0;
}
| 7 | CPP |
def solution(a, b, c, d):
mult = 0
seti = set()
for i in range(10000):
aux = b + (mult*a)
if aux not in seti:
seti.add(aux)
else:
return aux
aux = d + (mult*c)
if aux not in seti:
seti.add(aux)
else:
return aux
mult += 1
return -1
def main():
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
print(solution(a, b, c, d))
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
int cnt = 0;
int x, y;
scanf("%d %d", &a, &b);
scanf("%d %d", &c, &d);
x = b;
y = d;
while (x != y && cnt < 210) {
if (x < y)
x += a;
else
y += c;
cnt++;
}
if (cnt == 210)
printf("-1\n");
else
printf("%d", x);
return 0;
}
| 7 | CPP |
gcd = lambda a,b: a if b==0 else gcd(b,a%b)
lcm = lambda a,b: a*b//(gcd(a,b) if a>b else gcd(b,a))
def f(l1,l2):
a,b = l1
c,d = l2
s = max(b,d)
e = s + lcm(a,c) + 1
i = s
while i < e:
if (i-b)%a==0 and (i-d)%c==0:
return i
i += 1 # not optimized, but work?
return -1
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
print(f(l1,l2))
| 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
for i in range(0, 101):
for j in range(0, 101):
if b + i * a == d + j * c:
print(b + i * a)
exit(0)
print(-1)
| 7 | PYTHON3 |
a,b=map(int,input().split())
c,d=map(int,input().split())
t=max(a,b,c,d)+1
flag=-1
for i in range(t):
if (b+a*i-d)%c==0 and b+a*i>=d:
flag=b+a*i
break
print(flag)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a == 0 || b == 0) return 0;
if (a == b) return a;
if (a > b) return gcd(a - b, b);
return gcd(a, b - a);
}
int main() {
int a, b;
cin >> a >> b;
int c, d;
cin >> c >> d;
int g = gcd(a, c);
int check = abs(d - b) / g;
if (check * g != abs(d - b))
cout << "-1" << endl;
else {
while (b != d) {
if (b < d)
b += a;
else
d += c;
}
cout << b << endl;
}
}
| 7 | CPP |
from math import inf
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
if b > d:
a, c = c, a
b, d = d, b
r1 = (d-b) % a
r2 = c % a
k2s = [(r1+k2*r2) % a for k2 in range(a)]
if 0 not in k2s:
print(-1)
else:
print(k2s.index(0)*c+d) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
scanf("%d%d%d%d", &a, &b, &c, &d);
long long key = 0;
if (b < d) {
swap(b, d);
swap(a, c);
}
for (int i = 0; i < 1000000; i++) {
key = b + a * i;
if ((key - d) % c == 0) {
printf("%lld\n", key);
return 0;
;
}
}
printf("-1\n");
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, pro, g, x, y, t, ma, lcm, ans;
int exgcd(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
int g = exgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
int main() {
cin >> a >> b >> c >> d;
ma = max(b, d);
pro = d - b;
g = exgcd(a, c, x, y);
if (pro % g)
cout << -1 << endl;
else {
t = c / g;
x = x * pro / g;
x = (x % t + t) % t;
ans = b + x * a;
lcm = a * c / g;
while (ans < ma) ans += lcm;
cout << ans << endl;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i <= 100000; i++) {
if ((b + i * a - d) >= 0 && (b + i * a - d) % c == 0) {
cout << b + i * a << endl;
return 0;
}
}
for (int i = 0; i <= 100000; i++) {
if ((d + i * c - b) >= 0 && (d + i * c - b) % a == 0) {
cout << d + i * c << endl;
return 0;
}
}
cout << -1 << endl;
}
| 7 | CPP |
import math
a,b = list(map(int,input().split()))
c,d = list(map(int,input().split()))
f = abs(d - b)
if (f)%(math.gcd(a,c))==0:
while b!=d:
if b>d:
d = d+c
else:
b = b+a
print(b)
else:
print(-1)
| 7 | PYTHON3 |
a, b = tuple(map(int, input().split()))
c, d = tuple(map(int, input().split()))
from sys import exit
mod = d%c
for i in range(1000):
if b >= d and b%c == mod:
print(b)
exit()
b += a
print(-1) | 7 | PYTHON3 |
import sys
I=lambda:list(map(int,input().split()))
a,b=I()
c,d=I()
for i in range(101):
for j in range(101):
if b+a*i==d+c*j:
print(b+a*i)
sys.exit()
print(-1) | 7 | PYTHON3 |
def main():
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
check = 0
for i in range(100):
y = b + a*i
x = (b + a*i - d) * 1.0 / c
if x >= 0 and x == int(x):
print(y)
check += 1
break
if check == 0:
print("-1")
main()
| 7 | PYTHON3 |
if __name__ == '__main__':
a, b = input().split()
a, b = int(a), int(b)
c, d = input().split()
c, d = int(c), int(d)
i = 0
for i in range(1000001):
if (b - d) % c == 0 and (b - d) / c >= 0:
print(b)
break
b += a
if i == 1000000:
print(-1)
break
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
static void call(string::iterator it, string::iterator ed) {}
template <typename T, typename... aT>
static void call(string::iterator it, string::iterator ed, T a, aT&... rest) {
string b;
for (; *it != ','; ++it)
if (*it != ' ') b += *it;
cout << b << "=" << a << " ";
call(++it, ed, rest...);
}
};
int main() {
long long int a, b, c, d, i, j;
cin >> a >> b >> c >> d;
map<long long int, long long int> mp;
for (i = 0; i <= 1000000; i++) {
long long int ret = b + i * a;
if (mp[ret] != 0) {
cout << ret << endl;
return 0;
}
mp[ret]++;
ret = d + i * c;
if (mp[ret] != 0) {
cout << ret << endl;
return 0;
}
mp[ret]++;
}
cout << -1 << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const long long MOD = 1e9 + 7;
bool isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) return false;
}
return true;
}
void solve() {
int a, b, c, d;
cin >> b >> a >> d >> c;
for (int i = 0; i < 10000; i++) {
if ((a + b * i - c) % d == 0 && (a + b * i - c) >= 0) {
cout << a + b * i << "\n";
return;
}
}
cout << -1 << "\n";
return;
}
int main() { solve(); }
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &c) {
s << "[ ";
for (auto it : c) s << it << " ";
s << "]\n";
return s;
}
int main() {
int a, b, c, d;
cin >> b >> a >> d >> c;
map<int, int> meow;
for (int i = 0; i < 7122; ++i) {
meow[a] = 1;
a += b;
}
for (int i = 0; i < 7222; ++i) {
if (meow[c]) {
cout << c << '\n';
return 0;
}
c += d;
}
cout << "-1\n";
return 0;
}
| 7 | CPP |
def gcd(a,b):
while b:
a,b = b,a%b
return a
a,b = map(int,input().split())
c,d = map(int,input().split())
A = d//a
D = d%a
C = b//c
B = b%c
g = gcd(a,c)
aa = a//g
cc = c//g
delta = D-B
if delta%g != 0:
print(-1)
else:
delta //= g
for x in range(-A,-A+cc+100):
done = False
for y in range(-C,-C+aa+100):
if aa*x-cc*y == delta:
print(b+g*aa*(x+A))
done = True
break
if done:
break
else:
print(-1)
| 7 | PYTHON3 |