Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def main():
    n = int(input())
    s = input()
    # Positions for each character.
    r = []
    g = []
    b = []
    for ind, c in enumerate(s):
        if c == 'R':
            r.append(ind)
        elif c == 'G':
            g.append(ind)
        else:
            b.append(ind)
    ans = 0

    for i in r:
        for j in g:
            for k in b:
                o, p, q = sorted((i, j, k))
                if p - o != q - p:
                    ans += 1
    return ans


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

def main():
    n = int(input())
    s = input()
    # Positions for each character.
    r = set()
    g = set()
    r_add = r.add
    g_add = g.add
    for ind, c in enumerate(s):
        if c == 'R':
            r_add(ind)
        elif c == 'G':
            g_add(ind)
    b = set(range(n)) - r - g

    ans = 0
    for i in r:
        for j in g:
            p, q = min(i, j), max(i, j)
            if (q - p) % 2 == 0 and (p + q) // 2 in b:
                ans -= 1
            if (q + (q - p)) in b:
                ans -= 1
            if (p - (q - p)) in b:
                ans -= 1
            ans += len(b)
    return ans


if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

N = int(input())
L = [[] for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(N):
    tmp = format(As[i], 'b').zfill(60)
    for j in range(60):
        L[j].append(int(tmp[j]))


def calc(acc, i):
    if i == 0:
        return acc
    else:
        return calc(acc*2 % mod, i-1)


for i in range(60):
    tmp = calc(1, 59 - i)
    a = sum(L[i]) % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod
ans = ans % mod
print(ans)

### FIXED CODE ###

N = int(input())
L = [0 for i in range(60)]
As = list(map(int, input().split()))
mod = 1000000007
ans = 0

for A in As:
    for i in range(60):
        if A >> i & 1 == 1:
            L[i] += 1

acc = 1
tmps = []
for i in range(60):
    tmps.append(acc)
    acc = acc * 2 % mod

for i in range(60):
    tmp = tmps[i]
    a = L[i] % mod
    b = (N - a) % mod
    ans += (tmp * a * b) % mod

ans = ans % mod
print(ans)
### BUGGY CODE ###

import sys
n,k = [int(_) for _ in input().split()]
base = n

if n % k == 0 :
  print("0")
  sys.exit()

while base > abs(base - k):
  base = abs(base - k)

print(base)

### FIXED CODE ###

import sys
n,k = [int(_) for _ in input().split()]

amari = n % k
if amari == 0 :
  print("0")
  sys.exit()

base = amari
while base > abs(base - k):
  base = abs(base - k)

print(base)
### BUGGY CODE ###

import sys
import bisect

input = sys.stdin.readline

def main():

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()
    a = tuple(a)

    bc.sort(key=lambda x: x[1], reverse=True)

    num = 0
    ans = 0

    for i in range(m):
        b = bc[i][0]
        c = bc[i][1]
        index = bisect.bisect_left(a[num:],c)
        if index == 0:
            break
        elif index > b:
            ans += c * b
        else:
            ans += c * index
            ans += sum(a[num+index:num+b])

        num += b
        if num >= n:
            break

    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)
if __name__ == '__main__':
  main()


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()
    a = tuple(a)

    bc.sort(key=lambda x: x[1], reverse=True)

    num = 0
    ans = 0

    for i in range(m):
        b = bc[i][0]
        c = bc[i][1]
        for j in range(num,min(num+b,n)):
            if c > a[j]:
                ans += c
            else:
                ans += a[j]

        num += b
        if num >= n:
            break

    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, K = map(int, input().split())
p_list = list(map(int, input().split()))

dst = 0.0

for i in range(N-K+1):
    p_sum = 0.0
    for j in range(K):
        p = p_list[i+j]
        p_sum += ( p/2 * (1+p)) / p
    if p_sum > dst:
        dst = p_sum
    
print(dst)

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))

#期待値L
L = [0 for _ in range(N)]
for i in range(N):
    L[i] = (1+P[i])/2

#累積和S
S = [0 for i in range(N)]
S[0] = L[0]
for i in range(1, N):
    S[i] = S[i-1] + L[i]

total = S[K-1]
for i in range(N-K):
    tmp = S[i+K]-S[i]
    if total < tmp:
        total = tmp

print(total)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    x = a.index(max(a))
    a[x] //= 2
print(sum(a))


### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = [int(i) * (-1) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    x = heapq.heappop(a) * (-1) // 2
    heapq.heappush(a, x * (-1))
print(-sum(a))
### BUGGY CODE ###

k,s=map(int,input().split())
upper  = min(k,s)+1
lower = max(0,s-2*k)
ans = 0
for i in range(lower,upper):
  for j in range(lower,upper):
    for k in range(lower,upper):
      if i+j+k == s:
        ans += 1
print(ans)

### FIXED CODE ###

k,s=map(int,input().split())
upper  = min(k,s)+1
lower = max(0,s-2*k)
ans = 0
for i in range(lower,upper):
  for j in range(lower,upper):
    if 0 <= s-(i+j) <= k:
      ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(set(a))
s =0
for i in b:
    if(a.count(i)<i):
        s += a.count(i)
    elif(a.count(i)>i):
        s += a.count(i)-i
print(s)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = {}
for i in a:
    b[i] = b.get(i,0)+1
s =0
for i in b.keys():
    c = b[i]
    if(c<i):
        s += c
    elif(c>i):
        s += c-i
print(s)
### BUGGY CODE ###

N,T=map(int,input().split());AB=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*T
AB.sort()
m=0
for a,b in AB:
  m=max(m,dp[-1]+b)
  for j in range(T-1,a-1,-1):
    dp[j] = max(dp[j],dp[j-a]+b)

print(m)


### FIXED CODE ###

N,T=map(int,input().split());AB=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*T
AB.sort()
m=0
for a,b in AB:
  m=max(m,dp[-1]+b)
  for j in range(T-1,a-1,-1):
    dp[j] = max(dp[j],dp[j-a]+b)

print(m)
### BUGGY CODE ###

import math

a,b,n = map(int,input().split())

l = []

for x in range(n+1):
    ans = 0
    ans = math.floor(a*x/b) - a * math.floor(x/b)
    l.append(ans)

print(max(l))

### FIXED CODE ###

A,B,N=map(int,input().split())
def f(x):
  return int(A*x/B)-A*int(x/B)

print(f(min(N,B-1)))
### BUGGY CODE ###

from collections import Counter
h, w, m = map(int, input().split())
A = []
B = []
points = set()
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    points.add((a - 1,b - 1))
ac = Counter(A).most_common()
bc = Counter(B).most_common()
#print(ac, bc, points)
x = ac[0][1]
y = bc[0][1]
acm = [i for i, j in ac if j == x]
bcm = [i for i, j in bc if j == y]

ans = 0
for i in acm:
    for j in bcm:
        tmp = x + y
        if (i, j) in points:
            tmp -= 1
        ans = max(ans, tmp)
print(ans)


### FIXED CODE ###

from collections import Counter
h, w, m = map(int, input().split())
A = []
B = []
points = set()
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)
    points.add((a - 1, b - 1))
ac = Counter(A).most_common()
bc = Counter(B).most_common()
#print(ac, bc, points)

x = ac[0][1]
y = bc[0][1]

acm = []
bcm = []

for i, j in ac:
    if j == x:
        acm.append(i)
    else:
        break

for i, j in bc:
    if j == y:
        bcm.append(i)
    else:
        break

ans = x + y - 1
for i in acm:
    for j in bcm:
        if (i, j) not in points:
            print(ans + 1)
            exit()
print(ans)
### BUGGY CODE ###

# 2020/07/26
# diverta 2019 Programming Contest - B

# Input
r, g, b, n = map(int,input().split())

ans = 0

# Calc
for ir in range(n+1):
    for ig in range(n+1):
        cb = n - r * ir - g * ig
        if cb >= 0 and cb % b == 0:
            ans = ans + 1

# Output
print(ans)


### FIXED CODE ###

# 2019/05/12
# diverta 2019 Programming Contest - B

# Input
r, g, b, n = map(int, input().split())

# Init
cnt = 0

# Calc
for i in range(n+1):
    rcnt = r * i
    if rcnt > n:
        break
    
    for j in range(n+1):
        rgcnt = rcnt + g * j
        if rgcnt > n:
            break
        bcnt = n - rgcnt
        if bcnt % b == 0:
            cnt += 1
# Output
print(cnt)
### BUGGY CODE ###

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


class SEGMENT_TREE:
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (2 * N)  # 問題により修正

    def init(self, arr):
        N = self.N
        for i in range(N):
            self.tree[N + i] = arr[i]
        for i in range(N - 1, 0, -1):
            self.tree[i] = gcd(
                self.tree[i * 2], self.tree[i * 2 + 1])  # 問題により修正

    def update(self, p, value):
        i = p + self.N
        self.tree[i] = value
        while i > 1:
            self.tree[i // 2] = gcd(self.tree[i], self.tree[i ^ 1])  # 問題により修正
            i //= 2

    def query(self, l, r):
        N = self.N
        res = 0  # 問題により修正
        l += N
        r += N
        while l < r:
            if (l & 1):
                res = gcd(res, self.tree[l])  # 問題により修正
                l += 1
            if (r & 1):
                r -= 1
                res = gcd(res, self.tree[r])  # 問題により修正
            l //= 2
            r //= 2
        return res


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    seg = SEGMENT_TREE(N)
    seg.init(A)
    ans = 0
    for i in range(N):
        tmp = gcd(seg.query(0, i), seg.query(i + 1, N))
        ans = max(ans, tmp)
    print(ans)

### FIXED CODE ###

def gcd(x, y):
    x, y = max(x, y), min(x, y)
    if y == 0:
        return x
    return gcd(y, x % y)


n = int(input())
a = list(map(int, input().split()))

l = [0]*n
r = [0] * n
for i in range(n):
    if i == 0:
        l[i] = a[i]
        continue
    l[i] = gcd(a[i], l[i-1])

for i in range(n - 1, -1, -1):
    if i == n - 1:
        r[i] = a[i]
        continue
    r[i] = gcd(a[i], r[i+1])

l = [0] + l[:-1]
r = r[1:] + [0]

ans = 0
for x, y in zip(l, r):
    ans = max(ans, gcd(x, y))
print(ans)
### BUGGY CODE ###

from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

H, W, ch, cw, gh, gw, *S = open(0).read().split()
H, W, ch, cw, gh, gw = [int(_) - 1 for _ in [H, W, ch, cw, gh, gw]]
H += 1
W += 1

X = []
Y = []
D = []
for i in range(H * W):
    h, w = divmod(i, W)
    if S[h][w] == '#':
        continue
    for dh in range(-2, 3):
        for dw in range(-2, 3):
            if 0 <= h + dh < H and 0 <= w + dw < W and (
                    dh > 0 or
                (dh == 0 and dw > 0)) and S[h + dh][w + dw] == '.':
                X += [i]
                Y += [i + dw + W * dh]
                D += [0 if (dh, dw) in ((1, 0), (0, 1)) else 1]
dist = dijkstra(
    csr_matrix((D, (X, Y)), (H * W, H * W), dtype=int),
    indices=ch * W + cw,
    directed=0)
ans = dist[gh * W + gw]
if ans > 10**10:
    ans = -1
else:
    ans = int(ans)
print(ans)


### FIXED CODE ###

import collections, itertools
H, W, ch, cw, dh, dw, *S = open(0).read().split()
H, W, ch, cw, dh, dw = [int(_) + 1 for _ in [H, W, ch, cw, dh, dw]]
H += 3
W += 3
S = ['#' * W] + ['#' * W] + ['##' + s + '##'
                             for s in S] + ['#' * W] + ['#' * W]
Dist = [[None] * W for _ in range(H)]
Q = collections.deque([(0, ch, cw)])
while Q:
    d, ox, oy = Q.popleft()
    if Dist[ox][oy] is not None:
        continue
    stack = [[ox, oy]]
    warp = set()
    while stack:
        x, y = stack.pop()
        if (x, y) == (dh, dw):
            print(d)
            exit()
        Dist[x][y] = d
        for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None:
                if S[nx][ny] == '.':
                    stack += [[nx, ny]]
                else:
                    warp.add((x, y))
    for x, y in warp:
        for dx, dy in itertools.product(range(-2, 3), repeat=2):
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None and S[nx][ny] == '.':
                Q += [(d + 1, nx, ny)]
print(-1)
### BUGGY CODE ###

A,B,N=map(int,input().split())
ans=0
for i in range(max(1,N-B+1),N+1):
    ans=max(ans,((A*i)//B - A*(i//B)))
print(ans)

### FIXED CODE ###

A,B,N=map(int,input().split())
x=(N//B)*B-1
ans=(A*N)//B - A*(N//B)
if N>=B:
    ans=max(ans, (A*x)//B - A*(x//B))
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    if S[i] == S[j]:
      continue
    for k in range(j+1, N):
      if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        if j-i == k-j:
          continue
        else:
          count += 1
      
print(count)


### FIXED CODE ###

n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')
count = r*g*b
for i in range(n):
    for d in range(n):
        j = i+d
        k = j+d
        if k >= n: 
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k] != s[i]: 
            count -= 1
            
print(count)
### BUGGY CODE ###

H,W,K = map(int,input().split())
r1,c1,r2,c2 = map(lambda x:int(x)-1,input().split())
C = [input() for i in range(H)]

import heapq
dxy = [(0,1),(1,0),(0,-1),(-1,0)]
INF = float('inf')

dists = [INF] * (H*W*4)
dists[(r1*W+c1)*4] = 0
hq = [(r1*W+c1)*4]
heapq.heapify(hq)
while hq:
    v = heapq.heappop(hq)
    cp,d = divmod(v,4)
    cy,x = divmod(cp,W)
    c,y = divmod(cy,H)
    if y==r2 and x==c2:
        print(0--c//K)
        exit()
    for di,(dx,dy) in enumerate(dxy):
        nx,ny = x+dx,y+dy
        if not 0 <= nx < W: continue
        if not 0 <= ny < H: continue
        if C[ny][nx] == '@': continue
        if di != d:
            nc = c + (K-c)%K
            if dists[(y*W+x)*4+di] <= nc: continue
            dists[(y*W+x)*4+di] = nc
            heapq.heappush(hq, ((nc*H+y)*W+x)*4+di)
        else:
            if dists[(ny*W+nx)*4+di] <= c+1: continue
            heapq.heappush(hq, (((c+1)*H+ny)*W+nx)*4+di)
print(-1)

### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W,K = map(int,input().split())
r1,c1,r2,c2 = map(lambda x:int(x)-1,input().split())
C = [input() for i in range(H)]

def solve():
    from collections import deque
    dxy = [(0,1),(1,0),(0,-1),(-1,0)]
    INF = float('inf')
    dists = [[INF]*W for _ in range(H)]
    dists[r1][c1] = 0
    q = deque([(r1,c1)])
    while q:
        y,x = q.popleft()
        if y==r2 and x==c2:
            print(dists[y][x])
            exit()
        for dx,dy in dxy:
            for i in range(1,K+1):
                nx,ny = x+dx*i,y+dy*i
                if not 0 <= nx < W: break
                if not 0 <= ny < H: break
                if C[ny][nx] == '@': break
                if dists[ny][nx] <= dists[y][x]: break
                if dists[ny][nx] <= dists[y][x] + 1: continue
                dists[ny][nx] = dists[y][x] + 1
                q.append((ny,nx))
    print(-1)
solve()
### BUGGY CODE ###

from scipy.special import comb
from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]

count = Counter(A)
combs = {k:comb(count[k], 2) for k in count.keys()}
all = sum(combs.values())

for a in A:
    ans = all - combs[a] + comb(count[a]-1,2)
    print(int(ans))


### FIXED CODE ###

from scipy.special import comb
from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]

count = Counter(A)
combs = {k:comb(count[k], 2) for k in count.keys()}
combs_minas_one = {k:comb(count[k]-1, 2) for k in count.keys()}
all = sum(combs.values())

for a in A:
    ans = all - combs[a] + combs_minas_one[a]
    print(int(ans))
### BUGGY CODE ###

N = int(input())

list = []
for i in range(1, 50):
    for j in range(1, 50):
        for k in range(1, 50):
            list.append(i**2 + j**2 + k**2 +i*j + j*k + k*i)

for i in range(N):
    print(list.count(i+1))


### FIXED CODE ###

N = int(input())

list = [0] * 10000
for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            v = i**2 + j**2 + k**2 +i*j + j*k + k*i
            if v <= 10000:
                list[v-1] += 1

for i in range(N):
    print(list[i])
### BUGGY CODE ###

import math
import collections


def P(n, r):
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    if n < 2:
        return 0
    else:
        return P(n, r)//math.factorial(r)


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))


### FIXED CODE ###

import math
import collections


def C(n, r):
    if n < 2:
        return 0
    else:
        return n*(n-1)//r


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))
### BUGGY CODE ###

K,A,B = map(int,input().split())
bis = K+1
tempbis = 1
while K>0:
    if tempbis<A:
        tempbis+=1
    else:
        if K>=2:
            K-=1
            tempbis += B-A
        else:
            tempbis +=1
    K-=1

print(max(bis,tempbis))

### FIXED CODE ###

K,A,B = map(int,input().split())
bis = K+1
tempbis = 1
if A<B and A<K:
    tempbis=A
    K -= A-1
    tempbis += K%2
    tempbis += (B-A)*(K//2)

print(max(bis,tempbis))
### BUGGY CODE ###

n, m, s = map(int,input().split())
adj = [[] for i in range(n)]
for _ in range(m):
    u, v, a, b = map(int,input().split())
    adj[u - 1].append((v - 1,-a,b))
    adj[v - 1].append((u - 1,-a,b))

for i in range(n):
    c, d = map(int,input().split())
    adj[i].append((i,c,d))

out = [-1] * n

LARGE = 10000

done = dict()
from heapq import *
q = []
if s > LARGE:
    s = LARGE
heappush(q, (0, 0, s))

while q:
    time, loc, curr = heappop(q)
    if out[loc] == -1:
        out[loc] = time
    for nex, cost, timeD in adj[loc]:
        currNex = curr + cost
        timeNex = time + timeD
        if currNex > LARGE:
            currNex = LARGE
        if currNex < 0:
            continue
        if (nex, currNex) not in done or timeNex < done[(nex, currNex)]:
            done[(nex, currNex)] = timeNex
            heappush(q, (timeNex, nex, currNex))
print(*out[1:], sep = '\n')
    


### FIXED CODE ###

n, m, s = map(int,input().split())
adj = [[] for i in range(n)]
for _ in range(m):
    u, v, a, b = map(int,input().split())
    adj[u - 1].append((v - 1,-a,b))
    adj[v - 1].append((u - 1,-a,b))

for i in range(n):
    c, d = map(int,input().split())
    adj[i].append((i,c,d))

out = [-1] * n
count = 0

LARGE = 50 * n

done = dict()
from heapq import *
q = []
if s > LARGE:
    s = LARGE
heappush(q, (0, 0, s))

while q:
    time, loc, curr = heappop(q)
    if out[loc] == -1:
        out[loc] = time
        count += 1
        if count == n:
            break
    for nex, cost, timeD in adj[loc]:
        currNex = curr + cost
        timeNex = time + timeD
        if currNex > LARGE:
            currNex = LARGE
        if currNex < 0:
            continue
        if (nex, currNex) not in done or timeNex < done[(nex, currNex)]:
            done[(nex, currNex)] = timeNex
            heappush(q, (timeNex, nex, currNex))
print(*out[1:], sep = '\n')
### BUGGY CODE ###

N = int(input())
import sys
sys.setrecursionlimit(1000000)
MOD = 10**9+7
E = {}
for i in range(0,N+1):
    E[i] = []
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    E[a].append(b)
    E[b].append(a)

dp = [ [0 for i in range(2)] for j in range(100100)]

def dfs(c,p):
    dp[c][0],dp[c][1] = 1,1
    for to in E[c]:
        if to != p:
            dfs(to,c)
            dp[c][0] *= dp[to][0] + dp[to][1]
            dp[c][1] *= dp[to][0]

dfs(0,-1)

ans = (dp[0][0] + dp[0][1]) % MOD
print(ans)


### FIXED CODE ###

from heapq import heappush, heappop
import collections
import math
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    N = int(input())
    E = {}
    for i in range(0, N+1):
        E[i] = []
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        E[a].append(b)
        E[b].append(a)

    dp = [[0 for i in range(2)] for j in range(100100)]

    def dfs(c, p):
        dp[c][0], dp[c][1] = 1, 1
        for to in E[c]:
            if to != p:
                dfs(to, c)
                dp[c][0] *= dp[to][0] + dp[to][1]
                dp[c][1] *= dp[to][0]

    dfs(0, -1)

    ans = (dp[0][0] + dp[0][1]) % MOD
    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

n=int(1.0e+18)
x,y=map(int,input().split(' '))
X = n//x
if x%y==0:
    print('-1')
else:
    i=2
    while i < X:
        if x*i % y != 0:
            print(str(x*i))
        else:
            i+=1
    if i >= X:
        print('-1')

### FIXED CODE ###

n=int(1.0e+18)
x,y=map(int,input().split(' '))
X = n//x
if x%y==0:
    print('-1')
else:
    i=2
    while i < X:
        if (x*i)%y!=0:
            print(str(x*i))
            break
        i+=1
    if i >= X:
        print('-1')
### BUGGY CODE ###

N=int(input())
ldp=[[[False,[]] for j in range(N+1)] for i in range(N)]
ldp[0][0][0]=True
ldp[0][1][0]=True
ldp[0][1][1].append(0)
if N==1:
    print(1)
for i in range(N-1):
    for j in range(N+1):
        #if N<i+2:
        if j<i+2:
            ldp[i+1][j][0]=ldp[i][j][0]
            ldp[i+1][j][1]=ldp[i][j][1]
        else:
            #ldp[i+1][j]=(ldp[i][j] or ldp[i][N-(i+2)])
            if ldp[i][j][0]==True:
                ldp[i+1][j][0]=True
                ldp[i+1][j][1]=ldp[i][j][1]
            #elif ldp[i][N-(i+2)][0]==True:
            elif ldp[i][j-(i+2)][0]==True:
                ldp[i+1][j][0]=True
                #ldp[i+1][j][1]=ldp[i][N-(i+2)][1]+[i+1]
                ldp[i+1][j][1]=ldp[i][j-(i+2)][1]+[i+1]
            else:
                ldp[i+1][j][0]=False
    if ldp[i+1][N][0]==True:
        for k in ldp[i+1][N][1]:
            print(k+1)
        break
#for i in range(N):
#    print(ldp[i])


### FIXED CODE ###

N=int(input())
sum=0
for i in range(N):
    sum+=i+1
    if sum>=N:
        break
for j in range(1,i+2):
    if j!=sum-N:
        print(j)
### BUGGY CODE ###

n, = (int(x) for x in input().split())
p = list(int(x) for x in input().split())

x = 0
for i in range(n):
    for j in range(i+1):
        if p[i] > p[j]:
            break
        if i == j:
            x += 1
print(x)

### FIXED CODE ###

n, = (int(x) for x in input().split())
p = list(int(x) for x in input().split())
 
x = 0
m = 1e6
for i in range(n):
    if p[i] <= m:
        x += 1
        m = p[i]
print(x)