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

N = int(input())
S = input()

#i文字目以降のRGBの数
RGB = [[0]*(N+1) for i in range(3)]
for i in range(N-1,-1,-1):
    if S[i] == "R":
        RGB[0][i] = RGB[0][i+1]+1
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]
    elif S[i] == "G":
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]+1
        RGB[2][i] = RGB[2][i+1]
    else:
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]+1

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += RGB[2][j]
            if j+(j-i) < N and S[j+(j-i)] == "B":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += RGB[0][j]
            if j+(j-i) < N and S[j+(j-i)] == "R":
                ans -= 1
        elif (S[i] == "R" and S[j] == "B") or (S[i] == "B" and S[j] == "R"):
            ans += RGB[1][j]
            if j+(j-i) < N and S[j+(j-i)] == "G":
                ans -= 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()

#i文字目以降のRGBの数
RGB = [[0]*(N+1) for i in range(3)]
for i in range(N-1,-1,-1):
    if S[i] == "R":
        RGB[0][i] = RGB[0][i+1]+1
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]
    elif S[i] == "G":
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]+1
        RGB[2][i] = RGB[2][i+1]
    else:
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]+1

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += RGB[2][j]
            if j+(j-i) < N and S[j+(j-i)] == "B":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += RGB[0][j]
            if j+(j-i) < N and S[j+(j-i)] == "R":
                ans -= 1
        elif (S[i] == "R" and S[j] == "B") or (S[i] == "B" and S[j] == "R"):
            ans += RGB[1][j]
            if j+(j-i) < N and S[j+(j-i)] == "G":
                ans -= 1
print(ans)
### BUGGY CODE ###

N,M= [int(i) for i in input().split()]
n = sorted([int(x) for x in input().split()])

s =[0]*(N+1)
s[0]=n[0]
for i in range(1,N+1):
        s[i] = s[i-1]+n[i-1]
MM=n[-1]*2
mm=n[0]*2

while True:
        c=0        
        r=(mm+MM)//2
        for i in range(N):
                for j in range(N):
                   if n[i]+n[j] >= r:
                        c+=N-j
                        break
        if (MM-mm) < 2:
                break
        elif c>=M:
                mm=r
        elif c<M:
                MM=r

v=0
for i in range(N):
        for j in range(N):
                t=n[i]+n[j]
                if  t >= r:
                        v+= (s[N] - s[j]) + (N-j)*n[i]
                        break
v = v - (c-M)*(r)

print(v)                  


### FIXED CODE ###

from bisect import bisect_left

N,M= [int(i) for i in input().split()]
n = sorted([int(x) for x in input().split()])

s =[0]*(N+1)
s[0]=n[0]
for i in range(1,N+1):
        s[i] = s[i-1]+n[i-1]
MM=n[-1]*2
mm=n[0]*2

while True:
        c=0        
        r=(mm+MM)//2
        for i in range(N):
                c += N-bisect_left(n,r-n[i])
        if (MM-mm) < 2:
                break
        elif c>=M:
                mm=r
        elif c<M:
                MM=r

v=0
for i in range(N):
        j=bisect_left(n,r-n[i])
        v+= (s[N] - s[j]) + (N-j)*n[i]

v = v - (c-M)*(r)

print(v)
### BUGGY CODE ###

t=str(input())
a= str()
for i in t:
    if i=="?":
        a+="D"
    else:
        a+=i
print(a)


### FIXED CODE ###

t=str(input())
print(t.replace("?","D"))
### BUGGY CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(set(a))
c = []
for i in b:
  c.append(a.count(i))
c.sort(reverse=True)
#if len(c) == k:
  #print(0)
#else:
print(sum(c[k:]))

### FIXED CODE ###

import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
values, counts = zip(*c.most_common())
print(sum(counts[k:]))
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    word = S[l - 1: r]
    ans.append(word.count('AC'))

for i in ans:
    print(i)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
check = []
num, cnt = 0, 0

for i in range(N):
    if S[i] == 'A':
        cnt = 1
    elif S[i] == 'C':
        if cnt == 1:
            cnt = 0
            num += 1
    else:
        cnt = 0
    check.append(num)

for l, r in lr:
    print(check[r - 1] - check[l - 1])
### BUGGY CODE ###

# -*- coding: utf-8 -*-

"""
参考：http://tutuz.hateblo.jp/entry/2018/08/06/074104
・別解
・予め必要なA,C,?の個数は集めておく。
・Bの位置を決めて、4つの選び方パターンを全部数え上げる。
"""

MOD = 10 ** 9 + 7
S = input()

# あるBの位置よりも左にあるAと?の個数
A, LQ = [0] * len(S), [0] * len(S)
for i in range(len(S)-1):
    a = lq = 0
    if S[i] == 'A':
        a += 1
    if S[i] == '?':
        lq += 1
    A[i+1] = A[i] + a
    LQ[i+1] = LQ[i] + lq
# あるBの位置よりも右にあるCと?の個数
C, RQ = [0] * len(S), [0] * len(S)
for i in range(len(S)-1, 0, -1):
    c = rq = 0
    if S[i] == 'C':
        c += 1
    if S[i] == '?':
        rq += 1
    C[i-1] = C[i] + c
    RQ[i-1] = RQ[i] + rq

ans = 0
for i in range(len(S)):
    if S[i] == '?' or S[i] == 'B':
        # (A,B,C) と選ぶ場合(後ろの3べきは使わなかった?の分)
        case1 = (A[i] * C[i] * pow(3, LQ[i] + RQ[i])) % MOD
        # (A,B,?) と選ぶ場合
        case2 = (A[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0))) % MOD
        # (?,B,C) と選ぶ場合
        case3 = (LQ[i] * C[i] * pow(3, max(LQ[i] + RQ[i] - 1, 0))) % MOD
        # (?,B,?) と選ぶ場合
        case4 = (LQ[i] * RQ[i] * pow(3, max(LQ[i] + RQ[i] - 2, 0))) % MOD
        # 全部足し合わせてMOD
        ans = (ans + case1 + case2 + case3 + case4) % MOD

print(int(ans))


### FIXED CODE ###

# -*- coding: utf-8 -*-

"""
参考：http://drken1215.hatenablog.com/entry/2018/08/05/224100_1
・文字列DP
・こういう、ちょっと状況込み入ったDPがまだ自分でうまく書けない。
・もっと数こなして経験積まなきゃなー。
"""

MOD = 10 ** 9 + 7
S = input()

# 文字列Sのi文字目まで考えたときにABCのj文字目まで照合させた個数
dp = [[0] * 4 for i in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)):
    # i文字目でABCカウントを進めない場合(真下に送る分)
    for j in range(4):
        if S[i] == '?':
            dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 3) % MOD
        else:
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
    # i文字目でABCカウントを進める場合(右下に送る分)
    if S[i] == '?' or S[i] == 'A':
        dp[i+1][1] = (dp[i+1][1] + dp[i][0]) % MOD
    if S[i] == '?' or S[i] == 'B':
        dp[i+1][2] = (dp[i+1][2] + dp[i][1]) % MOD
    if S[i] == '?' or S[i] == 'C':
        dp[i+1][3] = (dp[i+1][3] + dp[i][2]) % MOD

print(dp[len(S)][3])
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N, M = map(int, input().split())
aN = list(map(int, input().split()))

cnt = 0
for i in range(N):
    ans = 0
    for j in range(i, N):
        ans += aN[j]
        if ans % M == 0:
            cnt += 1
print(cnt)


### FIXED CODE ###

# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc105/editorial.pdf
　　　http://drken1215.hatenablog.com/entry/2018/08/13/125300
　　　https://www.hamayanhamayan.com/entry/2018/08/12/010816
・左端固定で右端動かすループの累積和だけ取れば、
　(右端の累積和)-(左端-1の累積和)で、どこでも分かるようになる。
・B-AがMの倍数 → BとAのmod Mが等しい(やってみれば分かる)
・各ループ内で、それまでに集計した累積和mod Mから左端として使える場所を数える。
"""

from collections import defaultdict

N, M = map(int, input().split())
aN = list(map(int, input().split()))

# 累積和を一時的に格納する変数
sm = 0
ans = 0
# 累積和のmod Mを格納するdict
d = defaultdict(int)
# 何もない累積和0の分を足しておく
d[0] = 1
for i in range(N):
    sm += + aN[i]
    # 今回のsm%Mを右端として、mod Mが同値になる左端候補の数を答えに加算
    ans += d[sm%M]
    # 今回のsm%Mはこの後左端候補として使うので+1
    d[sm%M] += 1
print(ans)
### BUGGY CODE ###

N = int(input())

x = list(map(int,input().split()))
sort_x = x.copy()
sort_x.sort()

cnt = 0
center_num = (N-1) // 2

for l in x:
    if sort_x.index(l) <= center_num:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])

### FIXED CODE ###

import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])
### BUGGY CODE ###

n = int(input())

result = []

def cal(n, result):
    result.append(i)
    result = result[::-1]
    return result

for i in input().split():
    result = cal(i, result)

print(" ".join(result))

### FIXED CODE ###

from collections import deque

n = int(input())

result = deque()
index = 0

if n % 2 == 0:
    for i in input().split():
        if index % 2 == 1:
            result.appendleft(i)
            index += 1
        else:
            result.append(i)
            index += 1
else:
    for i in input().split():
        if index % 2 == 1:
            result.append(i)
            index += 1
        else:
            result.appendleft(i)
            index += 1

print(" ".join(result))
### BUGGY CODE ###

# coding: utf-8
# Your code here!
moj = str(input())
moj_list =list(moj)
kai = int(input())
han = 0
for i in range(kai):
    kyu = []
    kyu = list(input().split(" "))
    if kyu[0] == "1":
        if han == 0:
            han = 1
        elif han == 1:
            han = 0
    elif kyu[0] == "2":
        if han ==0:
            if kyu[1] == "1":
                moj = kyu[2] + moj
            elif kyu[1] == "2":
                moj = moj + kyu[2]
        if han ==1:
            if kyu[1] == "1":
                moj = moj + kyu[2]
            elif kyu[1] == "2":
                moj = kyu[2] + moj        
if han == 1:
    moj = moj[::-1]
    
print(moj)

### FIXED CODE ###

# coding: utf-8
# Your code here!
moj = str(input())
kai = int(input())
han = 0
omo = ''
ura = ''
for i in range(kai):
    kyu = []
    kyu = list(input().split(" "))
    if kyu[0] == "1":
        if han == 0:
            han = 1
        elif han == 1:
            han = 0
    elif kyu[0] == "2":
        if han == 0:
            if kyu[1] == "1":
                ura += kyu[2]
            elif kyu[1] == "2":
                omo += kyu[2]
        if han == 1:
            if kyu[1] == "1":
                omo += kyu[2]
            elif kyu[1] == "2":
                ura += kyu[2]
if han == 1:
    moj = moj[::-1]
    omo = omo[::-1]
    moj = omo + moj + ura
elif han == 0:
    ura = ura[::-1]
    moj = ura + moj + omo
    
print(moj)
### BUGGY CODE ###

#D - Friends
N,M = map(int,input().split())
par = [i for i in range(N+1)]
 
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
 
def size(x):
    return par.count(find(x))
 
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    if par[x] > par[y]:
        x,y = y,x
    #par[x] += par[y]
    par[y] = x
#    par[x] = y
 
#print(par)
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    unite(a,b)
#    print(par)
 
group_count = 0
 
for i in range(N):
    group_count = max(group_count,size(i))
 
# 出力
print(group_count)


### FIXED CODE ###

#D - Friends
N,M = map(int,input().split())
par = [i for i in range(N)]
rank = [1] * (N)

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]

def size(x):
    return par.count(find(x))

def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y : return 0
    if par[x] > par[y]:
        x,y = y,x
    par[y] = x
#    par[x] = x
    if par[x] == par[y]:
        rank[x] += rank[y]
#        rank[y] += rank[x]
#print(par)
#print(rank)
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    unite(a,b)
#    print(par)
#    print(rank)
group_count = 0

group_count = max(rank)

# 出力
print(group_count)
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False

if ok == True or ans == 0:
    print(ans)
else:
    print(-1)

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(n):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
BC = []
for i in range(M):
    a = list(map(int,input().split()))
    BC.append(a)
BC = sorted(BC, key = lambda x:x[1],reverse = True)
maxc = max([i[1] for i in BC])
Asub = [i for i in A if i <= maxc+1]
for b,c in BC:
    count = b
    Asub = sorted(Asub)
    for i in range(len(Asub)):
        if Asub[i] < c and count != 0:
            Asub[i] = c
            count -= 1
        else:
            break

print(sum(Asub) + sum(A[len(Asub):]))

### FIXED CODE ###

def main():
    N,M = map(int,input().split())
    A = sorted(list(map(int,input().split())))
    BC = []
    for i in range(M):
        a = list(map(int,input().split()))
        BC.append(a)
    BC = sorted(BC, key = lambda x:x[1],reverse = True)
    sum = 0
    for b,c in BC:
        if sum + b <= N:
            sum += b
            for i in range(b):
                A.append(c)
        else:
            sub = N - sum
            for i in range(sub):
                A.append(c)
    A = sorted(A,reverse = True)
    suma = 0
    for i in range(N):
        suma += A[i]
    print(suma)    

main()
### BUGGY CODE ###

S = input()

ans = 0
for i in range(len(S)):
    for j in range(i + 4, len(S) + 1):
        n = int(S[i:j])
        ans += n % 2019 == 0

print(ans)


### FIXED CODE ###

S = input()
S = list(map(int, S))

t = 1
r = 0
d = [0] * 2019
d[0] += 1
for n in reversed(S):
    r = (r + n * t) % 2019
    t = t * 10 % 2019
    d[r] += 1

ans = 0
for m in d:
    ans += m * (m-1) // 2

print(ans)
### BUGGY CODE ###

h,n = map(int,input().split())
dp = [[float('inf')]*(h+1) for i in range(n+1)]
dp[0][0] = 0

for i in range(1,n+1):
    a,b = map(int,input().split())
    for j in range(h+1):
        if j-a<0:
            dp[i][j] = min(dp[i][j],b,dp[i-1][j])
        else:
            dp[i][j] = min(dp[i][j-a]+b,dp[i-1][j])

print(dp[n][h]) 

### FIXED CODE ###

h,n = map(int,input().split())

ab = [list(map(int,input().split())) for i in range(n)]
ma = max(a for a,b in ab)


dp = [10**10]*(h+ma+1)
dp[0] = 0

for i in range(1,h+ma+1):
    dp[i] = min(dp[i-a]+b for a,b in ab)

print(min(dp[h:]))
### BUGGY CODE ###

s = input()
K = int(input())
ans_lis = []


def check(s, kosu):
    lis_kosu = []
    for i in range(len(s) - kosu + 1):
        lis_kosu.append(s[i:i + kosu])
    return list(set(lis_kosu))


for i in range(1, len(s) + 1):
    ans_lis += check(s, i)


print(sorted(ans_lis)[K - 1])


### FIXED CODE ###

s = input()
K = int(input())
ans_lis = []
s_length = len(s)
lis = [[] for i in range(26)]

for i in range(s_length):
    lis[ord(s[i]) - ord('a')].append(i)


for i in range(26):
    k = 1
    while k <= K:
        for j in lis[i]:
            ans_lis.append(s[j:j + k])
        k += 1
        ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()
### BUGGY CODE ###

N = int(input())

nums = [float(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = int(num * (10**9))
    
    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
        
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0
for i in range(N):
    for j in range(i+1,N):
        two_sum = two_fives[i][0] + two_fives[j][0]
        five_sum = two_fives[i][1] + two_fives[j][1]
        if two_sum >= 18 and five_sum >= 18:
            ok_count += 1

print(ok_count)



### FIXED CODE ###

import numpy as np
from decimal import Decimal

N = int(input())

nums = [Decimal(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = int(num * (10**9))
    
    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0

two_five_exists = np.zeros((19,19), dtype=int)

for i in range(N):    
    two_count, five_count = two_fives[i]
    two_count = min(18, two_count)
    five_count = min(18, five_count)
    ok_count += two_five_exists[two_count, five_count]

    two_pair = 18 - two_count
    five_pair = 18 - five_count
    two_five_exists[two_pair:, five_pair:] += 1

print(ok_count)
### BUGGY CODE ###


def main():
    q, h, s, d = map(int, input().split())
    n = int(input()) * 100
    h = min(h, 2*q)
    s = min(s, 2*h)
    d = min(d, 2*s)
    ans = 0
    vals = [(200, d), (100, s), (50, h), (25, q)]
    while n > 0:
        for m, val in vals:
            if m <= n:
                n -= m
                ans += val
                break
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###


def main():
    q, h, s, d = map(int, input().split())
    n = int(input()) * 100
    h = min(h, 2*q)
    s = min(s, 2*h)
    d = min(d, 2*s)
    ans = 0
    vals = [(200, d), (100, s), (50, h), (25, q)]
    for m, val in vals:
        c = n // m
        n -= m * c
        ans += val*c
    print(int(ans))


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

L, R = map(int, input().split())
min = 2019

for i in range(L, R+1):
	if i % 2019 == 0:
		min = 0
	if min == 0:
		break
	for j in range(i+1, R+1):
		num = i * j % 2019
		if j > i and num < min:
			min = num

print(min)

### FIXED CODE ###

L, R = map(int, input().split())
min = 2019

if R -L >= 2019:
	min = 0
else:

	for i in range(L, R+1):
		for j in range(i+1, R+1):
			num = i * j % 2019
			if j > i and num < min:
				min = num

print(min)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
for i in range(n):
  tmp = max(a)
  if tmp == a[i]:
    a[i] = -1
    print(max(a))
    a[i] = tmp
  else:
    print(tmp)



"""
for i in range(n):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
tmpa = a[:] 
tmpa.sort()

for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """
### BUGGY CODE ###

import numpy as np
N = int(input())
Ls = np.sort(list(map(int, input().split())))
count = 0
for i in range(N-2):
    a = Ls[i]
    for k in range(N-i-2):
        ab = a + Ls[i+1:N-1-k]
        c = Ls[N-k-1]
        count = count + np.count_nonzero(ab - c > 0)
print(count)

### FIXED CODE ###

import bisect
n = int(input())
lis = sorted(list(map(int,input().split())))
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_left(lis,lis[i]+lis[j])
        count += index-1-j
print(count)
### BUGGY CODE ###

n,m = map(int,input().split())
path = [[]for i in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1,input().split())
    path[a] += [b]
    path[b] += [a]
ans = [-1 for i in range(n)]
count = [[] for i in range(n)]
c=1
ans[0] = -2

for i in path[0]:
    ans[i] = 1
    count[1] += [i]
while -1 in ans:
    for i in count[c]:
        for j in path[i]:
            if ans[j]==-1:
                ans[j]=i+1
                count[c]+=[i]
        c+=1
print("Yes")
for i in range(1,n):
    print(ans[i])

### FIXED CODE ###

n,m = map(int,input().split())
path = [[]for i in range(n)]
for i in range(m):
    a,b = map(lambda x: int(x)-1,input().split())
    path[a] += [b]
    path[b] += [a]
ans = [-1 for i in range(n)]
depth = [[] for i in range(n)]
visited = [False for i in range(n)]
d=0
ans[0] = -2
depth[0]+=[0]
visited[0]=True
while False in visited:
    for i in depth[d]:
        for j in path[i]:
            if not visited[j]:
                ans[j] = i+1
                depth[d+1] += [j]
                visited[j] = True
    d += 1
print("Yes")
for i in range(1,n):
    print(ans[i])
### BUGGY CODE ###

from numpy.linalg import solve

N = int(input())
A = list(int(x) for x in input().split())
 
left = []

for i in range(N):
    num = []
    for j in range(N):
        if j == i or j == (i + 1):
            num.append(1)
        else:
            num.append(0)
        if i == N - 1:
            num[0] = 1
        
    left.append(num)

#print(left)

right = list(x * 2 for x in A)
#print (solve(left, right))

answer = ""
for a in solve(left, right):
    answer += str(int(a))
    answer += " "

print(answer)

### FIXED CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

N = int(input())
a_ = list(int(x) for x in input().split())
X_ = [0 for _ in range(N)]

X_sum = sum(a_)
logging.info("sum = " + str(X_sum))

X_[0] = X_sum - 2 * sum(a_[1::2])
logging.info("X_1 = " + str(X_[0]))

for i in range(1, N):
    X_[i] = 2 * a_[i - 1] - X_[i - 1]

answer = ""
for i in X_:
    answer += str(i)
    answer += " "

print(answer)
### BUGGY CODE ###

N= int(input())
li = [list(input()) for i in range(N)]

ans= 0
for i in range (N):
  li[i].sort()
  
for i in range(N-1):
  for j in range(i+1,N):
    if li[i] == li[j]:
      ans+=1
    else: continue
      
print(ans)

### FIXED CODE ###


def inp():
  return list(input())

N = int(input())
res = {}

for i in range(N):
  s = str(sorted(inp()))
  
  if s in res:
    res[s] += 1
  else:
    res[s] = 1
    

ans = 0
for num in res.values():
  ans += num*(num-1)/2
  
print(int(ans))
### BUGGY CODE ###

R,G,B,N=list(map(int,input().split()))
ans=[]
if 1<=R<=3000 and 1<=G<=3000 and 1<=B<=3000 and 1<=N<=3000:
	limR=N//R
	for r in range(limR+1)[::-1]:
		zanGB=N-r*R
		limG=zanGB//G
		for g in range(limG+1):
			zanB=zanGB-g*G
			if zanB%B==0:
				b=zanB//B
				ans.append([r,g,b])
print(len(ans))


### FIXED CODE ###

R,G,B,N=list(map(int,input().split()))
ans=0
if 1<=R<=3000 and 1<=G<=3000 and 1<=B<=3000 and 1<=N<=3000:
	limR=N//R
	for r in range(limR+1)[::-1]:
		zanGB=N-r*R
		limG=zanGB//G
		for g in range(limG+1):
			zanB=zanGB-g*G
			if zanB%B==0:
				b=zanB//B
				ans+=1
print(ans)
### BUGGY CODE ###

import sys
x,y = map(int, input().split())
temp = x
if x == y:
    print(-1)
    sys.exit()
while True:
    temp += x
    if temp % y != 0:
        print(temp)
        sys.exit()
    elif temp > pow(10, 18):
        print(-1)
        sys.exit()

### FIXED CODE ###

import sys
def gcd(a, b):
        while b:
                a, b = b, a % b
        return a
def lcm(a, b):
    return a * b // gcd (a, b)

x,y = map(int, input().split())
temp = x
if x == y:
    print(-1)
    sys.exit()
while True:
    temp += x
    if temp % y != 0:
        print(temp)
        sys.exit()
    elif temp > lcm(x, y):
        print(-1)
        sys.exit()