ZhenlongDai/ACPR huggingface dataset:
Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = input()

tmp = 0

for i in range(len(N)):
    tmp += int(N[i])
    
if tmp % int(N) == 0:
    print('Yes')
else:
    print('No')

Failing test case input:
190

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):
N = input()

tmp = 0

for i in range(len(N)):
    tmp += int(N[i])
    
if int(N) % tmp == 0:
    print('Yes')
else:
    print('No')

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = (input())
number_2 = [int(s) for s in a]
total = sum(number_2)
print(total)
if int(a) % total == 0:
  print('Yes')
else:
  print('No')

Failing test case input:
284

Expected output:
No


Actual output:
14
No


Fixed submission (verdict: Accepted):
a = (input())
number_2 = [int(s) for s in a]
total = sum(number_2)
if int(a) % total == 0:
  print('Yes')
else:
  print('No')

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=input()
if int(s)%sum(map(int,list(s)))==0:
	print('YES')
else:
  	print('NO')
    

Failing test case input:
151

Expected output:
No


Actual output:
NO


Fixed submission (verdict: Accepted):
s=input()
if int(s)%sum(map(int,list(s)))==0:
	print('Yes')
else:
  	print('No')

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
if int(n) % sum(list(map(int, n))) == 0:
	print("YES")
else:
	print("NO")

Failing test case input:
190

Expected output:
Yes


Actual output:
YES


Fixed submission (verdict: Accepted):
n = input()
if int(n) % sum(list(map(int, n))) == 0:
	print("Yes")
else:
	print("No")

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n=input()
    s=sum([int(i) for i in n])
    print(s)
    if int(n)%s==0:
        print("Yes")
    else:
        print("No")

if __name__=='__main__':
    main()


Failing test case input:
128

Expected output:
No


Actual output:
11
No


Fixed submission (verdict: Accepted):
def main():
    n=input()
    s=sum([int(i) for i in n])
    if int(n)%s==0:
        print("Yes")
    else:
        print("No")

if __name__=='__main__':
    main()

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
num = int(input())

fx = 0
for i in str(num):
    fx += int(i)

print("YES" if num % fx == 0 else "NO")

Failing test case input:
1075

Expected output:
No


Actual output:
NO


Fixed submission (verdict: Accepted):
num = int(input())

fx = 0
for i in str(num):
    fx += int(i)

print("Yes" if num % fx == 0 else "No")
Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = input()
print(n)
print(sum(map(int, n)))
x = sum(map(int, n))
print(int(n)/x)

if int(n) % sum(map(int, n)) == 0:
    print('Yes')
    exit()
else:
    print('No')


Failing test case input:
172

Expected output:
No


Actual output:
172
10
17.2
No


Fixed submission (verdict: Accepted):
import math
import string


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


def nCr(n, r):
    return math.factorial(n)


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = input()


x = sum(map(int, n))


if int(n) % sum(map(int, n)) == 0:
    print('Yes')
    exit()
else:
    print('No')

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = input()

i = 0

for i in range(len(a)):
  i += int(a[i])

print('Yes' if int(a)%i ==0 else 'No')

Failing test case input:
561

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
a = input()
x = 0
for i in range(len(a)):
    x += int(a[i])
print("Yes" if int(a) % x == 0 else "No")
Problem: p03502
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):










import sys

def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]

def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


N = iIn()

fN = sum(list(map(int, list(str(N)))))

ans = 'Yes' if N == fN else 'No'

print(ans)

Failing test case input:
117

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):










import sys

def input(): return sys.stdin.readline().rstrip()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]

def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)


N = iIn()

fN = sum(list(map(int, list(str(N)))))

ans = 'Yes' if N % fN == 0 else 'No'

print(ans)

Problem: p03502
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
num=input()
s=0
for it in num:
    s+=int(it)
print(s)
num=int(num)
print("Yes" if num%s==0 else "No")



Failing test case input:
128

Expected output:
No


Actual output:
11
No


Fixed submission (verdict: Accepted):
num=input()
s=0
for it in num:
    s+=int(it)
num=int(num)
print("Yes" if num%s==0 else "No")
Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
n = len(s)
idx = 0
while idx < n:
    if idx+5 <= n and s[idx:idx+5] == 'dream':
        idx += 5
    elif s[idx:idx+4] == 'eras':
        idx += 4
    else:
        break
    if idx+2 <= n and s[idx:idx+2] == 'er' and (idx+2 == n or s[idx+2:idx+3] != 'a'):
        idx += 2
if idx == n:
    print('YES')
else:
    print('NO')

Failing test case input:
erasedream

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
s = input()
n = len(s)
idx = 0
while idx < n:
    if idx+5 > n:
        break
    if s[idx:idx+5] == 'dream':
        idx += 5
        if idx+2 <= n and s[idx:idx+2] == 'er' and (idx+2 == n or s[idx+2:idx+3] != 'a'):
            idx += 2
    elif s[idx:idx+5] == 'erase':
        idx += 5
        if idx+1 <= n and s[idx:idx+1] == 'r':
            idx += 1
    else:
        break

if idx == n:
    print('YES')
else:
    print('NO')

Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if S == '':
    print('Yes')
else:
    print('No')

Failing test case input:
erasedream

Expected output:
YES

Actual output:
Yes


Fixed submission (verdict: Accepted):
S = input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream','')
if S == '':
    print('YES')
else:
    print('NO')

Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def solve(s):
    sys.stderr.write(s)
    sys.stderr.write("\n")

    while(len(s) >= 1):
        if s == "":
            return True
        elif s.startswith("maerd"):
            s = s[5:]
        elif s.startswith("remaerd"):
            s = s[7:]
        elif s.startswith("esare"):
            s = s[5:]
        elif s.startswith("resare"):
            s = s[6:]
        else:
            return False



def main():
    line = sys.stdin.readline().rstrip()
    line_rev = line[::-1]

    if solve(line):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())


Failing test case input:
erasedream

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
import sys

def solve(s):
    tmp_s = s
    while(len(tmp_s) > 0):
        if tmp_s.startswith("maerd"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("remaerd"):
            tmp_s = tmp_s[7:]
        elif tmp_s.startswith("esare"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("resare"):
            tmp_s = tmp_s[6:]
        else:
            return False

    return True

def main():
    line = sys.stdin.readline().rstrip()
    line_rev = line[::-1]

    if solve(line_rev):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())
Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
if not input().replace('eraser', '').replace('erase', '').replace('dream', '').replace('dreamer', ''):
  print('Yes')
else:
  print('No')

Failing test case input:
erasedream

Expected output:
YES

Actual output:
Yes


Fixed submission (verdict: Accepted):
if not input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', ''):
  print('YES')
else:
  print('NO')

Problem: p03856
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys

S = input()
index = len(S)
while index >= 7:
    five = S[index-5:index]
    six = S[index-6:index]
    seven = S[index-7:index]
    if five == "dream" or five == "erase":
        index -= 5
    elif six == "eraser":
        index -= 6
    elif seven == "dreamer":
        index -= 7
    else:
        print("NO")
        sys.exit()

last = S[:index]





Failing test case input:
erasedream

Expected output:
YES

Actual output:
no output


Fixed submission (verdict: Accepted):

import sys

S = input()
index = len(S)
while index > 7:
    five = S[index-5:index]
    six = S[index-6:index]
    seven = S[index-7:index]
    if five == "dream" or five == "erase":
        index -= 5
    elif six == "eraser":
        index -= 6
    elif seven == "dreamer":
        index -= 7
    else:
        print("NO")
        sys.exit()

last = S[:index]
if last == "dream" or last == "erase" or last == "eraser" or last == "dreamer":
    print("YES")
else:
    print("NO")

Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
s.reverse()
s = ''.join(map(str, s))
count = 0
word = ['maerd', 'remaerd', 'resare', 'esare']

while count <= len(s)-8:
  counttemp = count
  for i in range(4):
    w = word[i]
    if s[count:count+len(w)] == w:
      count += len(w)
  if counttemp == count:
    break
if s[count:] in word:
  print('YES')
else:
  print('NO')
    


Failing test case input:
erasedream

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
s = list(input())
s.reverse()
s = ''.join(map(str, s))
count = 0
word = ['maerd', 'remaerd', 'resare', 'esare']

while count <= len(s)-8:
  counttemp = count
  for i in range(4):
    w = word[i]
    if s[count:count+len(w)] == w:
      count += len(w)
  if counttemp == count:
    break

if s[count:] in word or s[count:] =='':
  print('YES')
else:
  print('NO')
Problem: p03856
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


import sys
read = sys.stdin.read
readline = sys.stdin.readline




s = [*input()]
a = [*"dream"]
b = [*"dreamer"]
c = [*"erase"]
d = [*"eraser"]


while True:
    if not s:
        print("Yes")
        break
    elif s[-5:] == a:
        for _ in range(5): s.pop()
    elif s[-5:] == c:
        for _ in range(5): s.pop()
    elif s[-6:] == b:
        for _ in range(6): s.pop()
    elif s[-6:] == d:
        for _ in range(6): s.pop()
    else:
        print("No")
        break







Failing test case input:
erasedream

Expected output:
YES

Actual output:
Yes


Fixed submission (verdict: Accepted):


import sys
read = sys.stdin.read
readline = sys.stdin.readline




s = [*input()]
a = [*"dream"]
b = [*"dreamer"]
c = [*"erase"]
d = [*"eraser"]

while True:
    if not s:
        print("YES")
        break
    elif s[-5:] == a:
        for _ in range(5): s.pop()
    elif s[-5:] == c:
        for _ in range(5): s.pop()
    elif s[-7:] == b:
        for _ in range(7): s.pop()
    elif s[-6:] == d:
        for _ in range(6): s.pop()
    else:
        print("NO")
        break

Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0
print(reversed_keys)
while i < len(rS):
    if rS[i:i+5] in reversed_keys:
        i += 5
    elif rS[i:i+6] in reversed_keys:
        i += 6
    elif rS[i:i+7] in reversed_keys:
        i += 7
    else:
        break
if i == len(rS):
    print('YES')
else:
    print('NO')


Failing test case input:
erasedream

Expected output:
YES

Actual output:
['maerd', 'remaerd', 'esare', 'resare']
YES


Fixed submission (verdict: Accepted):
S = input()
rS = S[::-1]
keys = ['dream', 'dreamer', 'erase', 'eraser']
reversed_keys = [keys[i][::-1] for i in range(len(keys))]
i = 0

while i < len(rS):
    if rS[i:i+5] in reversed_keys:
        i += 5
    elif rS[i:i+6] in reversed_keys:
        i += 6
    elif rS[i:i+7] in reversed_keys:
        i += 7
    else:
        break
if i == len(rS):
    print('YES')
else:
    print('NO')
Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

def solve(s):
    if s == "":
        return True
    elif s.endswith("dream"):
        return solve(s[:-5])
    elif s.endswith("dreamer"):
        return solve(s[:-7])
    elif s.endswith("erase"):
        return solve(s[:-5])
    elif s.endswith("eraser"):
        return solve(s[:-6])
    else:
        return False
    return False


def main():
    line = sys.stdin.readline()

    if solve(line):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())


Failing test case input:
erasedream

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
import sys

def solve(s):
    tmp_s = s
    while(len(tmp_s) > 0):
        if tmp_s.startswith("maerd"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("remaerd"):
            tmp_s = tmp_s[7:]
        elif tmp_s.startswith("esare"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("resare"):
            tmp_s = tmp_s[6:]
        else:
            return False

    return True

def main():
    line = sys.stdin.readline().rstrip()
    line_rev = line[::-1]

    if solve(line_rev):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())

Problem: p03856
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10000)

def solve(s):
    if s == "":
        return True
    elif s.endswith("dream"):
        return solve(s[:-5])
    elif s.endswith("dreamer"):
        return solve(s[:-7])
    elif s.endswith("erase"):
        return solve(s[:-5])
    elif s.endswith("eraser"):
        return solve(s[:-6])
    else:
        return False
    return False


def main():
    line = sys.stdin.readline()

    if solve(line):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())


Failing test case input:
erasedream

Expected output:
YES

Actual output:
NO


Fixed submission (verdict: Accepted):
import sys

def solve(s):
    tmp_s = s
    while(len(tmp_s) > 0):
        if tmp_s.startswith("maerd"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("remaerd"):
            tmp_s = tmp_s[7:]
        elif tmp_s.startswith("esare"):
            tmp_s = tmp_s[5:]
        elif tmp_s.startswith("resare"):
            tmp_s = tmp_s[6:]
        else:
            return False

    return True

def main():
    line = sys.stdin.readline().rstrip()
    line_rev = line[::-1]

    if solve(line_rev):
        print("YES")
    else:
        print("NO")

    return 0

if __name__ == '__main__':
    sys.exit(main())
Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = str(input())
t = str(input())
cnt = 0
for i in range(0,2):
  if s[i] == t[i]:
    cnt += 1
print(int(cnt))

Failing test case input:
RTR
STR

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
s = str(input())
t = str(input())
cnt = 0
for i in range(0,3):
  if s[i] == t[i]:
    cnt += 1
print(int(cnt))

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())
T = list(input())
cnt = 0

for i in range(2):
    if S[i] == T[i]:
        cnt += 1
    else:
        cnt

print(cnt)


Failing test case input:
QVT
RST

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
S = list(input())
T = list(input())
cnt = 0

for i in range(3):
    if S[i] == T[i]:
        cnt += 1

print(cnt)

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = str(input())
T = str(input())

s = list(S)
t = list(T)

ans = 0

for i in range(2):
    if s[i] == t[i]:
        ans += 1
        
print(ans)

Failing test case input:
RTS
TTS

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
S = str(input())
T = str(input())

s = list(S)
t = list(T)

ans = 0

for i in range(3):
    if s[i] == t[i]:
        ans += 1
        
print(ans)

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
T = input()
counter = 0
for i in range(2):
    if S[i] == T[i]:
        counter += 1
        
print(counter)


Failing test case input:
VRS
QTS

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
S = input()
T = input()
counter = 0
for i in range(3):
    if S[i] == T[i]:
        counter += 1
        
print(counter)

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())
T = list(input()) 

ans =  0
print(S)
for i in range(3):
    if S[i] == T[i]:
        ans += 1

print(ans)

Failing test case input:
UTR
STS

Expected output:
1


Actual output:
['U', 'T', 'R']
1


Fixed submission (verdict: Accepted):
S = list(input())
T = list(input()) 

ans =  0
for i in range(3):
    if S[i] == T[i]:
        ans += 1

print(ans)

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=input()
T=input()
count=0
for i in range(0,2):
    if S[i]==T[i]:
        count+=1
print(count)

Failing test case input:
VSS
TRS

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
S=input()
T=input()
count=0
for i in range(0,3):
    if S[i]==T[i]:
        count+=1
print(count)

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
t = list(input())
num = 0
for i in range(2):
    if s[i] == t[i]:
        num += 1
print(num)


Failing test case input:
RTS
STS

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
s = list(input())
t = list(input())
num = 0
for i in range(3):
    if s[i] == t[i]:
        num += 1
print(num)
Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=list(str(input()))
T=list(str(input()))
i=0

for i in range(3):
	if S[i]==T[i]:
		i+=1
print(i)

Failing test case input:
TSR
STS

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
S=list(str(input()))
T=list(str(input()))
p=0

for i in range(3):
	if (S[i]==T[i]):
		p+=1
print(p)

Problem: p02921
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

s,t = input(), input()

c = 1
for i in range(len(s)):
	if s[i] == t[i]:c+=1
	
print(c)

Failing test case input:
TSR
TTR

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):

s,t = input(), input()

c = 0
for i in range(len(s)):
	if s[i] == t[i]:c+=1
	
print(c)

Problem: p02921
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
predict = input('predict')

actual = input('actual')

count = 0

for index in range(0, len(predict)):
    if predict[index] == actual[index]:
        count += 1
        
print (count)

Failing test case input:
RTT
SUS

Expected output:
0


Actual output:
predictactual0


Fixed submission (verdict: Accepted):
predict = input()

actual = input()

count = 0

for index in range(0, len(predict)):
    if predict[index] == actual[index]:
        count += 1

print (count)
Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = list(map(int,input().split()))
b = sorted(a)
if a[2] == b[1]:
  print("Yes")
else:
  print("No")

Failing test case input:
5 -1 0

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
a = list(map(int,input().split()))
if a[0] <= a[2] and a[1] >= a[2]:
  print("Yes")
else:
  print("No")

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


a, b, c = map(int, input().split())


if (c >= a) and (c <= b) :
    print("YES")
else :
    print("NO")

Failing test case input:
-1 4 -1

Expected output:
Yes


Actual output:
YES


Fixed submission (verdict: Accepted):


a, b, c = map(int, input().split())


if (c >= a) and (c <= b) :
    print("Yes")
else :
    print("No")

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

a, b, c = [int(x) for x in sys.stdin.readline().split()]

if a <= c and b >= c:
	print('YES')
else:
	print('NO')

Failing test case input:
9 3 1

Expected output:
No


Actual output:
NO


Fixed submission (verdict: Accepted):
import sys

a, b, c = [int(x) for x in sys.stdin.readline().split()]

if a <= c and b >= c:
	print('Yes')
else:
	print('No')

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c = (int(i) for i in input().split())
if(a<=c and c<=b):
    print('YES')
else:
    print('No')
  

Failing test case input:
-4 2 -3

Expected output:
Yes


Actual output:
YES


Fixed submission (verdict: Accepted):
a,b,c = (int(i) for i in input().split())
if(a<=c and c<=b):
    print('Yes')
else:
    print('No')

Problem: p03719
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
A,B,C = input().split()
if C >= A and C <= B:
    print('YES')
else:
    print('NO')

Failing test case input:
0 2 -6

Expected output:
No


Actual output:
NO


Fixed submission (verdict: Accepted):
A,B,C = map(int, input().split())

if C >= A and C <= B:
    print('Yes')
else:
    print('No')

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c=input().split()
print("Yes" if c>=a and c<=b else "No")

Failing test case input:
-1 2 -2

Expected output:
No


Actual output:
Yes


Fixed submission (verdict: Accepted):
a,b,c=map(int,input().split())
print("Yes" if a<=c and c<=b else "No")

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





lists=list(map(int,input().split()))






if lists[0]<=lists[2] and lists[1]>=lists[2]:
        print("YES")
else:
    print("NO")


Failing test case input:
0 2 -7

Expected output:
No


Actual output:
NO


Fixed submission (verdict: Accepted):





lists=list(map(int,input().split()))






if lists[0]<=lists[2] and lists[1]>=lists[2]:
        print("Yes")
else:
    print("No")

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c = map(int, input().split(' '))
print("YES") if c >= a and c <= b else print("NO")


Failing test case input:
-2 2 -3

Expected output:
No


Actual output:
NO


Fixed submission (verdict: Accepted):
a, b, c = map(int, input().split(' '))
print("Yes") if c >= a and c <= b else print("No")
Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C = map(int, input().split())

if C >= A and C <= B:
    print('YES')
else:
    print('No')

Failing test case input:
-1 3 -1

Expected output:
Yes


Actual output:
YES


Fixed submission (verdict: Accepted):
A, B, C = map(int, input().split())

if C >= A and C <= B:
    print('Yes')
else:
    print('No')

Problem: p03719
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c=map(int,input().split())
print('Yes' if a<=b and b<=c else 'No')

Failing test case input:
-1 3 -1

Expected output:
Yes


Actual output:
No


Fixed submission (verdict: Accepted):
a,b,c=map(int,input().split())
print('Yes' if a<=c and c<=b else 'No')
Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
D = input().split()

for i in range(N,10000):
    match = False
    for s in str(i):
        if s in D:
            match = True
            break
    if not match:
        print(i)
        break

Failing test case input:
31766 1
3

Expected output:
40000


Actual output:
no output


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
D = input().split()

for i in range(N,100000):
    match = False
    for s in str(i):
        if s in D:
            match = True
            break
    if not match:
        print(i)
        break

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


N,K = input().split()
N = int(N)

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

for i in range(10001):
    if i >= N :
        if dig_check(i,d):
            print(i)
            break



Failing test case input:
17212 1
-1

Expected output:
17212


Actual output:
no output


Fixed submission (verdict: Accepted):
def dig_check(i,d):
    for k in [int(j) for j in str(i)]:
        if k in d:
            return False
    return True


N,K = input().split()
N = int(N)

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

for i in range(100001):
    if i >= N :
        if dig_check(i,d):
            print(i)
            break

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
dislike=list(map(int,input().split()))


while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        print(n)
        exit()
    n+=1

Failing test case input:
21630 1
0

Expected output:
21631


Actual output:
21630


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
dislike=list(map(int,input().split()))


while 1:
    for i in range(len(str(n))):
        if int(str(n)[i]) in dislike:
            break
        if i==len(str(n))-1:
            print(n)
            exit()
    n+=1

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums < available:
        print(i)
        break

Failing test case input:
1001 8
1 3 4 5 6 7 8 9

Expected output:
2000


Actual output:
2222


Fixed submission (verdict: Accepted):
numbers = {str(i) for i in range(10)}
N, K = map(int, input().split())
*D, = map(str, input().split())
D = set(D)
available = numbers - D
ans = 0
for i in range(N, 100000):
    nums = set(str(i))
    if nums <= available:
        print(i)
        break
Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re



input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

pattern = re.compile("|".join(D))


for ans in range(int(N), 10000):
    result = re.findall(pattern, str(ans))
    if not result:
        print(ans)
        break


Failing test case input:
34782 1
1

Expected output:
34782


Actual output:
no output


Fixed submission (verdict: Accepted):
input_1st=input()
input_2nd=input()

N, K = input_1st.split(" ")
D = input_2nd.split(" ")

for ans in range(int(N), 100000):
    flg = True
    for i in range(len(str(ans))):
        if str(ans)[i] in D:
          flg = False
          break

    if flg:
        print(ans)
        break

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
k=hoge[1]

d=[]
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,k):
	d.append(hoge[i])

payment=0
for i in range(0,10000-n+1):
	payment=n+i
	for j in range(0,k):
		if(str(d[j]) in str(payment)):
			break
		if(j==k-1):
			print(payment)
			sys.exit()

Failing test case input:
19738 1
-1

Expected output:
19738


Actual output:
no output


Fixed submission (verdict: Accepted):


import sys

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
k=hoge[1]

d=[]
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
for i in range(0,k):
	d.append(hoge[i])

payment=0
for i in range(0,100000):
	payment=n+i
	for j in range(0,k):
		if(str(d[j]) in str(payment)):
			break
		if(j==k-1):
			print(payment)
			sys.exit()

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
d = list(input().split())
ans = 100000
for i in range(n, 10001):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        if ans > i:
            ans = i
print(ans)


Failing test case input:
19727 1
0

Expected output:
19727


Actual output:
100000


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
d = list(input().split())
ans = 100000
for i in range(n, 100001):
    for j in range(k):
        if d[j] in str(i):
            break
    else:
        if ans > i:
            ans = i
print(ans)

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
D=list(map(int,input().split()))

for i in range(n,10001):
  for j in str(i):
    if int(j) in D:
      break
  else:
    print(i)
    exit()

Failing test case input:
17691 1
2

Expected output:
17691


Actual output:
no output


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
D=list(map(int,input().split()))

for i in range(n,88889):
  for j in str(i):
    if int(j) in D:
      break
  else:
    print(i)
    exit()
Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
a = list(input().split())
for i in range(n+1, 10**6):
  if all([j not in a for j in str(i)]):
 
    print(i)
    exit()

Failing test case input:
18 1
0

Expected output:
18


Actual output:
19


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
a = list(input().split())
for i in range(n, 10**6):
  if all([j not in a for j in str(i)]):
 
    print(i)
    exit()

Problem: p04039
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = [int(x) for x in input().split(' ')]
d = set(x for x in input().split(' '))

for i in range(10000):
    if set(str(i)).isdisjoint(d) and i >= n:
        print(i)
        exit()

Failing test case input:
20079 1
-1

Expected output:
20079


Actual output:
no output


Fixed submission (verdict: Accepted):
n, k = [int(x) for x in input().split(' ')]
d = set(x for x in input().split(' '))

for i in range(100000):
    if set(str(i)).isdisjoint(d) and i >= n:
        print(i)
        exit()
Problem: p02839
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
I = [int(_) for _ in open(0).read().split()]
H, W = I[:2]
A = I[2:2 + H * W]
B = I[2 + H * W:]
D = [abs(a - b) for a, b in zip(A, B)]
dp = [0] + [1] + [0] * (W - 1)
for h in range(H):
    dpo = dp
    dp = [0] * (W + 1)
    for w, d in enumerate(D[W * h:W * (h + 1)]):
        s = dp[w] | dpo[w + 1]
        dp[w + 1] = (s << d) | (s >> d)
        t = bin(s)[2:][-1 - d:][::-1]
        t += '0' * (d - len(t))
        dp[w + 1] |= int(t, 2)
for i in range(160 * 80):
    if dp[-1] & 2**i:
        print(i)
        exit()


Failing test case input:
1 3
0 10 4
151 14 1
1 2 3
3 2 6

Expected output:
144


Actual output:
143


Fixed submission (verdict: Accepted):
I = [int(_) for _ in open(0).read().split()]
H, W = I[:2]
A = I[2:2 + H * W]
B = I[2 + H * W:]
D = [abs(a - b) for a, b in zip(A, B)]
dp = [0] + [1] + [0] * (W - 1)
for h in range(H):
    dpo = dp
    dp = [0] * (W + 1)
    for w, d in enumerate(D[W * h:W * (h + 1)]):
        s = dp[w] | dpo[w + 1]
        dp[w + 1] = (s << d) | (s >> d)
        if d:
            t = bin(s)[2:][::-1][:d + 1]
            t += '0' * (d + 1 - len(t))
            dp[w + 1] |= int(t, 2)
for i in range(160 * 80):
    if dp[-1] & 2**i:
        print(i)
        exit()

Problem: p02839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    ofs=6400
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    dp[0][0]|=((1<<(ofs+x))|(1<<(ofs-x)))

    from itertools import product
    for i,j in product(range(h),range(w)):
        x=abs(A[i][j]-B[i][j])
        t=0
        if(i-1>=0):
            t|=dp[i-1][j]
        if(j-1>=0):
            t|=dp[i][j-1]
        dp[i][j]=((t<<x)|(t>>x))

    for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
        if(s=='1'):
            print(i)
            return
                    
resolve()


Failing test case input:
1 3
1 0 25
83 2 2
1 3 3
7 2 6

Expected output:
57


Actual output:
no output


Fixed submission (verdict: Accepted):

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    ofs=6400
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    dp[0][0]|=((1<<(ofs+x))|(1<<(ofs-x)))

    from itertools import product
    for i,j in product(range(h),range(w)):
        x=abs(A[i][j]-B[i][j])
        t=0
        if(i-1>=0):
            t|=dp[i-1][j]
        if(j-1>=0):
            t|=dp[i][j-1]
        dp[i][j]|=((t<<x)|(t>>x))

    for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
        if(s=='1'):
            print(i)
            return
                    
resolve()
Problem: p02839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    ofs=6400
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    dp[0][0]|=(1<<(ofs+x))|(1<<(ofs-x))

    from itertools import product
    for i,j in product(range(h),range(w)):
        x=abs(A[i][j]-B[i][j])
        t=0
        if(i-1>=0):
            t|=dp[i-1][j]
        if(j-1>=0):
            t|=dp[i][j-1]
        dp[i][j]=(t<<x)|(t>>x)

    for i,s in enumerate(bin(dp[-1][-1])[ofs:]):
        if(s=='1'):
            print(i)
            return
                    
resolve()


Failing test case input:
2 3
1 10 80
80 10 1
1 2 3
4 2 6

Expected output:
5


Actual output:
no output


Fixed submission (verdict: Accepted):

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    ofs=6400
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    dp[0][0]|=((1<<(ofs+x))|(1<<(ofs-x)))

    from itertools import product
    for i,j in product(range(h),range(w)):
        x=abs(A[i][j]-B[i][j])
        t=0
        if(i-1>=0):
            t|=dp[i-1][j]
        if(j-1>=0):
            t|=dp[i][j-1]
        dp[i][j]|=((t<<x)|(t>>x))

    for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
        if(s=='1'):
            print(i)
            return
                    
resolve()
Problem: p02839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    A=[[] for _ in range(H)]
    B=[[] for _ in range(H)]
    C=[[0]*W for _ in range(H)]
    minusdigit=80
    for i in range(H):
        A[i]=list(map(int,input().split()))
    for i in range(H):
        B[i]=list(map(int,input().split()))
    for i in range(H):
        for j in range(W):
            C[i][j]=abs(A[i][j]-B[i][j])
    dp=[[0]*W for _ in range(H)]
    dp[0][0]=((1<<minusdigit)<<C[0][0])|((1<<minusdigit)>>C[0][0])
    for i in range(1,H):
        dp[i][0]=(dp[i-1][0]<<C[i][0])|(dp[i-1][0]>>C[i][0])
    for j in range(1,W):
        dp[0][j]=(dp[0][j-1]<<C[0][j])|(dp[0][j-1]>>C[0][j])
    
    for i in range(1,H):
        for j in range(1,W):
            dp[i][j]=(dp[i-1][j]<<C[i][j])|(dp[i-1][j]>>C[i][j])|(dp[i][j-1]<<C[i][j])|(dp[i][j-1]>>C[i][j])
    ans=dp[H-1][W-1]>>minusdigit
    for i in range(len(bin(ans))-2):
        if (ans>>i)&0b1==1:
            print(i)
            exit()
    
    

if __name__ == '__main__':
    main()


Failing test case input:
1 3
0 9 133
80 14 1
1 2 3
4 2 11

Expected output:
47


Actual output:
57


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**9)
INF = 10**18


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W = map(int, input().split())
    A = [[] for _ in range(H)]
    B = [[] for _ in range(H)]
    C = [[0] * W for _ in range(H)]
    minusdigit = 80 * 80 * 2
    for i in range(H):
        A[i] = list(map(int, input().split()))
    for i in range(H):
        B[i] = list(map(int, input().split()))
    for i in range(H):
        for j in range(W):
            C[i][j] = abs(A[i][j] - B[i][j])
    dp = [[0] * W for _ in range(H)]
    dp[0][0] = ((1 << minusdigit) << C[0][0]) | ((1 << minusdigit) >> C[0][0])
    for i in range(1, H):
        dp[i][0] = (dp[i - 1][0] << C[i][0]) | (dp[i - 1][0] >> C[i][0])
    for j in range(1, W):
        dp[0][j] = (dp[0][j - 1] << C[0][j]) | (dp[0][j - 1] >> C[0][j])

    for i in range(1, H):
        for j in range(1, W):
            dp[i][j] = (dp[i - 1][j] << C[i][j]) | (dp[i - 1][j] >> C[i][j]) | (dp[i][j - 1] << C[i][j]) | (dp[i][j - 1] >> C[i][j])
    ans = dp[H - 1][W - 1]
    for i in range(len(bin(ans)) - (2 + minusdigit)):
        if (ans >> (i + minusdigit)) & 0b1 == 1 or (-i + minusdigit >= 0 and (ans >> (-i + minusdigit)) & 0b1 == 1):
            print(i)
            exit()


if __name__ == '__main__':
    main()
Problem: p02839
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys


def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):

    
    ab = [[0]*W for _ in range(H)]

    for h in range(H):
        for w in range(W):
            ab[h][w] = abs(A[h][w]-B[h][w])
    
    setlist = [set() for _ in range(H+W-1)]
    setlist[0].add(ab[0][0])
    for i in range(1,H+W-1):
        h = i
        w = 0
        while h >= 0:
            if h >= H or w>=W:
                h -= 1
                w += 1
                continue
            for num in setlist[i-1]:
                if abs(num+ab[h][w]) < 160:
                    setlist[i].add(abs(num+ab[h][w]))
                setlist[i].add(abs(num-ab[h][w]))
            h -= 1
            w += 1
    
    print(min(setlist[H+W-2]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  
    B = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  
    solve(H, W, A, B)

if __name__ == '__main__':
    main()


Failing test case input:
2 3
1 10 80
80 10 1
1 2 3
4 2 6

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):

import sys

def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
    SA=[[0]*W for i in range(H)]
    MAX = (H+W)*80
    for i in range(H):
        for j in range(W):
            SA[i][j]=abs(A[i][j]-B[i][j])

    DP=[[0 for i in range(W)] for j in range(H)]
    DP[0][0]=1<<MAX+SA[0][0]

    for i in range(H):
        for j in range(W):
            tempbit=DP[i][j]
            if i<H-1:
                DP[i+1][j]|=tempbit<<SA[i+1][j]
                DP[i+1][j]|=tempbit>>SA[i+1][j]

            if j<W-1:
                DP[i][j+1]|=tempbit<<SA[i][j+1]
                DP[i][j+1]|=tempbit>>SA[i][j+1]

    ANS=1<<MAX*2
    for i in range(MAX*2+1):
        if 1<<i & DP[-1][-1]!=0:
            ANS=min(ANS,abs(i-MAX))

    print(ANS)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  
    B = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  
    solve(H, W, A, B)

if __name__ == '__main__':
    main()
Problem: p02839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
def input():
    return sys.stdin.readline()[:-1]
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
maxd=1
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])
        maxd=max(maxd,d[i][j])
dp=[[0 for j in range(w)] for k in range(h)]
c=20000
dp[0][0] |= 1 << c+d[0][0]
for i in range(h):
    for j in range(w):
        if i+1<h:
            dp[i+1][j] |= dp[i][j] << d[i+1][j]
            dp[i+1][j] |= dp[i][j] >> d[i+1][j]
        if j+1<w:
            dp[i][j+1] |= dp[i][j] << d[i][j+1]
            dp[i][j+1] |= dp[i][j] >> d[i][j+1]
m=1000000
cnt = 0
for x in bin(dp[h-1][w-1])[2:][::-1]:
    m=min(m,abs(cnt-c))
    cnt+=1
print(m)

Failing test case input:
1 3
0 7 1
80 1 1
1 2 5
6 4 6

Expected output:
74


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
def input():
    return sys.stdin.readline()[:-1]
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
maxd=1
for i in range(h):
    for j in range(w):
        d[i][j] = abs(a[i][j]-b[i][j])
        maxd=max(maxd,d[i][j])
dp=[[0 for j in range(w)] for k in range(h)]
c=20000
dp[0][0] |= 1 << c+d[0][0]
for i in range(h):
    for j in range(w):
        if i+1<h:
            dp[i+1][j] |= dp[i][j] << d[i+1][j]
            dp[i+1][j] |= dp[i][j] >> d[i+1][j]
        if j+1<w:
            dp[i][j+1] |= dp[i][j] << d[i][j+1]
            dp[i][j+1] |= dp[i][j] >> d[i][j+1]
m=1000000
cnt = 0
for x in bin(dp[h-1][w-1])[2:][::-1]:
    if x=='1':
        m=min(m,abs(cnt-c))
    cnt+=1
print(m)
Problem: p02839
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    dp = [[set() for _ in range(W+1)] for _ in range(2)]
    dp[0][1].add(abs(A[0][0] - B[0][0]))
    for i in range(H):
        dp[(i+1) & 1] = [set() for _ in range(W+1)]
        for j in range(W):
            diff = abs(A[i][j] - B[i][j])
            dp[(i+1) & 1][j+1] |= set(map(lambda x: abs(x + diff), dp[i & 1][j+1]))
            dp[(i+1) & 1][j+1] |= set(map(lambda x: abs(x - diff), dp[i & 1][j+1]))
            dp[(i+1) & 1][j+1] |= set(map(lambda x: abs(x + diff), dp[(i+1) & 1][j]))
            dp[(i+1) & 1][j+1] |= set(map(lambda x: abs(x - diff), dp[(i+1) & 1][j]))
    print(min(dp[H & 1][W]))


if __name__ == "__main__":
    main()


Failing test case input:
1 3
4 10 90
80 14 1
1 2 3
4 2 6

Expected output:
9


Actual output:
59


Fixed submission (verdict: Accepted):
def main():
    H, W = map(int, input().split())
    N = 80 * (H+W) 
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [list(map(int, input().split())) for _ in range(H)]
    dp = [[set() for _ in range(W+1)] for _ in range(2)]
    dp[0][1].add(0)
    def ltN(x): return x <= N
    for i in range(H):
        dp[(i+1) & 1] = [set() for _ in range(W+1)]
        for j in range(W):
            diff = abs(A[i][j] - B[i][j])
            tmp = set()
            for x in dp[i & 1][j + 1]:
                tmp.add(abs(x + diff))
                tmp.add(abs(x - diff))
            for x in dp[(i+1) & 1][j]:
                tmp.add(abs(x + diff))
                tmp.add(abs(x - diff))
            dp[(i+1) & 1][j+1] = tmp
    print(min(dp[H & 1][W]))


if __name__ == "__main__":
    main()
Problem: p02839
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
r_k = 80*10
diffs = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
dp = [[[False] * r_k for _ in range(W+1)] for _ in range(H+1)]
for i in range(H+1):
    dp[i][0][0] = True
for j in range(W+1):
    dp[0][j][0] = True
for i in range(H):
    for j in range(W):
        diff = diffs[i][j]
        for k in range(r_k):
            dp[i + 1][j + 1][abs(k - diff)] = dp[i + 1][j][k] or dp[i][j +
                                                                       1][k] or dp[i + 1][j + 1][abs(k - diff)]
            if k + diff < r_k:
                dp[i + 1][j + 1][k + diff] = dp[i + 1][j][k] or dp[i][j +
                                                                      1][k] or dp[i + 1][j + 1][k+diff]

for k in range(r_k):
    if dp[H][W][k]:
        print(k)
        break


Failing test case input:
1 3
0 15 4
151 1 1
1 2 3
3 2 6

Expected output:
134


Actual output:
3


Fixed submission (verdict: Accepted):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
diffs = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
max_diff = 0
for diff in diffs:
    max_diff = max(max_diff, max(diff))
r_k = max_diff*(H+W)
dp = [[[False] * r_k for _ in range(W)] for _ in range(H)]
dp[0][0][0] = True
for i in range(H):
    for j in range(W):
        diff = diffs[i][j]
        dp_ = dp[i][j]
        if j < W-1:
            dpj = dp[i][j + 1]
            for k in range(r_k):
                if dp_[k] == True:
                    dpj[abs(k - diff)] = True
                    if k+diff<r_k:
                        dpj[k + diff] = True
        if i < H - 1:
            dpi = dp[i + 1][j]
            for k in range(r_k):
                if dp_[k] == True:
                    dpi[abs(k-diff)] = True
                    if k+diff < r_k:
                        dpi[k + diff] = True

ans = pow(80, 3)
diff = diffs[H-1][W-1]
for k, flg in enumerate(dp[H - 1][W - 1]):
    if flg:
        ans = min(ans, abs(k-diff), k+diff)
print(ans)