Problem:


Score: 100 points

Problem Statement

We have two distinct integers A and B.

Print the integer K such that |A - K| = |B - K|.

If such an integer does not exist, print IMPOSSIBLE instead.

Constraints

All values in input are integers.

0 \leq A,\ B \leq 10^9

A and B are distinct.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the integer K satisfying the condition.

If such an integer does not exist, print IMPOSSIBLE instead.

Sample Input 1

2 16

Sample Output 1

9

|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.

Sample Input 2

0 3

Sample Output 2

IMPOSSIBLE

No integer satisfies the condition.

Sample Input 3

998244353 99824435

Sample Output 3

549034394



Sample input:
2 16


Sample output:
9

Submission status: Runtime Error

Solution code:
a,b=map(int,input().splot())
if a%2==b%2:
  print((int)((a+b)/2))
else:
  print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:

from pprint import pprint
from collections import defaultdict
dp = {5:1}
mapper = {0: 0, 1: 9, 2: 5, 3: 1, 4: 10, 5: 6, 6: 2, 7: 11, 8: 7, 9: 3}
wildcard_mapper = {0: [0, 9, 5, 1, 10, 6, 2, 11, 7, 3],
             1: [4, 0, 9, 5, 1, 10, 6, 2, 11, 7],
             2: [8, 4, 0, 9, 5, 1, 10, 6, 2, 11],
             3: [12, 8, 4, 0, 9, 5, 1, 10, 6, 2],
             4: [3, 12, 8, 4, 0, 9, 5, 1, 10, 6],
             5: [7, 3, 12, 8, 4, 0, 9, 5, 1, 10],
             6: [11, 7, 3, 12, 8, 4, 0, 9, 5, 1],
             7: [2, 11, 7, 3, 12, 8, 4, 0, 9, 5],
             8: [6, 2, 11, 7, 3, 12, 8, 4, 0, 9],
             9: [10, 6, 2, 11, 7, 3, 12, 8, 4, 0],
             10: [1, 10, 6, 2, 11, 7, 3, 12, 8, 4],
             11: [5, 1, 10, 6, 2, 11, 7, 3, 12, 8],
             12: [9, 5, 1, 10, 6, 2, 11, 7, 3, 12]}
cache_mapper = {(0, 0): 0,
 (0, 1): 9,
 (0, 2): 5,
 (0, 3): 1,
 (0, 4): 10,
 (0, 5): 6,
 (0, 6): 2,
 (0, 7): 11,
 (0, 8): 7,
 (0, 9): 3,
 (1, 0): 4,
 (1, 1): 0,
 (1, 2): 9,
 (1, 3): 5,
 (1, 4): 1,
 (1, 5): 10,
 (1, 6): 6,
 (1, 7): 2,
 (1, 8): 11,
 (1, 9): 7,
 (2, 0): 8,
 (2, 1): 4,
 (2, 2): 0,
 (2, 3): 9,
 (2, 4): 5,
 (2, 5): 1,
 (2, 6): 10,
 (2, 7): 6,
 (2, 8): 2,
 (2, 9): 11,
 (3, 0): 12,
 (3, 1): 8,
 (3, 2): 4,
 (3, 3): 0,
 (3, 4): 9,
 (3, 5): 5,
 (3, 6): 1,
 (3, 7): 10,
 (3, 8): 6,
 (3, 9): 2,
 (4, 0): 3,
 (4, 1): 12,
 (4, 2): 8,
 (4, 3): 4,
 (4, 4): 0,
 (4, 5): 9,
 (4, 6): 5,
 (4, 7): 1,
 (4, 8): 10,
 (4, 9): 6,
 (5, 0): 7,
 (5, 1): 3,
 (5, 2): 12,
 (5, 3): 8,
 (5, 4): 4,
 (5, 5): 0,
 (5, 6): 9,
 (5, 7): 5,
 (5, 8): 1,
 (5, 9): 10,
 (6, 0): 11,
 (6, 1): 7,
 (6, 2): 3,
 (6, 3): 12,
 (6, 4): 8,
 (6, 5): 4,
 (6, 6): 0,
 (6, 7): 9,
 (6, 8): 5,
 (6, 9): 1,
 (7, 0): 2,
 (7, 1): 11,
 (7, 2): 7,
 (7, 3): 3,
 (7, 4): 12,
 (7, 5): 8,
 (7, 6): 4,
 (7, 7): 0,
 (7, 8): 9,
 (7, 9): 5,
 (8, 0): 6,
 (8, 1): 2,
 (8, 2): 11,
 (8, 3): 7,
 (8, 4): 3,
 (8, 5): 12,
 (8, 6): 8,
 (8, 7): 4,
 (8, 8): 0,
 (8, 9): 9,
 (9, 0): 10,
 (9, 1): 6,
 (9, 2): 2,
 (9, 3): 11,
 (9, 4): 7,
 (9, 5): 3,
 (9, 6): 12,
 (9, 7): 8,
 (9, 8): 4,
 (9, 9): 0,
 (10, 0): 1,
 (10, 1): 10,
 (10, 2): 6,
 (10, 3): 2,
 (10, 4): 11,
 (10, 5): 7,
 (10, 6): 3,
 (10, 7): 12,
 (10, 8): 8,
 (10, 9): 4,
 (11, 0): 5,
 (11, 1): 1,
 (11, 2): 10,
 (11, 3): 6,
 (11, 4): 2,
 (11, 5): 11,
 (11, 6): 7,
 (11, 7): 3,
 (11, 8): 12,
 (11, 9): 8,
 (12, 0): 9,
 (12, 1): 5,
 (12, 2): 1,
 (12, 3): 10,
 (12, 4): 6,
 (12, 5): 2,
 (12, 6): 11,
 (12, 7): 7,
 (12, 8): 3,
 (12, 9): 12}
n = input().rstrip("\n")
#n = "?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???"
rn = reversed(n)

m = 10 ** 9 + 7

for c in rn:
    new_dp = defaultdict(int)
    if c == "?":
        for used, count in dp.items():
            for next_used in wildcard_mapper[used]:
                new_dp[next_used] += count
                
    else:
        digit = int(c)
        for used, count in dp.items():
            next_used = cache_mapper[(used,digit)]
            new_dp[ next_used] += count
            
    dp = new_dp
    #for i in range(13):
    #    dp[i] %= m
print(dp[0] % m)

Submission status: Runtime Error

Solution code:
A,B = map(int,input().split())
 
K=(A+B)/2
 
def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
 
if is_integer_num(K)==False:
  print(IMPOSSIBLE)
else:
  print(K)

Submission status: Runtime Error

Solution code:
A=int(input())
B=int(input())

K=(A+B)/2

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

if is_integer_num(K)==False:
  print(IMPOSSIBLE)
else:
  print(K)

Submission status: Runtime Error

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
print(k)
if k < 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
A, B = int(input()), int(input())

# AとBの偶奇が一致する場合 存在する
# AとBの偶奇が一致しない場合 存在しない

if (A % 2 != B % 2):
    print("IMPOSSIBLE")
else:
    k = int((A + B) / 2)
    print(k)

Submission status: Runtime Error

Solution code:
A,B = list(map(int,input().split()))
ans = (A+B) %　2
if ans == 0:
  print((A+B)//2)
else :
  print("impossible")

Submission status: Runtime Error

Solution code:
s = input()

mod = 1000000007
length = len(s)
ans = list([0]*13 for i in range(length+1))
ans[0][0] = 1

for i in range(length):
    for j in range(13):
        x = j*10 % 13 - 1
        if s[i] == '?':
            for k in range(10):
                x = (x + 1) % 13
                ans[i+1][x] += ans[i][j]
        else:
            x = (x + int(s[i]) + 1) % 13
            ans[i+1][x] += ans[i][j]

print(ans[length][5] % mod)

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())

if (a + b) % 2 == 0:
    print((a+b)/2)
else:
    print(IMPOSSIBLE)

Submission status: Runtime Error

Solution code:
N = int(input()) 
s = list(map(int, input().split()))
A = 0
for i in range (N):
  if s[i] == i:
    continue
  else:
    A+=1
if A <= 2 or:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
if A == 0 or B == 0 or (A + B)%2 ==1:
	print(IMPOSSIBLE)
else:
  print(int((A + B)/2))

Submission status: Runtime Error

Solution code:
import random
r = random.randint(1,3)

if r == 1:
  # TLE
  import time
  time.sleep(5)
elif r == 2:
  # MLE
  x = '01234567'
  x *= (1 << 27)
else:
  # RE
  RE

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())

for k in range(max(A, B)):
  if abs(A - k) == abs(B - k):
    print(k)
    return
    
print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
a,b=map(input())
a=a+b
if (a)%2==0:
  print(a//2)
else:
  print('IMPOSSIBLE')

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
mod = 10**9+7
dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    if S[i] == '?':
        for num in range(10):
            for j in range(13):
                dp[i+1][(j*10+num)%13] += dp[i][j]
    else:
        num = int(S[i])
        for j in range(13):
            dp[i + 1][(j * 10 + num) % 13] += dp[i][j]

    for j in range(13):
        dp[i + 1][j] %= mod

print(dp[n][5])

Submission status: Runtime Error

Solution code:

A = input()
B = input()
A = int(A)
B = int(B)

if (A+B) % 2 == 0:
    print((A+B)//2)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
a,b = map(int, input().split())

if ((a%2 == 1)and(b%2==1)):
    c = (a+b)/2
    print(int(c))

if ((a%2==0)and(b%2==0)):
    c =(a+b)/2
    print(int(c))

if ((a%2==0)and(b%2==1)) or ((a%2==1)and(b%==0)):
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
N = int(input())
ps = list(map(int, input().split()))
 
count = 0
 
for p,n in zip(ps,range(N)):
    if p != n:
        count += 1
if count == 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:

A = input()
B = input()
A = int(A)
B = int(B)
K = (A+B) / 2
K = int(K)

if K % 2 == 0:
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:

A = input()
B = input()
A = int(A)
B = int(B)
K = (A+B) / 2

if K % 2 == 0:
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 29 14:29:48 2019

@author: re
"""

A = int(A)
B = int(B)


K = (A+B) / 2
K = int(K)

if abs(A-K) == abs(B-K):
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 29 14:29:48 2019

@author: re
"""

A = input()
B = input()
A = int(A)
B = int(B)


K = (A+B) / 2
K = int(K)

if abs(A-K) == abs(B-K):
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
a=sum(input().split());print(a%2*'IMPOSSIBLE'or a//2)

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split());print({a/2+b/2,"IMPOSSIBLE"}[(a+b)%2])

Submission status: Runtime Error

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
xs = [int(x) for x in stdin.readline().rstrip().split()]
ys = [int(x) for x in stdin.readline().rstrip().split()]

count = 0

for i in range(n):
   r = min(xs[i], ys[i])
   xs[i] -= r
   ys[i] -= r
   count += r
   r = min(xs[i+1], ys[i])
   xs[i+1] -= r
   count += r
   
print(count)

Submission status: Runtime Error

Solution code:
A, B = map(int, input())
print((A + B) // 2 if abs(A - B) % 2 == 0 else 'IMPOSSIBLE')

Submission status: Runtime Error

Solution code:
ba, bb = (int(x) for x in input().split())
m = a if a > b else b
for i in range(m+2):
    a = abs(a-i)
    b = abs(b-i)
    if a == b:
        print(i)
        break:
if i == m+1:
    print('IMPOSSIBLE')

Submission status: Runtime Error

Solution code:
ba, bb = (int(x) for x in int(input().split()))
m = a if a > b else b
for i in range(m+2):
    a = abs(a-i)
    b = abs(b-i)
    if a == b:
        print(i)
if i == m+1:
    print('IMPOSSIBLE')

Submission status: Runtime Error

Solution code:
S=input()
MOD=10**9+7
dp=[0]*13
dp[0]=1
for i in range(len(S)):
    new_dp=[0]*13
    s=S[-1-i]
    if s=="?":
        for j in range(10):
            rem=(j*10**i)%13
            for k in range(13):
                new_dp[(k+rem)%13]+=dp[k]
    else:
        rem=(int(s)*10**i)%13
        for k in range(13):
            new_dp[(k+rem)%13]+=dp[k]
    for l in range(13):
        new_dp[l]%=MOD
    dp=new_dp
print(dp[5])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
for i in range(n):
  if a[i]>=b[i]:
    c+=int(b[i])
  else:
    if (a[i]+a[i+1])>=b[i]:
      c+=int(b[i])
      a[i+1]=a[i]+a[i+1]-b[i]
    else:
      c+=int(a[i]+a[i+1])
print(c)

Submission status: Runtime Error

Solution code:
INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])

Submission status: Runtime Error

Solution code:
A,B=map(int,input().split())
if (A*B)%2==1:
  print(IMPOSSIBLE)
  else
  	print((A+B)/2)

Submission status: Runtime Error

Solution code:
a = input()
b = input()
c = max(a,b) - min(a,b)
d = min(a,b)+(c/2)
if c%2== 0:
  print(d)
else:
  print(d)

Submission status: Runtime Error

Solution code:
import copy

S = input()

dp = [0] * 13

dp[0] = 1

mod = 10 ** 9 + 7
mul = 1
for i in range(len(S)-1, -1, -1):
    # 二次元dpの代わり
    ndp = [0] * 13
    
    if S[i] == '?':
        for k in range(10):
            for j in range(13):
                # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
                # ただし、0-9までの値をその桁が取る可能性があるので、
                #　それぞれの場合全てを加算する
                ndp[(k * mul + j) % 13] += dp[j]
                ndp[(k * mul + j) % 13] %= mod
    else:
        k = int(S[i])
        for j in range(13):
            # 次の桁の余りが加わった時に、そこへ前のdp[j]の値を入れる
            ndp[(k * mul + j) % 13] += dp[j]
            ndp[(k * mul + j) % 13] %= mod

    mul *= 10
    mul %= 13
    dp = copy.deepcopy(ndp)

# 13で割って5で余るものを出力
print(dp[5])

Submission status: Runtime Error

Solution code:
import copy

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

N = 13
MOD = 1000000000 + 7
s = input()
dp = [0 for i in range(N)]
nextdp = [0 for i in range(N)]
dp[0] = 1
rs = reversed(s)

for i, si in enumerate(rs):
    nextdp = [0 for j in range(N)]

    for j in range(10):
        c = 0
        if si == "?":
            c = (j * 10 ** i) % N
        elif j == 0:
            c = (int(si) * 10 ** i) % N
        else:
            break

        for k in range(N):
            nextdp[(k + c) % N] += dp[k]
            nextdp[(k + c) % N] %= MOD

    dp = copy.copy(nextdp)

print(dp[5])

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import numpy as np

def main():
    S = input()
    
    lenS = len(S)
    N = 13
    DP = np.zeros(N, dtype=np.int64)
    DP[0] = 1
    
    mod = 10 ** 9 + 7
    mul = 1
    for i in reversed(range(lenS)):
        nextDP = np.zeros(N, dtype=np.int64)
        c = S[i]
        if c == '?':
            for k in range(10):
                for j in range(N):
                    nextDP[(k * mul + j) %N] += DP[j]
                    nextDP[(k * mul + j) %N] %= mod

        else:
            k = int(S[i])
            for j in range(N):
                nextDP[(k * mul + j) %N] += DP[j]
                nextDP[(k * mul + j) %N] %= mod

        mul *= 10
        mul %= N
        DP = nextDP

    return DP[5]

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

Submission status: Runtime Error

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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return -1
    return 1

f=0
for i in range(n):
    for j in range(n):
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
AB = int(input().split())

A = AB[0]
B = AB[1]

if A%2 == 0 and B%2 == 0:
  print((A+B)/2)
  
elif A%2 == 1 and B%2 ==1:
  print((A+B)/1)
  
else:
  print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
c = a + b
if c % 2 == 1:
    print('IMPOSSIBLE')
else:
    print(int(c / 2))

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
c = a + b
if c % 2:
    print('IMPOSSIBLE')
else:
    print(int(c / 2))

Submission status: Runtime Error

Solution code:
A = float(input())
B = float(input())
X = float(-(A+B)/2)

if X.is_integer():
    K = int(X)
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
X = float((A+B)/2)

if X.is_integer():
    K = int(X)
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
K = float((A+B)/2)

if K.is_integer():
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
K = float((A+B)/2)

if K.is_integer():
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
K = (A+B) /2

if isinstance(K, int):
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
import sys
a = []
for l in sys.stdin:
  a.append(int(l))
  
print(a)

Submission status: Runtime Error

Solution code:
import sympy
A = int(input())
B = int(input())
K = sympy.Symbol("K")
AK= abs(A-K)
BK= abs(B-K)

sympy.solve("AK-BK")
if isinstance(K, int):
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
sum += min(A[1],B[0]-min(A[0],B[0]))
for i in range(N-1):
    sum += min(A[i+1],B[i+1])
    sum += min(A[i+2],B[i+1]-min(A[i+1],B[i+1]))
print(sum)

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())

A = abs(a)
B = abs(b)

if isinstance((A-B) / 2, int):
    K = (A-B)/2
    print(K)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())

A = abs(a)
B = abs(b)

if isinstance((a-b) / 2, int):
    print((a-b)/2)
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
# OLE?
a = input()
b = input()

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
if (a[0]+a[1])%2==0:
    print (a[0]+a[1])/2
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
N = int(input())
m = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(N):
  if m[i]<b[i]:
    if (m[i]+m[i+1])>b[i]:
        s += b[i]
        m[i+1] += m[i]-b[i]
    else:
       s += m[i]+m[i+1]
  else:
    s += b[i]
print(s)

Submission status: Runtime Error

Solution code:
s = input()
dp = [0 for _ in range(13)]
dp[0] = 1
c = 1000000007
m = 1
r13 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
r10 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
for i in range(len(s) - 1, -1, -1):
    ndp = [0 for _ in r13]
    if s[i] == "?":
        for j in r10:
            jm = j * m
            for k in r13:
                index = (jm + k) % 13
                ndp[index] = (ndp[index] + dp[k]) % c
    else:
        jm = int(s[i]) * m
        for k in r13:
            index = (jm + k) % 13
            ndp[index] = (ndp[index] + dp[k]) % c
    dp = ndp[:]
    m = m * 10 % 13
print(dp[5])

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = sorted(a)
k = 0
for i in range(N):
  if a[i] != b[i]:
    k += 1
if k >2 :
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
a,b=map(int,input().split())
if (a+b)%2 == 0:
    print(a+b)/2
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

from collections import namedtuple

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def dist(pf, pt):
    return abs(pf[0]-pt[0]) + abs(pf[1]-pt[1])

def print_ans(sx, sy, ans):
    print(len(ans))
    for p in ans:
        print(sx*p[0], sy*p[1])

def move(k, pf, pt):
    assert(pt[1]>pf[1])
    d = min(pt[0]-pf[0], k)
    return [pf[0]+d,pf[1]+k-d]

def main():
    k = ri()
    x, y = rli()
    sx = 1 if x >= 0 else -1
    sy = 1 if y >= 0 else -1
    x = abs(x)
    y = abs(y)

    pf = [0, 0]
    pt = [x, y]
    if k % 2 == 0 and (x+y) % 2 == 1:
        print(-1)
        return
    d = dist(pf, pt)

    ans = []

    # 3回で到達
    if d < k and d % 2 == 1:
        ans.append(((x+y-k)//2, (k+x+y)//2))
        ans.append((x+y-k, 0))
        ans.append((x, y))
        print_ans(sx, sy, ans)
        return

    n = (x+y+k-1) // k
    d = (n*k-(x+y))//2
    if d > 0:
        pf = [k-d, -d]
        ans.append(tuple(pf))
    while dist(pf, pt) > 0:
        pf = move(k, pf, pt)
        ans.append(tuple(pf))
    print_ans(sx, sy, ans)
    assert(pf[0] == x and pf[1] == y)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()[::-1]
MOD = 10**9+7
dp = (1,0,0,0,0,0,0,0,0,0,0,0,0)
p = 1
for i, s in enumerate(S):
    nx = [0,]*13
    if s == '?':
        for k in range(10):
            q = (k*p)%13
            for j, d in enumerate(dp):
                nx[(j+q)%13] += d
    else:
        q = (int(s)*p)%13
        for j, d in enumerate(dp):
            nx[(j+q)%13] += d
    dp = (n % MOD for n in nx)
    p = (10*p)%13
print(dp[5])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0
for i in range(n-1,-1,-1):
    # i+1の討伐
    if a[i+1] < b[i]:
        count += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        count += b[i]
        a[i+1] -= b[i]
        b[i] = 0

    # iの討伐
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        count += b[i]
        a[i] -= b[i]
        b[i] = 0

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
S = input().strip()

MOD = 10**9 + 7
dp = np.zeros((100005, 13))
N = len(S)

dp[0][0] = 1
for i in range(N):
    c = -1
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki * 10 + j) % 13] += dp[i][ki]

    for j in range(13):
        dp[i+1][j] %= MOD

res = int(dp[N][5])

print(res)

Submission status: Runtime Error

Solution code:
# n,m = map(int,input().split())
n = int(input())
# n = input()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
left = 0
for i in range(n):
    a1,b1 = a[i],b[i]
    if a1 <= b1 + left:
        cnt += a1
        left = min(b1 - a1 + left,b1)
    else:
        cnt += b1 + left
        left = 0
if a[n] <= left:
    cnt += a[n]
else:
    cnt += left
print(cnt)

Submission status: Runtime Error

Solution code:
_l = '998244353 99824435'
_s = sum([int(i) for i in _l])
if _s % 2 != 0:
    print('IMPOSSIBLE')
else:
    print(_s / 2)

Submission status: Runtime Error

Solution code:
_l=input().split()
_s=sum([int(i) for i in _l])
if _s % 2 != 0:
  print('IMPOSSIBLE')
else:
  print(s/2)

Submission status: Runtime Error

Solution code:
a,b=[int(i) for i in inpput().split()]
a,b=min(a,b),max(a,b)
c=b-a
if c%2==0:
  print(c//2)
else:
  print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
_l=input().split()
_s=sum([int(i) for i in s])
if _s % 2 != 0:
  print('IMPOSSIBLE')
else:
  print(s/2)

Submission status: Runtime Error

Solution code:
s = input()
_list = [int(i) for i in s.split(' ')]
if sum(_list) % 2 != 0:
  print('IMPOSSIBLE')
  return
print(sum(_list) / 2)

Submission status: Runtime Error

Solution code:
_list = [int(i) for i in input().split(' ')]
if sum(_list) % 2 != 0:
  print("IMPOSSIBLE")
  return
print(sum(_list)/2)

Submission status: Runtime Error

Solution code:
k = int(input())
x, y = [int(x) for x in input().strip().split(" ")]
x, y = x-y, x+y

def main():
    if k % 2 == 0:
        if x % 2 != 0:
            return -1
    return to(x,y)

def cc(x, xs):
        if abs(x-xs) <= 2*k:
            if abs(x+k-xs) % 2 == k % 2:
                if abs(x+k-xs) <= abs(x-k-xs):
                    xs = x+k
                else:
                    xs = x-k
                return (True,xs)
            else:
                if x > xs:
                    xs += k
                else:
                    xs -= k
        else:
            if x > xs:
                xs += k
            else:
                xs -= k
        return (False,xs)


def to(x, y):
    rs = []
    xs, ys = 0, 0
    while True:
        if abs(x-xs) == k or abs(y-ys) == k:
            if abs(x-xs) <= k and abs(y-ys) <= k:
                return rs + [(x, y)]
        mm, ys = cc(y, ys)
        if mm:
            if x > xs:
                xs += k
            else:
                xs -= k
        else:
            mm, xs = cc(x, xs)
        rs.append((xs, ys))

if __name__ == '__main__':
    jj = main()
    if jj == -1:
        print(-1)
    else:
        print(len(jj))
        for r in jj:
            print((r[0]+r[1])//2, (r[1]-r[0])//2)

Submission status: Runtime Error

Solution code:
S = input()
dp = [[0]*13 for _ in range(len(S))]
mod = 10**9+7
for i in range(13):
    if S[0] == "?":
        dp[0][i] = 1 if i <= 9 else 0
    else:
        dp[0][i] = 1 if int(S[0]) == i else 0
for i in range(1,len(S)):
    if S[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i][(k*10+j) % 13] = (dp[i][(k*10+j) % 13]+dp[i-1][k])%mod
    else:
        j = int(S[i])
        for k in range(13):
            dp[i][(k*10+j)%13] = (dp[i][(k*10+j)%13]+dp[i-1][k])%mod
print(dp[len(S)-1][5])

Submission status: Runtime Error

Solution code:
i1 = int(input())
i2 = input().split(' ')
i3 = input().split(' ')

w = -1
s = 0

for i in range(i1):
  ii2 = int(i2[i])
  ii3 = int(i3[i])
#  print(ii2)
#  print(ii3)

  if ii2 > ii3:
    #引ききれた場合
    s += ii3
  else:
    s += ii2
    w = ii3 - ii2

    iii2 = int(i2[i+1])

    if iii2 > w:
      s += w
      w = iii2 - w
    else:
      s += iii2
      w = 0

print(s)

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

if a == b:
  print("IMPOSSIBLE")
  exit()

if a > b:
  diff = a - b
  _min = b
else:
  diff = b - a
  _min = a

res = int(diff / 2)
print(res)

res = res + _min

res = res % 2 

if res == 0:
  print(res)
else 
  print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
A,B = map(int,input().split())
k=(A**2-B**2)/(2*A-2*B)
if k == int(k):
  print(int(k))
else:
  print(IMPOSSIBLE)

Submission status: Runtime Error

Solution code:
N = int(input())
k = 0
lis = list(range(1, N+1))
for i in range(1, N+1):
  a = int(input())
  if a == lis[i-1]:
    k += 10
  else:
    k += 0
if k >= 10 * (N-2):
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
A,B =  map(int,input())
if (A==B) :
  print(0)
  
else:
  if((A+B/2 % 2 == 0):
    print((A+B)/2)
  else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
# chessboard, manhattan distance even will noly be possible if parity is right

from math import sqrt
eps = 1e-5

# Utils
def solve2(A11,A12,A21,A22,b1,b2):
    """Solves a 2x2 matrix equation."""
    det = (A11*A22-A12*A21)
    if abs(det) < eps:
        return (None, None)

    return (1/det*(b1*A22-b2*A12), 1/det*(b2*A11-b1*A21))

def dot(a,b):
    """Returns the dot product"""
    return sum(a[i]*b[i] for i in range(len(a)))
    
def normalize(a):
    """Normalize vector to unit length"""
    norm = sqrt(dot(a,a))
    return tuple(x/norm for x in a)

def cross(a,b):
    """3D cross product"""
    return (a[1]*b[2] - a[2]*b[1],
            a[2]*b[0] - a[0]*b[2],
            a[0]*b[1] - a[1]*b[0])

# intpt,onsegment,t,s = ll_intersect(a,da,b,db)
def ll_intersect(a,da,b,db):
    """Given two segments, return line intersection, segments crossing and
       parameters at crossing"""
    dx, dy = a[0]-b[0], a[1]-b[1]
    s,t = solve2(db[0], -da[0], db[1], -da[1], dx, dy)

    if s == None:
        return (None, False, None, None)

    ipt = (a[0] + t*da[0], a[1] + t*da[1])
    
    # Epsilon treatment?
    if s < -eps or s > 1+eps or t < -eps or t > 1+eps:
        return (ipt, False, t, s)
    
    return (ipt, True, t, s)
    

def manhattan(x,y,s,t):
    return abs(x-s) + abs(y-t)

def main():
    k = int(input())
    xx,yy = map(int,input().split())
    if k % 2 == 0:
        if (xx+yy)%2:
            print('-1')
            return
    
    P = []

    while (xx,yy) != (0,0):
        P.append((xx,yy))
        if manhattan(0,0,xx,yy) <= 2*k:
            Sorig = [[(-k,0),(k,k)],
                    [(0,k),(k,-k)],
                    [(k,0),(-k,-k)],
                    [(0,-k),(-k,k)]]
            S = [[(pos[0]+xx,pos[1]+yy),diff] for pos,diff in Sorig]
            
            inter = []
            for pp,dd in S:
                for pp2,dd2 in Sorig:
                    pt,onseg,_,_ = ll_intersect(pp,dd,pp2,dd2)
                    if onseg:
                        ix,iy = pt
                        if (ix - round(ix)) < eps and (iy - round(iy)) < eps:
                            inter.append((int(round(ix)),int(round(iy))))

            for ix,iy in inter:
                ix,iy = inter[-1]
                if manhattan(0,0,ix,iy) == k and manhattan(ix,iy,xx,yy) == k:
                    P.append((ix,iy))
                    P.append((0,0))
                    break
            if P[-1] == (0,0):
                break

        if xx < 0:
            signx = -1
            xx *= -1
        else:
            signx = 1

        if yy < 0:
            signy = -1
            yy *= -1
        else:
            signy = 1

        togo = k
        mn = min(togo,xx)
        xx -= mn
        togo -= mn
        yy -= togo

        xx *= signx
        yy *= signy

    for i in range(len(P)-1):
        assert abs(P[i][0] - P[i+1][0]) + abs(P[i][1] - P[i+1][1]) == k

    print(len(P)-1)
    for x,y in P[:-1][::-1]:
        print(x,y)

main()

Submission status: Runtime Error

Solution code:
N = int(input())
N = N+1
monsters = list(map(int, input().split()))
monsters.append(0)
heros = list(map(int, input().split()))
stack = 0
count = 0
point = 0
life = 0
for i in range(0, len(heros)):
    point = monsters[i] - (stack + heros[i])
    if point < 0:
        if abs(point) > monsters[i+1]:
            stack = monsters[i+1]
        else:
            stack = heros[i]-monsters[i]
        count += monsters[i]
    else:
        count += heros[i]
count += stack
print(count)

Submission status: Runtime Error

Solution code:
import statistics
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()
 
def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
    
A = MULT_INT_LIST()
mean = statistics.mean(A)
 
if is_integer_num(mean):
  print(int(mean))
else:
  print('IMPOSSIBLE')
 
 
import statistics
import sys
import math
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
    
A = MULT_INT_LIST()
mean = statistics.mean(A)

if is_integer_num(mean):
  print(int(mean))
else:
  print('IMPOSSIBLE')

Submission status: Runtime Error

Solution code:
A,B=input().split()
a=int(A)
b=int(B)
if a>=b:
  x=(a-b)/2
  if x%2==0:
    if a>=0:
      print(a-x)
    else:
      print(-a-x)
  else:
    print('IMPOSSIBLE') 
else:
  x=(b-a)/2
  if x%2==0:
     if b>=0:
      print(b-x)
    else:
      print(-b-x)
  else:
    print('IMPOSSIBLE')

Submission status: Runtime Error

Solution code:
A,B=input().split()
a=int(A)
b=int(B)
if a>=b:
  x=(a-b)/2
  if x%2==0:
    if a>=0:
      print(a-x)
    else:
      print(-a-x)
  else:
    print('IMPOSSIBLE') 
else:
  x=(b-a)/2
  if x%2==0:
     if a>=0:
      print(b-x)
    else:
      print(-b-x)
  else:
    print('IMPOSSIBLE')