Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02588 (python)

Fixed submission:
def five(x):
    cnt1 = 0
    while x%5==0:
        cnt1+= 1
        x = x//5
    cnt2 = 0
    while x%2==0:
        cnt2+= 1
        x = x//2
    return (min(cnt1,18), min(cnt2,18))

N = int(input())

F = []
for i in range(N):
    A = float(input())
    A = round(A*(10**9))
    F.append(five(A))

F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*19
k = 0
for i in range(N-1):
    if N-1-j < i:
        dp[min(F[i][1], 18)] -= 1
        # print(i, N - j - 1, dp)
    while N-1-j> i and F[i][0]+F[N-1-j][0] >= 18:
        dp[min(F[N-1-j][1],18)] += 1
        # print(i, N - j - 1, dp)
        j += 1
    k = sum(dp[:18-F[i][1]])
    temp += min(j, N-i-1) - k
    # print(j, N-i-1, k, temp)

print(temp)

"""
5
1
1
1
1
1
"""

Buggy submission (verdict: Runtime Error):
class cumsum2D:
    def __init__(self, data):
        self.N = len(data)
        self.M= len(data[0])
        self.cum = [[0] * (self.M + 1) for _ in range(self.N + 1)]
        for i in range(self.N):
            for j in range(self.M):
                self.cum[i + 1][j + 1] = self.cum[i][j + 1] + self.cum[i + 1][j] - self.cum[i][j] + data[i][j]

    def get(self,x1,y1,x2,y2):
        """
        長方形の領域 [x1,x2)*[y1,y2) の範囲内にインプットされた数字の和を取る
        """
        return self.cum[x2][y2] - self.cum[x1][y2] - self.cum[x2][y1] + self.cum[x1][y1]

def five(x):
    cnt1 = 0
    while x%5==0:
        cnt1+= 1
        x = x//5
    cnt2 = 0
    while x%2==0:
        cnt2+= 1
        x = x//2
    return (min(cnt1,18), min(cnt2,18))

def digit_lift(S, l):
    if '.' in S:
        a, b = S.split('.')
        n = int(a + b) * 10 ** (l - len(b))
    else:
        n = int(S) * 10 ** l
    return n

data = [[0]*18 for _ in range(18)]

N = int(input())
Q = set()
for _ in range(N):
    A = digit_lift(input().rstrip(),9)
    x, y = five(A)
    data[x][y] += 1
    Q.add((x,y))

cum = cumsum2D(data)
res = 0
for x, y in Q:
    res += cum.get(18-x,18-y,-1,-1)*data[x][y]
print((res-2*data[9][9])//2)
Problem p02609 (python)

Fixed submission:
def popcnt(n):
    return bin(n).count("1")

def f(n):
    cnt = 0
    while n>0:
        n = n%popcnt(n)
        cnt += 1
    return cnt

def solve(X):
    Y = int(X, 2)
    c = X.count("1")
    m, p = c-1, c+1
    Ym, Yp = Y%m if m else -1, Y%p
    for i in range(N):
        if X[i] == "1":
            Y = (Ym - pow(2,N-i-1,m))%m if Ym!=-1 else -1
        else:
            Y = (Yp + pow(2,N-i-1,p))%p
        print(f(Y) + 1 if Y!=-1 else 0)

N = int(input())
solve(input())

Buggy submission (verdict: Runtime Error):
def popcnt(n):
    return bin(n).count("1")

def f(n):
    cnt = 0
    while n>0:
        n = n%popcnt(n)
        cnt += 1
    return cnt

def solve(X):
    Y = int(X, 2)
    c = X.count("1")
    if c == 0:
        return 0
    m, p = c-1, c+1
    Ym, Yp = Y%m, Y%p
    for i in range(N):
        if X[i] == "1":
            Y = (Ym - pow(2,N-i-1,m))%m
        else:
            Y = (Yp + pow(2,N-i-1,p))%p
        print(f(Y) + 1)

N = int(input())
solve(input())

Buggy submission (verdict: Runtime Error):


def popcnt(n):
    return bin(n).count("1")

def f(n):
    k = n
    cnt = 0
    while k>0:
        k = k%popcnt(k)
        cnt+= 1
    return cnt

def solve(X):
    for i in reversed(range(N)):
        if [N-1-i] == 0:
            print(0)
        else:
            K = X ^ (1 << i)
            K2 = K%P[N-1-i]
            print(f(K2) + 1)




N = int(input())
X = input()
X = X.zfill(N)
count_1 = X.count("1")

P = [0]*N
for i in range(N):
    if X[i] == "1":
        P[i] = count_1 - 1
    else:
        P[i] = count_1 + 1
Y = int(X,2)

solve(Y)

Buggy submission (verdict: Runtime Error):


def popcnt(n):
    return bin(n).count("1")

def f(n):
    k = n
    cnt = 0
    while k>0:
        k = k%popcnt(k)
        cnt+= 1
    return cnt

def solve(X):
    for i in reversed(range(N)):
        K = X ^ (1 << i)
        K2 = K%P[N-1-i]
        print(f(K2) + 1)




N = int(input())
X = input()
X = X.zfill(N)
count_1 = X.count("1")

P = [0]*N
for i in range(N):
    if X[i] == "1":
        P[i] = count_1 - 1
    else:
        P[i] = count_1 + 1
Y = int(X,2)

solve(Y)
Problem p02642 (python)

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())

    A = list(map(int, input().split()))
    A. sort()
    Nmax = A[-1] + 1

    prime = [0]*Nmax
    for i in range(N):
        if prime[A[i]] == 0:
            prime[A[i]] = 1
        else:
            prime[A[i]] = -1

    for a in A:
        if prime[a] != 0:
            for q in range(a*2, Nmax, a):
                prime[q] = 0

    res = 0
    for a in prime:
        if a == 1:
            res += 1

    print(res)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N = int(input())
Nmax = 2*(10**5)+1

A = list(map(int, input().split()))
A. sort()

prime = [0]*Nmax
for i in range(N):
    if prime[A[i]] == 0:
        prime[A[i]] = 1
    else:
        prime[A[i]] = -1

for a in A:
    if prime[a] == 1:
        for q in range(a*2, Nmax, a):
            prime[q] = 0



print(sum(a for a in prime if a == 1))
Problem p02660 (python)

Fixed submission:
import math
import collections

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if n == 1:
    print(0)
    exit()
else:
    c = collections.Counter(prime_factorize(n))

res = 0
for x, y in c.items():
    num = int( (-1 + (1 +8*y)**(0.5))/2 )
    res += num

print(res)

Buggy submission (verdict: Runtime Error):
import math
import collections

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if n == 1:
    print(0)
else:
    c = collections.Counter(prime_factorize(n))

res = 0
for x, y in c.items():
    num = int( (-1 + (1 +8*y)**(0.5))/2 )
    res += num

print(res)
Problem p02733 (python)

Fixed submission:
"""

制約の小ささから見て全探索

"""

from itertools import product, accumulate
from bisect import *
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
S = []
T = []
for i in range(H):
    S.append(list(map(int, input().strip())))
    T.append(list(accumulate([0] + S[-1])))

cnt_list = []
for a in product((0,1),repeat=H):
    past_a = a[0]
    T2 = [[0]*(W+1)]
    for i in range(H):
        if a[i] == past_a:
            for j, t in enumerate(T[i]):
                T2[-1][j] += t
        else:
            T2.append(T[i].copy())
        past_a = a[i]
    cnt = len(T2) - 1
    l = 0
    flg = False
    while True:
        temp = []
        for s in T2:
            temp.append(bisect_right(s[l+1:], K + s[l]) + l)
        if min(temp) == 0:
            flg = True
            break
        else:
            l = min(temp)
        if l >= W:
            break
        else:
            cnt += 1
    if not flg:
        cnt_list.append(cnt)

print(min(cnt_list))

Buggy submission (verdict: Runtime Error):
"""

制約の小ささから見て全探索

"""

from itertools import product, accumulate
from bisect import *
import sys
input = sys.stdin.readline

H, W, K = map(int, input().split())
S = []
T = []
for i in range(H):
    S.append(list(map(int, input().strip())))
    T.append(list(accumulate([0] + S[-1])))

cnt_list = []
for a in product((0,1),repeat=H):
    past_a = a[0]
    T2 = [[0]*(W+1)]
    for i in range(H):
        if a[i] == past_a:
            for j, t in enumerate(T[i]):
                T2[-1][j] += t
        else:
            T2.append(T[i])
        past_a = a[i]
    cnt = len(T2) - 1
    l = 0
    flg = False
    while True:
        temp = []
        for s in T2:
            temp.append(bisect_right(s[l+1:], K + s[l]) + l)
        if min(temp) == 0:
            flg = True
            break
        else:
            l = min(temp)
        if l >= W:
            break
        else:
            cnt += 1
    if not flg:
        cnt_list.append(cnt)

print(min(cnt_list))
Problem p02787 (python)

Fixed submission:
def knapsack_weight(single=True):
    """
    重さが小さい時のナップサックDP
    :param single: True = 重複なし
    """
    """ dp[weight <= W] = 重さを固定した時の最小価値 """
    weight_max = max(weight_list)
    price_max = max(price_list)
    W2 = W + weight_max
    dp_max = float("inf")  # 総和価値の最大値
    dp = [dp_max] * W2
    dp[0] = 0               # 重さ 0 の時は価値 0

    for item in range(N):
        if single:
            S = range(W2, weight_list[item] - 1, -1)
        else:
            S = range(weight_list[item], W2)
        for weight in S:
            dp[weight] = min2(dp[weight], dp[weight - weight_list[item]] + price_list[item])
    return min(dp[w] for w in range(W, W2))

#######################################################################################################
import sys
input = sys.stdin.readline


def max2(x, y):
    """ pythonの組み込み関数 max は2変数に対しては遅い！！ """
    if x > y:
        return x
    else:
        return y

def min2(x, y):
    """ pythonの組み込み関数 min は2変数に対しては遅い！！ """
    if x < y:
        return x
    else:
        return y


W, N = map(int, input().split())                                # N: 品物の種類 W: 重量制限

price_list = []
weight_list = []
for _ in range(N):
    """ price と weight が逆転して入力されている場合有り """
    weight, price = map(int, input().split())
    price_list.append(price)
    weight_list.append(weight)


print(knapsack_weight(single=False))


############################################################################################

Buggy submission (verdict: Runtime Error):
def knapsack_price(single=True):
    """
    重さが小さい時のナップサックDP
    :param single: True = 重複なし
    """
    """ dp[price <= V] = 価値を固定した時の最大重量 """
    V = 10**6
    dp_max = 0
    dp = [dp_max] * (V + 1)
    dp[0] = 0   # 境界条件：　価値0 の時は重さは0

    for item in range(N):
        if single:
            S = range(V, price_list[item]-1, -1)
        else:
            S = range(price_list[item], V + 1)
        for price in S:
            dp[price] = max2(dp[price], dp[price - price_list[item]] + weight_list[item])
    return min(price for price in range(V+1) if dp[price] >= W)


#######################################################################################################
import sys
input = sys.stdin.readline


def max2(x, y):
    """ pythonの組み込み関数 max は2変数に対しては遅い！！ """
    if x > y:
        return x
    else:
        return y

def min2(x, y):
    """ pythonの組み込み関数 min は2変数に対しては遅い！！ """
    if x < y:
        return x
    else:
        return y


W, N = map(int, input().split())                                # N: 品物の種類 W: 重量制限

price_list = []
weight_list = []
for _ in range(N):
    """ price と weight が逆転して入力されている場合有り """
    weight, price = map(int, input().split())
    price_list.append(price)
    weight_list.append(weight)


print(knapsack_price(single=False))


############################################################################################
Problem p02788 (python)

Fixed submission:
from bisect import *

N, D, A = map(int, input().split())

data = []
for _ in range(N):
    x, h = map(int, input().split())
    data.append((x,h))
data.sort()

X = []
H = []
for x, h in data:
    X.append(x)
    H.append(h)

Imos = [0]*(N+1)
cnt = 0
damage = 0
res = 0
for i in range(N):
    damage -= Imos[i]*A
    h = H[i] - damage
    x = X[i]
    if h > 0:
        cnt = h//A + (h%A!=0)
        p = min(bisect_right(X, x+2*D)-1, N-1)
        Imos[p+1] += cnt
        damage = damage + cnt * A
        res += cnt
print(res)

Buggy submission (verdict: Runtime Error):
from bisect import *

N, D, A = map(int, input().split())
X = [0]
H = []
for _ in range(N):
    x, h = map(int, input().split())
    X.append(X[-1] + x)
    H.append(h)

Imos = [0]*N
cnt = 0
damage = 0
res = 0
for i in range(N):
    h = H[i] - damage
    x = X[i+1]
    if h > 0:
        cnt = h//A + (h%A!=0)
        p = bisect_left(X, x+2*D) - 1
        Imos[p] += cnt
        damage = damage - Imos[i]*A + cnt * A
        res += cnt
print(res)
Problem p02844 (python)

Fixed submission:
from itertools import product

N = int(input())
S = input()
S = [int(s) for s in S]


res = 0
for q in product(range(10), repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                res += 1
                break
            else:
                i+=1
print (res)

Buggy submission (verdict: Runtime Error):

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

S = [int(s) for s in S]


res = 0
for q in product(range(10), repeat=3):
    i = 0
    for s in S:
        if s==q[i]:
            if i==2:
                res += 1
                break
            else:
                i+=1
print (res)
Problem p02937 (python)

Fixed submission:
from bisect import *
from collections import defaultdict
import sys
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()
L = len(S)

dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)


s0 = -1
cnt = 0
for t in T:
    if not dic[t]:
        print(-1)
        exit()
    p = bisect_right(dic[t],s0)
    if p >= len(dic[t]):
        cnt += 1
        s0 = min(dic[t])
    else:
        s0 = dic[t][p]

print(L*cnt+s0 +1)

Buggy submission (verdict: Runtime Error):
from bisect import *
from collections import defaultdict
import sys
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()
L = len(S)

dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)


s0 = -1
cnt = 0
for t in T:
    if not dic[t]:
        print(-1)
        exit()
    p = bisect_right(dic[t],s0)
    if p >= len(dic[t]):
        cnt += 1
        s0 = min(dic[t])
    else:
        s0 = dic[t][bisect_right(dic[t], p)]

print(L*cnt+s0 +1)
Problem p02958 (python)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
p0 = 0
p1 = P[0]
temp = []
for i, p in enumerate(P[1:]):
    if p >= p1:
        p0 = p1
        p1 = p
        continue
    else:
        temp.append(i)
        p1 = p

if len(temp) == 2:
    P[temp[0]], P[temp[1]+1] = P[temp[1]+1], P[temp[0]]

    p0 = 0
    p1 = P[0]
    temp = []
    for i, p in enumerate(P[1:]):
        if p >= p1:
            p0 = p1
            p1 = p
            continue
        else:
            temp.append(i)
            p1 = p
    if len(temp) == 0:
        print("YES")
    else:
        print("NO")
elif len(temp)==0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
p0 = 0
p1 = P[0]
temp = []
for i, p in enumerate(P[1:]):
    if p >= p1:
        p0 = p1
        p1 = p
        continue
    else:
        temp.append(i)
        p1 = p

if len(temp) > 2:
    print("NO")
    exit()
if len(temp) == 0:
    print("YES")
    exit()

P[temp[0]], P[temp[1]+1] = P[temp[1]+1], P[temp[0]]

p0 = 0
p1 = P[0]
temp = []
for i, p in enumerate(P[1:]):
    if p >= p1:
        p0 = p1
        p1 = p
        continue
    else:
        temp.append(i)
        p1 = p

if len(temp) == 0:
    print("YES")
else:
    print("NO")
Problem p02982 (python)

Fixed submission:
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
data = [0]*16002
i = 1
while i**2<=16001:
    data[i**2]=1
    i += 1
res = 0
for a, b in combinations(X,2):
    temp = 0
    for x, y in zip(a, b):
        temp += (x-y)**2
    if data[temp]:
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
data = [0]*5002
i = 1
while i**2<=5001:
    data[i**2]=1
    i += 1
res = 0
for a, b in combinations(X,2):
    temp = 0
    for x, y in zip(a, b):
        temp += (x-y)**2
    if data[temp]:
        res += 1
print(res)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
data = [0]*4001
i = 1
while i**2<=4001:
    data[i**2]=1
    i += 1
res = 0
for a, b in combinations(X,2):
    temp = 0
    for x, y in zip(a, b):
        temp += (x-y)**2
    if data[temp]:
        res += 1
print(res)
Problem p03353 (python)

Fixed submission:
S = input().rstrip()
N = len(S)
K = int(input())
A = []
for i in range(N):
    A.append(S[i:])
A.sort()
B = set()
flg = False
for i in range(len(A)):
    for j in range(1,len(A[i])+1):
        B.add(A[i][:j])
        if len(B)==K:
            flg = True
            break
    if flg: break
B = list(B)
B.sort()
print(B[-1])

Buggy submission (verdict: Runtime Error):
S = input().rstrip()
N = len(S)
K = int(input())
A = set()
if N == 1:
    print(S)
    exit()
for i in range(N-1):
    A.add(S[i:])
A = list(A)
A.sort()
print(A)
cnt, i = 0, 0
while cnt + len(A[i]) < K:
    cnt += len(A[i])
    i += 1
print(A[i][:K-cnt])
Problem p03369 (python)

Fixed submission:
S = input().rstrip()
print(700 + S.count("o")*100)

Buggy submission (verdict: Runtime Error):
a, b, c, x, y = list(map(int, input().split()))
res = a * x + b * y
for i in range(1, max(x, y) + 1):
    res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
print(res)
Problem p03371 (python)

Fixed submission:
a, b, c, x, y = list(map(int, input().split()))
res = a * x + b * y
for i in range(1, max(x, y) + 1):
    res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
print(res)

Buggy submission (verdict: Runtime Error):
    a, b, c, x, y = list(map(int, input().split()))
    res = a * x + b * y
    for i in range(1, max(x, y) + 1):
        res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
    print(res)

Buggy submission (verdict: Runtime Error):
while(True):

    a, b, c, x, y = list(map(int, input().split()))
    res = a * x + b * y
    for i in range(1, max(x, y) + 1):
        res = min(res, a * max(x - i, 0) + b * max(y - i, 0) + 2 * c * i)
    print(res)
Problem p03498 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mi, ma = min(A), max(A)
print(2*N)
if abs(mi)<=ma:
    k = A.index(ma)
    print(k+1,1)
    print(k+1,1)
    for i in range(N-1):
        print(i+1,i+2)
        print(i+1,i+2)
else:
    k = A.index(mi)
    print(k+1,N)
    print(k+1,N)
    for i in reversed(range(N-1)):
        print(i+2,i+1)
        print(i+2,i+1)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
input = sys.stdin.readline
N = int(input())
A = [0] + list(map(int, input().split()))
P = [[] for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(N+1):
        for k in range(N+1):
            P[i].append((A[i]+A[j]+A[k],j,k))
B = [-float("inf")]
res = []
for i in range(1,N+1):
    P[i].sort(key=lambda x:x[0])
    tmp = [p for p, _, _ in P[i]]
    k = bisect_left(tmp,B[-1])
    B.append(P[i][k][0])
    b,c = P[i][k][1], P[i][k][2]
    if b: res.append((b,i))
    if c: res.append((c,i))
print(len(res))
for b, i in res:
    print(b,i)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import *
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
P = [[] for _ in range(N)]
Q = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        for k in range(N):
            P[i].append((A[i]+A[j]+A[k],j+1,k+1))
B = [-float("inf")]
print(2*N)
for i in range(N):
    P[i].sort(key=lambda x:x[0])
    tmp = [p for p, _, _ in P[i]]
    k = bisect_left(tmp,B[-1])
    B.append(P[i][k][0])
    b,c = P[i][k][1], P[i][k][2]
    print(b,i+1)
    print(c,i+1)
Problem p03525 (python)

Fixed submission:
from collections import Counter
import marshal
N = int(input())
D = Counter(list(map(int, input().split())))
P = [[0]]
for i in range(13):
    if D.get(i,0) == 0:
        continue
    if D.get(i,0) == 1:
        Q = marshal.loads(marshal.dumps(P))
        for p in P:
            p.append(i)
        for q in Q:
            q.append(24-i)
        P += Q
    if D.get(i,0) == 2:
        for p in P:
            p.append(i)
            p.append(24-i)
    if D.get(i,0) >= 3:
        print(0)
        exit()
res = 0
for p in P:
    m = float("inf")
    for i in range(len(p)):
        for j in range(i+1,len(p)):
            if abs(p[i]-p[j])>12:
                m = min(24-abs(p[i]-p[j]),m)
            else:
                m = min(abs(p[i]-p[j]),m)
    res = max(m,res)
print(res)

Buggy submission (verdict: Runtime Error):
from itertools import product
from collections import Counter
N=int(input())
D=list(map(int, input().split()))
print(list(sorted(D)))
res=0
c=Counter(D).values()
if c[0]>0 or max(c)>2:print(0);exit()
if N>13:print(1);exit()
for b in product(*((d,24-d) for d in D)):
    d0, m= 0,1<<30
    for d in sorted(b):
        m=min((d-d0),24-(d-d0),m)
        d0=d
    m=min(d0,24-d0,m)
    res = max(res,m)
print(res)
Problem p03666 (python)

Fixed submission:
from bisect import *
N, A, B, C, D = map(int, input().split())
P = [A + (N-1-i)*D - C*i for i in reversed(range(N))]
Q = [A + (N-1-i)*C - D*i for i in reversed(range(N))]
j = bisect_left(P,B)
if j < N and B >= Q[j]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
from bisect import *
N, A, B, C, D = map(int, input().split())
P = [A + (N-1-i)*D - C*i for i in reversed(range(N))]
Q = [A + (N-1-i)*C - D*i for i in reversed(range(N))]
j = bisect_left(P,B)
if B >= Q[j]:
    print("YES")
else:
    print("NO")
Problem p02957 (python)

Fixed submission:
A, B = map(int, input().split())
C = A + B
if C % 2 == 0:
    print(C // 2)
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    ll c = A + B;
    if (c % 2 == 1)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << c / 2 << endl;
    return 0;
}