Problem:


Score : 100 points

Problem Statement

You are given positive integers A and B.

If A is a divisor of B, print A + B; otherwise, print B - A.

Constraints

All values in input are integers.

1 \leq A \leq B \leq 20

Input

Input is given from Standard Input in the following format:

A B

Output

If A is a divisor of B, print A + B; otherwise, print B - A.

Sample Input 1

4 12

Sample Output 1

16

As 4 is a divisor of 12, 4 + 12 = 16 should be printed.

Sample Input 2

8 20

Sample Output 2

12

Sample Input 3

1 1

Sample Output 3

2

1 is a divisor of 1.



Sample input:
4 12


Sample output:
16

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
def  inpl(): return list(map(int, input().split()))
N, M = inpl()
A = sorted(inpl())
cost = [1e9, 2, 5, 5, 4, 5, 6, 3, 7, 6]
mincost = min([cost[a] for a in A])
maxcost = max([cost[a] for a in A])

DP = [0]*N
for a in A:
    if N - cost[a] >= 0:
        DP[N-cost[a]] = a

ans = DP[0]
for j in range(N//2 + 1):
    DP2 = [0]*N
    for i in range(max(0, N-maxcost*(j+1)), N-mincost*j):
        v = DP[i]
        if v == 0:
            continue
        for a in A:
            nk = i - cost[a]
            if nk >= 0:
                DP2[nk] = max(DP2[nk], 10*v + a)
    ans = max(ans, DP2[0])
    DP = DP2

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
i=0
while(a[1] != 0):
    a[i+1]=a[i+1]-(a[i+1]//a[i])*a[i]
    a=sorted(a)
    if(a[0] == 0):
        i += 1
        while(a[1] != 0):
            a[i+1]=a[i+1]-(a[i+1]//a[i])*a[i]
            a=sorted(a)
print(a[i+1])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input()) 
#n=4
lst = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
hps = np.array(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[len(hps)-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

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

hp = list(map(int, input().split()))
result = 0
checkyakusuru = []
checkodd = []
checkeven = []

if (hp.count(hp[0]) == m[0]):
    result = hp[0]

minhp = min(hp)

for p in hp:
    if (p % minhp == 0):
        checkyakusuru.append(1)
    
    if (checkyakusuru.count(1) == m[0]):
        result = p
        break
    else:
        if (p % 2 == 0):
            checkeven.append(1)
        if (checkeven.count(1) == m[0]):
            result = 2
            break
        else:
            result = 1

Submission status: Runtime Error

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

hp = list(map(int, input().split()))
result = 0
checkyakusuru = []
checkodd = []
checkeven = []

if (hp.count(hp[0]) == m[0]):
    result = hp[0]

minhp = min(hp)

for p in hp:
    if (p % minhp == 0):
        checkyakusuru.append(1)
    
    if (checkyakusuru.count(1) == m[0]):
        result = p
        break
    else:
        if (p % 2 == 0):
            checkeven.append(1)
        if (checkeven.count(1) == m[0]):
            result = 2
        else:
            result = 1

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
if all(A[0]==a for a in A):
    print(A[0])
else:
    B = []
    D = []
    for a in A:
        for i in range(len(A)):
            if A[i]%a != 0:
                B.append(A[i]%a)
                C = list(set(B))
    for i in range(len(C)-1):
        D.append(abs(C[i]-C[i+1]))
    print(min(min(C),min(D)))

Submission status: Runtime Error

Solution code:
N = int(input())
HPs = list(map(int, input().split()))

while len(HPs) > 1:
    HPs.sort()
    for i in range(len(HPs)-1):
        HPs[i+1] = HPs[i+1] % HPs[0]
    while 0 in HPs:
        HPs.remove(0)

print(HPs[0])

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce


def gcd_list(numbers):
    return reduce(fraction.gcd, numbers)


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i]) 
print("{}".format(gcd_list(A)))

Submission status: Runtime Error

Solution code:
var
 a,b:longint;
begin
 readln(a,b);
 if (b mod a = 0) then writeln(a+b) else 
writeln(b - a);
end.

Submission status: Runtime Error

Solution code:
from fractions import gcd

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


answer = 5000000000000000000000000000000000

e.sort(reverse=True)
for i in range(0,n-2):
    for j in e[i+1:n-1]:
        if gcd(e[i],j) < answer:
            answer = gcd(e[i],j)
            
print(answer)

Submission status: Runtime Error

Solution code:
N = input()
A = int(N[0])
B = int(N[2])

if B % A == 0:
    ans = B - A
else:
    ans = A + B

print(ans)

Submission status: Runtime Error

Solution code:
N, M = (int(x) for x in input().split())
KA = [[int(x) for x in l] for l in [input().split() for i in range(N)]]
[x.pop(0) for x in KA]
x = []
for s in KA:
  x.extend(s)
c = 0
for i in range(1, M + 1):
  c = c + (1 if x.count(i) == N else 0)
print(c)

Submission status: Runtime Error

Solution code:
import numpy as np
n,m = map(int,input().split())
if b%a == 0:
    print(b+a)
else:
    print(b-a)

Submission status: Runtime Error

Solution code:
n, m = [int(x) for x in input().split()]
food_list = [0 for x in range(m)]

for i in range(n):
  s = [int(x) for x in input().split()]
  k = s[0]
  e = s[1:]
  for j in range(k):
    food_list[e[j]-1] += 1

ans = 0
for i in range(m):
  if food_list[i] == n:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
inputData = input().split(' ')
ans = 0

if int(inputData[1]) % input(inputData[0]) ==0:
    ans = int(inputData[0]) + int(inputData[1])
else:
    ans = int(inputData[1]) - int(inputData[0])
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
i=0
while(a[-2] != 0):
    if(a[-1]%a[i]==0):
        a[-1]=0
        i+=1
    else:
        a[-1]=a[-1]-(a[-1]//a[i])*a[i]
    a=sorted(a)
print(a[-1])

Submission status: Runtime Error

Solution code:
n=int(input())
a_s=list(map(int,input().split()))
while True:
    a_s=set(a_s)
    a_s.discard(0)
    a_s=list(a_s)
    index=a_s.index(min(a_s))
    for i in range(len(a_s)):
        if i!=index and min(a_s)!=0:
            a_s[i]=a_s[i]%min(a_s)
    if len(a_s)==1:
        break
print(sum(a_s))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce

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

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

print(gcd(*A))

Submission status: Runtime Error

Solution code:
from collections import Counter

N, M=map(int, input().split())
a = []
for i in range(N):
  b = []
  b = list(map(int, input().split()))
  del b[0]
  a.extend(b)
  
c=Counter(a)
    # すべての要素とその出現回数を取り出します。
freq_scores = c.most_common()
    #c.most_common内の最も多い要素[0]の最大出現回数[1]を[0][1]で指定
max_count = freq_scores[0][1]

modes = []
    　#出現回数と最大出現回数が等しいかを確認します。
for num in freq_scores:
	if num[1] == max_count:
    	modes.append(num[0])

print(len(a[modes]))

Submission status: Runtime Error

Solution code:
str = input()
a = int(str[0])
b = int(str[2])*10 + int(str[3])

if (b % a) == 0:
	print(a + b)
else:
	print(b-a)

Submission status: Runtime Error

Solution code:
inputData1 = int(input())
inputData2 = int(input())
ans = 0
if inputData2 % inputData1 ==0:
    ans = inputData1 + inputData2
else:
    ans = inputData2 - inputData1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
a = np.zeros((N,M))
for i in range(N):
    K = list(map(int, input().split())) 
    for j in K[1:]:
        a[i][j-1] = 1
b = a.sum(axis=0)
print(len(np.where(b==N)[0]))

Submission status: Runtime Error

Solution code:
import random
A=randint(0,20)
B=randint(0,20)
if B/A=0:
  print(A+B)
else:
  print(A-B)

Submission status: Runtime Error

Solution code:
str = input().strip()

a = int(str[1])
b = int(str[2])

if (b % a) == 0:
	print(a + b)
else:
	print(b-a)

Submission status: Runtime Error

Solution code:
A=randint B=randint
if B/A=0:
  print(A+B)
else:
  print(A-B)

Submission status: Runtime Error

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

if b%a == 0 :
  print(b+a)
else :
  print(b -a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sys import stdin

a, b = stdin.readline().rstrip().split()

for i in range(1, 21):
    if a * i > b:
        break

    if b % (a * i) == 0:
        print(a + b)
        break
else:
    print(b - a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
for i in range(1, 21):
    if a * i > b:
        break

    if b % (a * i) == 0:
        print(a + b)
        break
else:
    print(b - a)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
def gcd(a,b):
  c = a%b
  if c == 0:
    return b
  else:
    return gcd(b,c)
c = 0
for i in a[1:]:
  c_ = gcd(i,a[0])
  if c_ == 1:
    c = 1
    break
  else:
    if c_ < c or c == 0:
      c = c_
print(c)

Submission status: Runtime Error

Solution code:
a,b=int(input())
if a/b=n:
  print(a+b)
  else 
  print(b-a)

Submission status: Runtime Error

Solution code:
def inpl(): return list(map(int, input().split()))

def match(x):
    return (2, 5, 5, 4, 5, 6, 3, 7, 6)[x-1]
N, M = inpl()
A = inpl()
A.sort(reverse = True)
matnum = set([match(a) for a in A])
maxdig = 1
Dig = [{0}]
for i in range(1,1+N//min(matnum)):
    k = set()
    for v in Dig[-1]:
        for a in matnum:
            k.add(a+v)
    if N in k:
        maxdig = i
    Dig.append(k)
N1 = N
anstr = ''
for i in range(maxdig, 0, -1):
    for a in A:
        if N1-match(a) in Dig[i-1]:
            anstr += str(a)
            N1 -= match(a)
            break
        
print(anstr)

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
if( b % a === 0){
  print a + b
} else {
  print b - a 
}

Submission status: Runtime Error

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

if A % B == 0:
  print(A+B)
else:
  print(B-A)

Submission status: Runtime Error

Solution code:
A,B = int(input().split())
if(B%A==0):
  print(A+B)
else:
  print(B-A)

Submission status: Runtime Error

Solution code:
N = int(input())
monstar = list(map(int, input().split()))
monstar.sort()
min1, min2 = monstar[0], monstar[1]
while min1 > 0 and min2 > 0:
  if min1 <= min2:
    min2 -= min1
  else:
    min1 -= min2
print(max(min1, min2))

Submission status: Runtime Error

Solution code:
a,b=[int(i) for i in input().split()] 
if( a/b === 0){
  print a + b
} else {
  print b -a 
}

Submission status: Runtime Error

Solution code:
a,b = int(input().split())
if b%a==0:
    print(a+b)
else:
    print(b-a)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys


def func_a(argv):
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
    B = int(argv[1]) if int(argv[1]) <= 20 else 0

    if A * B == 0:
        pass
    else:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


if __name__ == "__main__":
    func_a(sys.argv)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys


def func_a(argv):
    A = int(argv[0]) if int(argv[0]) >= 1 else 0
    B = int(argv[1]) if int(argv[1]) <= 20 else 0

    if A * B == 0:
        pass
    else:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


if __name__ == "__main__":
    func_a(sys.argv[1:])

Submission status: Runtime Error

Solution code:
A, B = (int(x) for x in input().split())
if B % A == 0:
  return A + B
else:
  return B - A

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys


def func_a(argv):
    A = int(argv[0])
    B = int(argv[1])

    if not (A >= 1):
        pass

    if not (B <= 20):
        pass

    if A <= B:
        if B % A == 0:
            print(A + B)
        else:
            print(B - A)


def main(argv):
    func_a(argv[1:])


if __name__ == "__main__":
    main(sys.argv)

Submission status: Runtime Error

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

if b % a == 0:
	print(a+b)
else:
	print(b-a)

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
menu = np.array([])
for i in range(N):
  a = np.array(input().split())
  menu = np.append(menu, a[1:])
menu = np.array(menu).astype(int).ravel()
count = 0
for i in range(1, M+1):
  if np.sum(menu == i) == N:
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
import sys 

A = int(sys.argv[1])
B = int(sys.argv[2])

if not (A >= 1):
  pass

if not (B <= 20):
  pass

if A <= B:
  if B % A == 0:
    print(A + B)
  else:
    print(B - A)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:59:16 2019

@author: doppe
"""

N, M = map(int, input().split())
likeList = []

for i in range(0, N):
    L = [int(i) for i in input().split()]
    likeListTmp = []
    if (i == 0):
        likeList = L
    else:
        for j in range(1, L[0] + 1):
            if (L[j] in likeList):
                likeListTmp.append(L[j])
        likeList = likeListTmp

print(len(likeList))

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
if b%a==0:
  print(a+b)
else:
    print(b-a)

Submission status: Runtime Error

Solution code:
A=input('Aを入力してください:')
B=input('Bを入力してください:')
 
def abcd(A,B):
    if B%A==0:
      return A+B
    else:
      return A-B
    
print (abcd(A,B))

Submission status: Runtime Error

Solution code:
A=input('Aを入力してください:')
B=input('Bを入力してください:')

def abcd(A,B):
    if B%A==0:
      return A+B
    elif:
      return A-B
    
print (abcd(A,B))

Submission status: Runtime Error

Solution code:
a,b = int(x) for x in input().split()
if (!b%a):
    print(a+b)
else:
    print(b-a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a, b = [int(x) for x in input().rstrip("\n").split(" ")]
 
if b % a == 0:
  print(b + a)
else:
  print(b -ab)

Submission status: Runtime Error

Solution code:
import sys
input_lines = sys.stdin.readlines()
a,b = input_lines.split( )

a = int(a)
b = int(b)

if(b%a==0):
  print(a+b)
else:
  print(b-a)

Submission status: Runtime Error

Solution code:
A=input('Aを入力してください:')
B=input('Bを入力してください:')

if B%A=0:
  print A+B
elif:
  print A-B

Submission status: Runtime Error

Solution code:
import sys

argvs = sys.argv

if len(argvs) < 2:
    sys.exit(1)

try:
    a = int(argvs[1])
    b = int(argvs[2])
except TypeError:
    sys.exit(1)

if b % a == 0:
    print(a+b)
else:
    print(b-a)

Submission status: Runtime Error

Solution code:
#coding: utf-8

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

if B%A == 0:
    print(A + B)
else:
    print(B - A)

Submission status: Runtime Error

Solution code:
a, b = map(int, ' '.split(input()))
if b%a == 0:
  print(a+b)
else:
  print(b-a)

Submission status: Runtime Error

Solution code:
a,b = map (int , input().split())
if b % a == 0 ;
    c = a+b
else;
    c = b-a
print (c)

Submission status: Runtime Error

Solution code:
import sys
input_lines = sys.stdin.readlines()
a,b = input_lines.split( )

if(b%a==0):
  print(a+b)
else:
  print(b-a)

Submission status: Runtime Error

Solution code:
1 <= int(A) <= int(B) <= 20

def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

Submission status: Runtime Error

Solution code:
A,B = input().split()
if B%A == 0:
  print(A + B)
else:
  print(A - B)

Submission status: Runtime Error

Solution code:
def main()
  a = input()
  b = input()

  if a/b == 0:
    print(a + b)
  else:
    print(b - a)

Submission status: Runtime Error

Solution code:
a, b = (int(i) for i in input().split())  
  
if b/a % 0:
	c = a + b
else:
	c = b - a
    
print(c)

Submission status: Runtime Error

Solution code:


a = input()
b = input()

if  a/b == 0:
  print(a + b)
else:
  print(b - a)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
a, b = tuple(li())
div, mod = divmod(b, a)
if mod == 0:
    return a + b
else:
    return b - a

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
	a,b = map(int, input().split())
	if (b %= a) == 0:
		print(a+b)
	else:
		print(b-a)

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
a, b = tuple(li())
div, mod = divmod(b, a)
if mod == 0:
	return a + b
else:
	return b - a

Submission status: Runtime Error

Solution code:
a, b = list(map(int, input().split()))
print([a+b,b-a][b%a])

Submission status: Runtime Error

Solution code:
a, b = (int(i) for i in input().split())  
  
if a/b % 0:
	c = a + b
else:
	c = b - a
    
print(c)

Submission status: Runtime Error

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

if(b%a==0):
  print(a+b)
else:
  print(b-a)

Submission status: Runtime Error

Solution code:
a=map(int,input().split())
if a[1]%a[0]==0:
    print(a[0]+a[1])
else:
    print(a[1]-a[0])

Submission status: Runtime Error

Solution code:
data = input().split()
A = data[0]
B = data[1]
if (B % A) == 0 :
    ANS = A+B
else:
    ANS = B - A
print(ANS)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b=list(map(int,input().split()))
print([a+b,b-a][b%a])

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
a, b = tuple(li())
div, mod = divmod(b, a)
if mod == 0:
	return a + b
else:
    return b - a

Submission status: Runtime Error

Solution code:
A, B = map(int, input())
print(A + B if B % A == 0 else B - A)

Submission status: Runtime Error

Solution code:
a = int(input())
b = int(input())
if b % a == 0:
  print (a + b)
else:
  print (b - a)

Submission status: Runtime Error

Solution code:
n, m = map(int, input(),split())
if m % n :
  print(m - n)
else :
  print(n + m)

Submission status: Runtime Error

Solution code:
def main():
	s = input().strip()
	a = s[0]
	b = s[1]
	if (b/a)*a == b:
		print(a+b)
	else:
		print(b-a)

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
a, b = map(int, input())
if b % a == 0:
  print(a+b)
else:print(b-a)

Submission status: Runtime Error

Solution code:
if b % a = 0:
  print(a+b)
else:
  print(b-a)

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
if B % A == 0:
  print(A + B)
else:
  print(B - A)

Submission status: Runtime Error

Solution code:
a,b = list(map(int,input().split()))
if b%a = 0:
  print(a+b)
else:
  print(a-b)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
if B % A == 0:
  print(A + B)
else:
  print(A - B)

Submission status: Runtime Error

Solution code:
A, B = map(int, input())
if B % A == 0:
  print(A + B)
else:
  print(A - B)