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:
import sys
sys.setrecursionlimit(999999)
dicte = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
n, m = map(int, input().split())
arr = list(map(int, input().split()))
dp = [-1 for i in range(n+1)]
def cast(a, b):
    return int(str(a)+str(b))
def solve(curn):
    maxi = -1
    if dp[curn] != -1:
        return dp[curn]

    for j in arr:
        if curn - dicte[j] >= 0:
            dp[curn-dicte[j]] = solve(curn-dicte[j])
            if dp[curn-dicte[j]] == None:
                maxi = max(j, maxi)
            else:
                maxi = max(cast(j, dp[curn-dicte[j]]), maxi)
    if maxi == -1:
        return None
    return maxi
print(solve(n))

Submission status: Runtime Error

Solution code:
import functools
dicte = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
n, m = map(int, input().split())
arr = list(map(int, input().split()))
dp = {}
def cast(a, b):
    return int(str(a)+str(b))
dp = {}
def solve(curn):
    maxi = -1
    if curn in dp:
        return dp[curn]
    if curn in dicte.values():
        for j in arr:
            if curn - dicte[j] == 0:
                maxi = max(j, maxi)
        if maxi == -1:
            return None
        dp[curn] = maxi
        return maxi
    for j in arr:
        if curn - dicte[j] >= 0:
            z = solve(curn-dicte[j])
            if z == None:
                maxi = max(j, maxi)
            else:
                maxi = max(cast(j, solve(curn - dicte[j])), maxi)
    if maxi == -1:
        return None
    dp[curn] = maxi
    return maxi
print(solve(n))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
cnt = [0] * m
for _ in range(n):
    k, *a = map(int, input().split())
    for A in a:
        cnt[A - 1] += 1
print(sum(c == n for c in cnt))

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:
a, b = map(int, input())
if a % b == 0:
    print(a + b)
else:
    print(b - a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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,B = 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(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,B = map(int,input().split())

if B%A = 0 :
	print(int(A+B)
else :
	print(int(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:
 提出

Submission status: Runtime Error

Solution code:
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)+[-1]*9
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')

Submission status: Runtime Error

Solution code:
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -float('inf')
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == (digs[n]-1):
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')

Submission status: Runtime Error

Solution code:
I = lambda: map(int, input().split())
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
minf = -10**9
n, _ = I()
*A, = sorted(I(), reverse = True)
digs = [0]*(n+1)
for i in range(1, n+1):
    d = []
    for a in A :
        before = i-nums[a]
        d.append(minf if before < 0 else digs[before]+1)
    digs[i] = max(d)
ans = []
while n > 0:
    for a in A:
        if digs[n-nums[a]] == digs[n]-1:
            ans.append(a)
            n -= nums[a]
            break
print(*ans, sep = '')

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, m = map(int, input().split())
a = list(map(int, input().split()))

dp = dict.fromkeys(range(n + 1))  # dp[n]: n本使うときの桁数
dp[0] = 0

num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
anum = sorted(
    dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True
)  # 後の計算用にsortしておく

for i in range(n):
    dp[i + 1] = -float("inf")
    for e in anum:
        if i + 1 - e[1] >= 0:
            dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1)

ans = ""
while dp[n] > 1:
    for e in anum:  # anum は降順sortされているので, 大きい順に確認
        if n - e[1] >= 0:
            if dp[n - e[1]] == dp[n] - 1:
                ans += str(e[0])
                n -= e[1]
                break

# 末尾桁は n =0(ちょうど使い切るように決定)
ans += str(list(filter(lambda e: e[1] == n, anum))[0][0])

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split(' '))
_, *intersection = map(int, input().split(' '))
intersection = set(intersection)
for _ in range(1, n):
    _, *newlist = map(int, input().split(' '))
    intersection = intersection & set(newlist)
print(len(intersection))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b = map(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)

Submission status: Runtime Error

Solution code:
from math import ceil
N = int(input())
a = [int(input()) for i in range(5)]
i = a.index(min(a))
ans = i-1 + ceil(N/min(a)) + 5 -i
print(ans)

Submission status: Runtime Error

Solution code:
num = int(input())
num_ls = sorted([x for x in map(int, input().split(' '))])
while True:
    dam = []
    searchMin = [ x for x in num_ls if x != 1 ]
    for x in num_ls:
        div = x % min(searchMin)
        if div == 0:
            dam.append(x)
        else:
            dam.append(div)

    if num_ls == dam:
        break
    else:
        num_ls = dam

print(min(num_ls))

Submission status: Runtime Error

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

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:
a,b = map(int(input().split()))
if b%a :
    print(b-a)
else:
    print(a+b)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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 b%a == 0:
    print(A+B)
else:
    print(B-A)

Submission status: Runtime Error

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

if a[1]%a[0]==0:
  print(a[0]+a[1])
else:
  print(a[1]-a[0])

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 collections import Counter;N, M = map(int, input().split());print(len([i for i in Counter([flatten for inner in [i[1:] for i in [[int(i) for i in input().split()] for i in range(N)]] for flatten in inner]).most_common() if i[1] == N]))

Submission status: Runtime Error

Solution code:
1 <= a <= b <=20

a,b=(int(x) for x in input().split())


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

Submission status: Runtime Error

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst))

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(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, 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 b % a == 0:
  print(a + b)
else:
  pritn(b - a)

Submission status: Runtime Error

Solution code:
# スペース区切りの整数の入力
N,M = map(int, input().split())
A_list=[]
food_list=[]

for i in range(N):
  A_list.append([int(e) for e in input().split()])

for i in range(M):
  food_list.append(0)
  
for i in range(N):
  K=A_list[i][0]
  for j in range(1,K+1):
    #print(A_list[i][j],end="")
    food_list[A_list[i][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:
a,b = 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().print())

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

Submission status: Runtime Error

Solution code:
*l = map(int, open(0).read().split())
if l[1] % l[0] == 0:
	print(l[0] + l[1])
else:
	print(l[1] - l[0])

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:
A, B = list(map(int, input()))

if B % A == 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:
a, b  map(int, input().split())
if b // a == b / a:
  print(a+b)
else:
  print(a-b)

Submission status: Runtime Error

Solution code:
8 20

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
if int(s[5:7])<5:
	print('Heisei')
else:
	print('TBD')

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

a = sorted(A)
B = [a[0]]
C = []
for i in range(1,N):
    x = a[i]%a[0]
    if x != 0:
        B.append(x)
b =sorted(B)
for i in range(len(b)-1):
    y = math.gcd(b[i],b[-1])
    C.append(y)
    
if len(b) == 1:
    print(b[0])
else:
    print(min(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 = 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, raw_input().split())

if B%A == 0:
    print '{}'.format('A+B')
else: # B%A != 0
    print '{}'.format('B−A')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
[A,B]=list(map(input().split()))

if(A%B==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:
n, m = [int(c) for c in input().split()]
 
k = [list(map(int, input().split())) for _ in range(n)]
 
food_count = [0] * m
 
for p in k:
    for i in range(1, len(p)):
        food_count[p[i]-1] += 1
 
count = 0
for f in food_count:
    if f == n:
        count += 1
 
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

def chk(i,j):
    tmp=[p[i][k] for k in range(M)]
    tmp[j]=p[i][j]+1
    for k in range(M-1,-1,-1):
        if tmp[k] > p[i+x[j]][k] :
            p[i+x[j]]=[tmp[k] for k in range(M)]

N,M=map(int,input().split())
x=[0,2,5,5,4,5,6,3,7,6]
a=list(map(int,input().split()))
a.sort()
b=[]
for i in range(M):
    for j in range(M):
        if x[a[j]]==x[a[i]]: tmp=j
    b.append(a[tmp]) 

a=list(set(b))
a.sort()
M=len(a)
x=[ x[a[i]] for i in range(M) ]


p=[-100 for i in range(N+10)]
p[0]=0
for i in range(N):
    if p[i]>-1:
        for j in range(M):
            p[i+x[j]]=max(p[i+x[j]],p[i]+1)

ans=""
while N>0:
    for j in range(M-1,-1,-1):
        if p[N]==p[N-x[j]]+1:
            ans+=str(a[j])
            N-=x[j]
            break
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=(int(i) for i in input().split())
2.if B%A==0:
3.  print(A+B)
4.else:
5.  print(B-A)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
hoge=list(map(int,input().split()))
###
def huga(a,b):
  x=max(a,b)
  y=min(a,b)
  z=1
  for i in range(y):
    wa=y-i
    if(x%wa==0 and y%wa==0):
      z=wa
      break
  return z
###
hoge.sort(reverse=True)
ans=hoge[0]
for i in range(n-1):
  ans=huga(ans,hoge[i+1])
  
print(ans)

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=map(int,input())
if b%a==0:
  print(a+b)
else:
  print(b-a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import heapq

N = int(input())
A = list(map(int,input().split(' ')))
A_min = heapq.nsmallest(2,A)
X= A_min[0]
Y = A_min[1]

while X > 0 and Y > 0:
  if X <= Y:
    Y -= X
  else:
    X -= Y
print(max(X,Y))

Submission status: Runtime Error

Solution code:
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(min_val,m))
    return m_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)

main()

Submission status: Runtime Error

Solution code:
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(min_val,m))
    return min_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(min_val,m))
    return min_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)
main()

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:
l=input().split()
a=int(l[0])
b=int(l[1])
if a%b==0:
    print(a+b)
elif:
    print(b-a)

Submission status: Runtime Error

Solution code:
l =input().split()

l[0] = A
l[1] = B
if B%A == 0:
    print(A+B)
else:
    print(B-A)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
for i in range(N):
    for j in range(N-i):
        if j == N-i-1:
            print(N)
        else:
            print(N,end='')

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce
input()
print(reduce(gcd,list(map(int,input().split()))))

Submission status: Runtime Error

Solution code:
N = int(input())
monsters = list(map(int, input().split()))
def gcd(a, b):
	if b > 0 :
      return gcd(b , a % b)
    else :
      return b
if len(monster) == 1 :
	print(monster[0])
else :
    mon = gcd(monster[0], monster[1])
    if len(monster) >= 2
    for i in range(2 , N) :
      mon = gcd(mon, monster[i])
print(mon)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

A, B = map(int input().split())

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

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=input()
if b%a==0:
  print(a+b)
else:
  print(b-a)

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:
A,B=[int(x) for x in input().split()]

m=B%A

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

Submission status: Runtime Error

Solution code:
#encoding: utf-8

N, M = map(int, input().split())
A = list(map(int, input().split()))
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

A.sort()
A.reverse()

dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        if i - match[a] >= 0:
            dp[i] = max(dp[i - match[a]] * 10 + a, dp[i])

print(dp[N])

Submission status: Runtime Error

Solution code:
import sys
import os
f = open("C:/Users/user/Documents/python/atcoder/ABC118/import.txt","r")
sys.stdin = f

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

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(i) for i in input().split()
if B%A==0:
  print(A+B)
else:
  print(B-A)

Submission status: Runtime Error

Solution code:
A,B = map(input().split())
print(A + B) if B % A == 0 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=input()
B=input()
if B%A==0:
    print(A+B)
else:
    print(B-A)

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:
N, M = map(int, input().split())
useful_num_list = list(map(int, input().split()))

need_matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-1] * (N+1)
dp[0] = 0
for i in range(1, N+1):
    max_scale = -1
    for num in useful_num_list:
        if need_matches[num] <= i:
            scale = dp[i-need_matches[num]] + 1
            if max_scale < scale:
                max_scale = scale
    dp[i] = max_scale

useful_num_list.sort(reverse=True)
ans =""
n = N
while n > 0:
    ans_scale = ""
    for num in useful_num_list:
        if dp[n] - 1 == dp[n - need_matches[num]]:
            ans_scale = str(num)
            n -= need_matches[num]
            break
    ans += ans_scale
print(ans)

Submission status: Runtime Error

Solution code:
a, b= input().split()
print(a+b) if b%a==0 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:
a,b = map(in(),input().split())
if(b%2 == 0):
  print(a+b)
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(A-B)

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 = int(input())
A = list(map(int,input().split()))
while len(A) > 1:
    a_ = A[0]
    for x in range(1,len(A)):
        A[x] %= a_
    A = [ans for ans in A if ans > 0]
    A.sort()
print(A[0])

Submission status: Runtime Error

Solution code:
###B - Foods Loved by Everyone
N, M = map(int, input().split())
kaito = []
for i in range(N):
    kaito.append([int(i) for i in input().split()])

cnt = 0
for i in range(1, M+1):
    jlist = []
    for j in range(N):
        if i in kaito[j][1:]:
            jlist.append(True)
        else:
            jlist.append(False)
    if all(jlist):
        cnt += 1
        
print(cnt)

Submission status: Runtime Error

Solution code:
import fraction

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

x = math.gcd(a[0],a[1])

if n != 2:
    for i in range(2,n):
        x = math.gcd(x,a[i])
        
print(x)

Submission status: Runtime Error

Solution code:
INF = float('inf')
n, m = map(int, input().split())
a = list(map(int, input().split()))
cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
l = [[x, cost[x-1]] for x in a]
l = sorted(l, key = lambda x: x[1]*10-x[0])
r = l[0]
k = max((n - 210),0)//r[1]
n -= r[1]*k
_max = [0] + [-INF]*n
for i in range(1, n+1):
  for x in l:
    if x[1] <= i:
      _max[i] = max(_max[i], _max[i-x[1]]*10 + x[0])
ans = str(_max[n]) + str(r[0])*k
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)

Submission status: Runtime Error

Solution code:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
  q.put(a)
x = q.get()
while not q.empty():
  y= -q.get()
  if y == 0:
    break
  q.put(x % y)
  x = y
print(x)

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:
A=int(input())
B=int(input())
if(A>0 and B%A==0):
  print(B+A)
else:
  print(B-A)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A B = map(int(),input().split())
if(A>0 && 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(B+A)
else:
  print(B-A)

Submission status: Runtime Error

Solution code:
A, B = list(map(int,input().split()))
if (A==0) or (B == 0);
	print(A-B)

elif B%A ==0 :
	print(A+B)

else:
	print(A-B)

Submission status: Runtime Error

Solution code:
A, B = list(map(int,input().split()))
if A or B == 0;
	print(A-B)

elif B%A ==0 :
	print(A+B)

else:
	print(A-B)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
A, B = map(int, input().split())
if math.gcd(A, B) == A:
    print(A + B)
else:
    print(B-A)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
favFood = [input().split() for i in range(n)]
for i in favFood:
    del i[:1]

if not(n == 1):
    count = 0
    for i in range(1, m):
        check = True
        for j in range(n):
            if not (str(i) in favFood[j]):
                check = False
        if check:
            count += 1
    print(count)

else:
    print(len(favFood))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
favFood = [input().split() for i in range(n)]
for i in favFood:
    del i[:1]
    
count = 0

for i in range(1, m):
    check = True
    for j in range(n):
        if not (str(i) in favFood[j]):
            check = False
    if check:
        count += 1

print(count)

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:
n=int(input().split())
if n[1]%n[0]==0:
    print(n[0]+n[1])
else:
    print(n[1]-n[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
a,b=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('A'))
b=int(input('B'))
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
    print(a + b)
else:
    print(b - a)

Submission status: Runtime Error

Solution code:
# ｎとｍの取得
data = input().split()
n = int(data[0]) #n == 人数
m = int(data[1]) #m == 数字の種類
ans = 0
#ｎ回データを取得してカウント

j = 1 #j == 好きな数字
i = 1 #i == 行数カウンタ
c = [0] * (m +1)#c == ある数が含まれているかのカウンタ　0で初期化
    #データの取得

while i <= n:
    tmp = [int(s) for s in input().split()]
    td = tmp[1:] #td == 好きな番号
    tn = tmp[0]  #tn == 好きな番号の数
    
    # 数字が含まれているかの比較
    while j <= m: # jがすべての数字について実行
        
        if j in td: # jがｔｄに含まれるかの分岐
            j = int(j) #　ｊを数値に戻す
            
            c[j] += 1 # ｃのｊ番目の要素にカウント
        j = int(j) #if ではじかれたとき用にｊを数値に戻す
        j += 1# ｊをカウント
    j = 1    
    i += 1 # iをカウント

# 全てに含まれている数字の集計

for x in c:
    if x == n:
        ans += 1



print(ans)

Submission status: Runtime Error

Solution code:
# ｎとｍの取得
data = input().split()
n = int(data[0]) #n == 人数
m = int(data[1]) #m == 数字の種類
ans = 0
#ｎ回データを取得してカウント

j = 1 #j == 好きな数字
i = 1 #i == 行数カウンタ
c = [0] * m #c == ある数が含まれているかのカウンタ　0で初期化
    #データの取得

while i <= n:
    tmp = input()
    td = tmp[1:] #td == 好きな番号
    tn = tmp[0]  #tn == 好きな番号の数
    print(td)
    # 数字が含まれているかの比較
    while j <= m: # jがすべての数字について実行
        j = str(j)# jを文字列に変換
        if j in td: # jがｔｄに含まれるかの分岐
            j = int(j) #　ｊを数値に戻す
            c[j] += 1 # ｃのｊ番目の要素にカウント
        j = int(j) #if ではじかれたとき用にｊを数値に戻す
        j += 1# ｊをカウント
    j = 1    
    i += 1 # iをカウント

# 全てに含まれている数字の集計

for x in c:
    if x == n:
        ans += 1

print(c)

print(ans)

Submission status: Runtime Error

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

A = list(map(int,input().split()))
dp = [False for i in range(N+10)]
memo = [[] for i in range(N+10)]
taiou = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]
matchi = []
for i in range(1,10):
    if i in A:
        matchi.append(taiou[i-1])
matchi = sorted(matchi,key = lambda x:-x[0])
matchi = sorted(matchi,key = lambda x:x[1])
# for i in range(1,len(matchi)):
#     if matchi[i][1] == matchi[i-1][1]:

minma = matchi[0][1]
# print(matchi)
# print(minma)
# dp[0] = F
for i in range(len(matchi)):
    dp[matchi[i][1]] = True
    memo[matchi[i][1]].append(matchi[i][0])
for i in range(N):
    for j in range(len(matchi)):
        if dp[i-matchi[j][1]]:
            dp[i] = True
            memo[i] = memo[i] + memo[i-matchi[j][1]]
            memo[i].append(matchi[j][0])
            break
# print(dp)
# print(memo)
maxi = N
for i in range(N//minma,0,-1):
    if dp[N-i*minma]:
        maxi = i
        # print(maxi)
        break

ans = sorted([matchi[0][0]]*maxi + memo[N-maxi*minma],reverse = True)
for i in range(len(ans)):
    print(ans[i],sep='',end='')
print('')