ZhenlongDai/ACPR huggingface dataset:
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int, input().split())
x=list(range(a,b+1))
l=[]
for i in range(c,d+1):
  if i in x:
    l.append(i)
if len(l)==0:
  print(0)
elif len(l)==1:
  print(1)
else:
  print(l[-1]-l[0])

Failing test case input:
-1 1 1 12

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
a,b,c,d=map(int, input().split())
x=list(range(a,b+1))
l=[]
for i in range(c,d+1):
  if i in x:
    l.append(i)
if len(l)==0:
  print(0)
elif len(l)==1:
  print(0)
else:
  print(l[-1]-l[0])

Problem: p03632
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())
print(min(b, d)-max(a, c))



Failing test case input:
-1 33 66 10

Expected output:
0


Actual output:
-56


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
print(0 if min(b, d)-max(a, c) < 0 else min(b, d)-max(a, c))

Problem: p03632
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,_in[0].split(' ')))  
    
    if B<C:
        cnt = 0
    else:
        cnt = min(B,D)-max(A,C)
    
    print(cnt)


Failing test case input:
4 0 0 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    A,B,C,D = list(map(int,_in[0].split(' ')))  
    
    if B<C or D<A:
        cnt = 0
    else:
        cnt = min(B,D)-max(A,C)
    
    print(cnt)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def abc070_b():
    a, b, c, d = map(int, input().split())
    
    if c > b:
        return 0
    
    if c < a < b < d:
        return b - a
    
    if a < c < b < d:
        return b - c
    
    if a < c < d < b:
        return d - c
    
    
if __name__ == '__main__':
    print(abc070_b())

Failing test case input:
-1 1 1 13

Expected output:
0


Actual output:
None


Fixed submission (verdict: Accepted):
def abc070_b():
    a, b, c, d = map(int, input().split())

    if c <= a < b <= d:
        return b - a

    if a <= c < d <= b:
        return d - c

    if a <= c < b <= d:
        return b - c

    if c <= a < d <= b:
        return d - a

    if b <= c or d <= a:
        return 0


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

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())
 
if B <= C:
    print(0)
else:
    print(min(B, D) - max(A,C))

Failing test case input:
4 0 -1 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
A, B, C, D = map(int, input().split())
a = max(0,min(B, D) - max(A,C))
print(a)

Problem: p03632
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
A,B,C,D = map(int,input().rstrip().split(" "))
print(min(B,D) - max(A,C))


Failing test case input:
0 -1 3 -1

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
A,B,C,D = map(int,input().rstrip().split(" "))
print(max(min(B,D) - max(A,C),0))
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,D = map(int, input().split())
if B <= C:
    print("0")
else:
    print(min(B,D) - max(A,C))


Failing test case input:
4 0 -1 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
A,B,C,D = map(int, input().split())
if B <= C:
    print("0")
else:
    print(max(0, min(B,D) - max(A,C)))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
l={i for i in range(a,b+1)}&{i for i in range(c,d+1)}
print(len(l)-1)

Failing test case input:
-2 -5 14 -1

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
l={i for i in range(a,b+1)}&{i for i in range(c,d+1)}
if not l:
  print(0)
else:
  print(len(l)-1)

Problem: p03632
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
A,B,C,D = map(int, input().split())

if B<=C:
  ans = 0
elif A<=C and D<=B: 
  ans = D-C
elif A>C and D>B:
  ans = B-A
elif A<=C and B<=D:
  ans = B-C
else:
  ans = C-B
print(ans)

Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
-2


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

if B<=C:
  ans = 0
elif D<=A:
  ans = 0
  
elif A<=C and D<=B: 
  ans = D-C
elif A>=C and D>=B:
  ans = B-A

elif A<=C and B>=C and B<=D:
  ans = B-C
else:
  ans = D-A
print(ans)

Problem: p03632
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

import sys


def solve(A: int, B: int, C: int, D: int):
    if C > B:
        print(0)
        return
    if C == B:
        print(1)
        return
    s = max(A, C)
    e = min(B, D)
    print(e - s)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    D = int(next(tokens))  
    solve(A, B, C, D)


if __name__ == "__main__":
    main()


Failing test case input:
-1 0 0 17

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):

import sys


def solve(A: int, B: int, C: int, D: int):
    s = max(A, C)
    e = min(B, D)
    print(max(e - s, 0))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    D = int(next(tokens))  
    solve(A, B, C, D)


if __name__ == "__main__":
    main()

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())
print(max(0, min(b-c, d-a)))

Failing test case input:
0 148 36 100

Expected output:
64


Actual output:
100


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
print(max(0, min(
  min(b-c, d-c),
  min(d-a, b-a))))
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d = map(int,input().split())
if b<=c or a>=d :
  print(0)
else:
  if (a<=c and b<d) or (a<c and b<=d):
    print("a",b-c)
  elif a<=c and b>d:
    print("b",d-c)
  elif a>c and b<=d:
    print("c",b-a)
  elif a==c and b==d:
    print(0)

Failing test case input:
-1 98 66 83

Expected output:
17


Actual output:
b 17


Fixed submission (verdict: Accepted):
a,b,c,d = map(int,input().split())
if b<=c or a>=d:
  print(0)
else:
  if a<=c and b<=d:
    print(b-c)
  elif a<=c and b>d:
    print(d-c)
  elif a>=c and b<=d:
    print(b-a)
  elif a>=c and b>d:
    print(d-a)

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


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

if b <= c or a==b or c==d:
  print(0)
else:
  print(min(b,d)-max(a,c))


Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
-2


Fixed submission (verdict: Accepted):


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

if b <= c or a==b or c==d or d <= a:
  print(0)
else:
  print(min(b,d)-max(a,c))

Problem: p03632
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a,b,c,d = map(int, input().split())

if (b<=c)|(d<=a):
    print(0)
else:
    if (a<=c)&(d<=b):
        print(d-c)
    else:
        print(c-b)

Failing test case input:
-1 2 1 10

Expected output:
1


Actual output:
-1


Fixed submission (verdict: Accepted):
a,b,c,d = map(int, input().split())

if (b<=c)|(d<=a):
    print(0)
else:
    if (a<=c)&(b<=d):
        print(b-c)
    elif (c<=a)&(d<=b):
        print(d-a)
    else:
        print(min(d-c,b-a))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())
if a > c:
    a, b, c, d = c, d, a, b
if b <= c:
    print(0)
else:
    if b <= d:
        print(b - c)
    else:
        print(c - d)


Failing test case input:
16 90 28 58

Expected output:
30


Actual output:
-30


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
if a > c:
    a, b, c, d = c, d, a, b
if b <= c:
    print(0)
else:
    if b <= d:
        print(b - c)
    else:
        print(d - c)

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

A,B,C,D= map(int,input().split())
if B < C:
    print(0)
    exit()
if A <= C:
    start =C
else:
    start =A
if B <=D:
    end =B
else:
    end =D
print(end-start)

Failing test case input:
4 0 0 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):

A,B,C,D= map(int,input().split())
if B < C:
    print(0)
    exit()
if D < A:
    print(0)
    exit()
if A <= C:
    start =C
else:
    start =A
if B <=D:
    end =B
else:
    end =D
print(end-start)
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())

if b <= c or d <= a:
    print(0)
elif a <= b:
    if c <= d:
        print(b-c)
    else:
        print(d-c)
else:
    if c <= d:
        print(b-a)
    else:
        print(c-b)

Failing test case input:
16 90 28 58

Expected output:
30


Actual output:
62


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())

if b <= c or d <= a: 
    print(0)
elif a <= c:
    if b <= d: 
        print(b-c)
    else: 
        print(d-c)
else:
    if b <= d: 
        print(b-a)
    else: 
        print(d-a)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d = map(int,input().split())
if b <= c:
    print(0)
elif a<=c<b:
    print(min(b,d)-c)
elif c<=a:
    print(min(b,d)-a)

Failing test case input:
4 0 -1 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
a,b,c,d = map(int,input().split())
if b <= c or d<=a:
    print(0)
elif a<=c<b:
    print(min(b,d)-c)
elif c<a:
    print(min(b,d)-a)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())
 
ans = 0
 
for i in range(max(A, B, C, D)+1):
  if (A <= i and i <= B) and (C <= i and i <= D):
    ans += 1

if ans <= 1:
  print(ans)
elif A == C and B == D:
  print(B - A)
else:
  print(ans)

Failing test case input:
-1 0 0 0

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
A, B, C, D = map(int, input().split())
 
ans = 0
 
for i in range(max(A, B, C, D)+1):
  if (A <= i and i <= B) and (C <= i and i <= D):
    ans += 1
 
if ans <= 1:
  print(0)
elif A == C and B == D:
  print(ans - 1)
else:
  print(ans-1)

Problem: p03632
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
a,b,c,d = map(int,input().split())
if c<=a:
    if d<=a:
        print(0)
    elif d<=b:
        print(c-a)
    else:
        print(b-a)
elif c<=b:
    if d<=b:
        print(d-c)
    else:
        print(b-c)
else:
    print(0)


Failing test case input:
1 11 1 6

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
a,b,c,d = map(int,input().split())
if c<=a:
    if d<=a:
        print(0)
    elif d<=b:
        print(d-a)
    else:
        print(b-a)
elif c<=b:
    if d<=b:
        print(d-c)
    else:
        print(b-c)
else:
    print(0)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d = map(int,input().split())
if b<=c:
  print(0)
elif a<=c and c<=b<=d:
  print(b-c)
elif a<=c and d<=b:
  print(d-c)
elif c<=a:
  print(min(d-a,b-a))
else:
  print(0)

Failing test case input:
4 1 -1 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
a,b,c,d = map(int,input().split())
if b<=c or d<=a:
  print(0)
elif a<=c :
  print(min(b-c,d-c))
elif c<a:
  print(min(d-a,b-a))
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())

ans = 0
if a <= c <= b:
  _min = min(b, d)
  ans = _min - c
print(ans)  

Failing test case input:
1 6 -1 4

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
ans = 0

_min = min(b, d)
_max = max(a, c)
ans = _min - _max
if ans < 0:
  print(0)
else:
  print(ans)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,D = map(int,input().split())
if B <= C :
    print(0)
if D <= A :
    print(0)
if A <= D and C <= B :
    if A <= C  and D <= B :
        print(D-C)
    elif C <= A and B <= D :
        print(B-A)
    elif (D-A) > (B-C) :
        print(B-C)
    else :
        print(D-A)
        

Failing test case input:
0 -6 4 -13

Expected output:
0


Actual output:
0
0


Fixed submission (verdict: Accepted):
A,B,C,D = map(int,input().split())
if B <= C :
    print(0)
elif D <= A :
    print(0)
elif A <= D and C <= B :
    if A <= C  and D <= B :
        print(D-C)
    elif C <= A and B <= D :
        print(B-A)
    elif (D-A) > (B-C) :
        print(B-C)
    else :
        print(D-A)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())
print(max(0,max(a,c)-min(b,d)))

Failing test case input:
0 33 23 101

Expected output:
10


Actual output:
0


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
print(max(0,min(b,d)-max(a,c)))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())

if A==C:
    print(min(B-A,D-C))

elif A<C:
    if B>=D:
        print(D-C)
    elif B<=D:
        print(B-C)

else:
    if D>=B:
        print(B-A)

    elif D<=B:
        print(D-A)               


Failing test case input:
-1 -9 3 -1

Expected output:
0


Actual output:
-12


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

if A==C:
    print(min(B-A,D-C))

elif A<C:
    if B>=D:
        print(max(0,D-C))
    elif B<=D:
        print(max(0,B-C))

else:
    if D>=B:
        print(max(B-A,0))

    elif D<=B:
        print(max(D-A,0))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d = map(int, input().split())
print(max(0, min(b,d) - min(a,c)))

Failing test case input:
-1 0 0 17

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
a,b,c,d = map(int, input().split())
print(max(0, min(b,d) - max(a,c)))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())
if A < C and B < D:
    print(B - C)
elif C <= A and B < D:
    print(B - A)
elif A < C and D <= B:
    print(D - C)
elif C <= A and D <= B:
    print(D - A)
else:
    print(0)

Failing test case input:
-1 0 1 12

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
A, B, C, D = map(int, input().split())
if A < C and B < D:
    print(max(0, B - C))
elif C <= A and B < D:
    print(max(0, B - A))
elif A < C and D <= B:
    print(max(0, D - C))
else:
    print(max(0, D - A))
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
if b<=c or d<=a:
    print(0)
else:
    print(abs(b-c))


Failing test case input:
0 6 1 5

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
if -max(a,c)+min(b,d)>=0:
    print(-max(a,c)+min(b,d))
else:
    print(0)

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

a,b,c,d = map(float, input().split())

a,b = max(a,c), min(b,d)

a = max(0.0, b-a)

print(a)


Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
0.0


Fixed submission (verdict: Accepted):

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

a,b = max(a,c), min(b,d)

a = max(0, b-a)

print(a)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d = map(int,input().split())

print(min(b, d) - max(a, c))

Failing test case input:
-1 -9 4 -1

Expected output:
0


Actual output:
-13


Fixed submission (verdict: Accepted):
a,b,c,d = map(int,input().split())

e = min(b, d) - max(a, c)
print(e if e >= 0 else 0)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = input().split(' ')
A, B, C, D = int(A), int(B), int(C), int(D)
if C - B < 0 or D - A < 0:
    print(0)
if A < C:
    print(B - C)
else:
    print(D - A)

Failing test case input:
19 90 29 58

Expected output:
29


Actual output:
0
61


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

if B < C or D < A:
    print(0)
else:
    print(min(D, B) - max(C, A))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map( int, input().split())
print(min(b,d) - max(a,c))

Failing test case input:
-1 -2 2 -2

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
a, b, c, d = map( int, input().split())
d = min(b,d) - max(a,c)
print(d if d>0 else 0)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
if b<c or a>d:
    print(0)
else:
    print(min(b-c,d-a))


Failing test case input:
10 90 20 80

Expected output:
60

Actual output:
70


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
if b<c or a>d:
    print(0)
else:
    print(min(b-c,d-a,b-a,d-c))

Problem: p03632
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
print(max(b-c,d-a,0))

Failing test case input:
16 90 33 58

Expected output:
25


Actual output:
57


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
print(max(min(b,d)-max(a,c),0))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
start=min(a,c)
end=min(b,d)
print(end-start if end-start > 0 else 0)

Failing test case input:
19 90 29 58

Expected output:
29


Actual output:
39


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
start=max(a,c)
end=min(b,d)
print(end-start if end-start > 0 else 0)
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

if b <= c:
  print(0)
else:
  print(min(b,d)-max(a,c))


Failing test case input:
4 0 -1 0

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):


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

if b <= c or a==b or c==d or d <= a:
  print(0)
else:
  print(min(b,d)-max(a,c))

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


A, B, C, D = map(int, input().split())
print(min(B, D) - max(A, C))

Failing test case input:
1 0 0 0

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):


A, B, C, D = map(int, input().split())
print(max(min(B, D) - max(A, C), 0))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
if a < c and b < d:
    print(b-c)
elif a < c and b >= d:
    print(d-c)
elif a >= c and b < d:
    print(b-a)
elif a >= c and b >= d:
    print(d-a)
else:
    print(0)

Failing test case input:
-2 -9 5 -1

Expected output:
0


Actual output:
-14


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
if a <= c < b <= d:
    print(b-c)
elif c <= a < d <= b:
    print(d-a)
elif a <= c < d <= b:
    print(d-c)
elif c <= a < b <= d:
    print(b-a)
elif b <= c or d <= a:
    print(0)
else:
    print(0)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
listA = list(map(int, input().split()))
if listA[1] < listA[2]:
    print(0)
else:
    listA.sort()
    print(listA[2]-listA[1])

Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
listA = list(map(int, input().split()))
if min(listA[3], listA[1])-max(listA[0], listA[2])<0:
    print(0)
else:
    print(min(listA[3], listA[1])-max(listA[0], listA[2]))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())
if A < C and B < D:
    print(D - A)
elif C <= A and B < D:
    print(D - C)
elif A < C and D <= B:
    print(B - A)
else:
    print(B - C)

Failing test case input:
-1 2 66 10

Expected output:
0


Actual output:
11


Fixed submission (verdict: Accepted):
A, B, C, D = map(int, input().split())
if A < C and B < D:
    print(max(0, B - C))
elif C <= A and B < D:
    print(max(0, B - A))
elif A < C and D <= B:
    print(max(0, D - C))
else:
    print(max(0, D - A))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,D = map(int,input().split())
line1 = list(range(A,B+1))
line2 = list(range(C,D+1))
line1_line2_and = set(line1) & set(line2)
line1_line2_and_list = list(line1_line2_and)
botton = len(line1_line2_and_list) -1
print(botton)


Failing test case input:
0 -6 4 -13

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):
A,B,C,D = map(int,input().split())
line1 = list(range(A,B))
line2 = list(range(C,D))
line1_line2_and = set(line1) & set(line2)
line1_line2_and_list = list(line1_line2_and)
botton = len(line1_line2_and_list) 
print(botton)
Problem: p03632
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
A,B,C,D=map(int,input().split())
s=max(A,B)
e=min(C,D)
if s<e:
  print(e-s)
else:
  print(0)

Failing test case input:
1 75 25 100

Expected output:
50


Actual output:
0


Fixed submission (verdict: Accepted):
A,B,C,D=map(int,input().split())
s=max(A,C)
e=min(B,D)
if s<e:
  print(e-s)
else:
  print(0)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())
ans = 0
if a < c < b < d:
    ans = b-c
if c < a < d < b:
    ans = d-a
if a < c < d < b:
    ans = d-c
if c < a < b < d:
    ans = b-a
print(ans)

Failing test case input:
1 11 1 6

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
ans = 0
if a <= c <= b <= d:
    ans = b-c
if c <= a <= d <= b:
    ans = d-a
if a <= c <= d <= b:
    ans = d-c
if c <= a <= b <= d:
    ans = b-a
print(ans)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())
if(B<=C):
    print("0")
elif(A<=C):
    if(B<=D):
        print(B-C)
    else:
        print(D-C)
elif(C<A):
    if(B<=D):
        print(B-A)
    else:
        print(D-A)

Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
-2


Fixed submission (verdict: Accepted):
A, B, C, D = map(int, input().split())
if(B<=C or D<=A):
    print("0")
elif(A<=C):
    if(B<=D):
        print(B-C)
    else:
        print(D-C)
elif(C<A):
    if(B<=D):
        print(B-A)
    else:
        print(D-A)

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

a, b, c, d = map(int, input().split())
if(c < b):
    if(d <= b):
        if(d <= a):
            time = 0
        else:
            time = d - c
    else:
        time = b - c
else:
    time = 0
print(time)


Failing test case input:
1 6 -1 4

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):

a, b, c, d = map(int, input().split())
if(c < b):
    if(d <= b):
        if(d <= a):
            time = 0
        elif(c < a):
            time = d - a
        else:
            time = d - c
    elif (c < a):
        time = b - a
    else:
        time = b - c
else:
    time = 0
print(time)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A, B, C, D = map(int, input().split())

if A >= C:
    start = A
else:
    start = C

if B >= D:
    end = D
else:
    end = B

print(end - start)


Failing test case input:
1 0 0 0

Expected output:
0


Actual output:
-1


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

if A >= C:
    start = A
else:
    start = C

if B >= D:
    end = D
else:
    end = B

time = end - start

if time < 0:
    time = 0

print(time)
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,D = map(int, input().split())
if D<A or B<C: print("0")
elif D-A < B-C: print(D-A)
else: print(B-C)

Failing test case input:
10 90 20 58

Expected output:
38


Actual output:
48


Fixed submission (verdict: Accepted):
A,B,C,D = map(int, input().split())
if D<A or B<C: print("0")
elif A<C and D<B: print(D-C)
elif C<A and B<D: print(B-A)
elif D-A < B-C: print(D-A)
else: print(B-C)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
print(min(b,d)-max(a,c))

Failing test case input:
0 -3 2 -2

Expected output:
0


Actual output:
-5


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
print(max(min(b,d)-max(a,c),0))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
print(max(0,max(a,c)-min(b,d)))

Failing test case input:
0 98 66 99

Expected output:
32


Actual output:
0


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c)))

Problem: p03632
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
a,b,c,d=map(int,input().split());print(min(b,d)-max(a,c))

Failing test case input:
0 -1 3 -1

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split());print(max(0,min(b,d)-max(a,c)))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split(" "))

print(max(0, b-c))

Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split(" "))

print(max(0, min(b, d) - max(a, c)))

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a=list(map(int,input().split()))
if a[1] < a[2]:
    print(0)
else:
    x = sorted(a)
    print(x[2]-x[1])

Failing test case input:
2 1 -1 0

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
a=list(map(int,input().split()))
if a[1] < a[2] or a[3] < a[0]:
    print(0)
else:
    x = sorted(a)
    print(x[2]-x[1])

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
if -max(a,c)+min(b,d)>=0:
    print(max(a,c)-min(b,d))
else:
    print(0)


Failing test case input:
1 6 -1 4

Expected output:
3


Actual output:
-3


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
if -max(a,c)+min(b,d)>=0:
    print(-max(a,c)+min(b,d))
else:
    print(0)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, d = map(int, input().split())
print(min(0, min(b,d) - max(a,c)))

Failing test case input:
-2 -9 5 -1

Expected output:
0


Actual output:
-14


Fixed submission (verdict: Accepted):
a, b, c, d = map(int, input().split())
print(max(0, min(b,d) - max(a,c)))
Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,d=map(int,input().split())
print(a,b,c,d)
al=[]
bl=[]
for i in range(a,b+1):
    al.append(i)
for i in range(c,d+1):
    bl.append(i)
albl=set(al)&set(bl)
if len(albl)==0:
    print(0)
else:
    print(len(albl)-1)

Failing test case input:
-1 -2 1 -2

Expected output:
0


Actual output:
-1 -2 1 -2
0


Fixed submission (verdict: Accepted):
a,b,c,d=map(int,input().split())
al=[]
bl=[]
for i in range(a,b+1):
    al.append(i)
for i in range(c,d+1):
    bl.append(i)
albl=set(al)&set(bl)
if len(albl)==0:
    print(0)
else:
    print(len(albl)-1)

Problem: p03632
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
from itertools import groupby

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

if b < c or d < a:
    print(0)
elif b >= c and d <= b:
    print(d-c)
elif a >= c and b <= d:
    print(b-a)
elif a >= c:
    print(d-a)
elif c < a:
    print(b-c)

Failing test case input:
-1 0 0 4

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
from sys import stdin
from itertools import groupby

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

if b < c or d < a:
    print(0)
elif b >= d and c >= a:
    print(d-c)
elif a >= c and b <= d:
    print(b-a)
elif a >= c:
    print(d-a)
elif c > a:
    print(b-c)
Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d = map(int,input().split())
v = x
if v >=k:
    print(abs(x)-k*d)
else:
    k-=v
    if k%2:
        print(abs(abs(x)-(v+1)*d))
    else:
        print(abs(x)-v*d)

Failing test case input:
1000011000011111 1100110110000001 1000111000001000

Expected output:
99999989889


Actual output:
-1000122001233111244310011099889


Fixed submission (verdict: Accepted):
x,k,d = map(int,input().split())
v = abs(abs(x)
w = abs(x)%d
if v >=k:
    print(abs(abs(x)-k*d))
else:
    k-=v
    if k%2:
        print(abs(w-d))
    else:
        print(w)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) > abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = abs(x)/d
    k_2 = k - kaisuu
    if k_2/2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = (abs(x) - d*kaisuu) - d
print(ans)


Failing test case input:
1000011100011110 1001111111110011 1010101000001010

Expected output:
10089899989900


Actual output:
-1010101000001010.0


Fixed submission (verdict: Accepted):
x,k,d = input().split()
x = int(x)
k = int(k)
d = int(d)
ans = 0
if abs(x) >= abs(k*d):
    ans =  abs(x) - abs(k*d)
else:
    kaisuu = int(abs(x)/d)
    k_2 = k - kaisuu
    if k_2%2 == 0:
        ans = abs(x) - d*kaisuu 
    else:
        ans = abs((abs(x) - d*kaisuu) - abs(d))
print(int(ans))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x, k, d = map(int, input().split())

x = abs(x)
k = k - int(x/d)
a = x - int(x/d)*d
if k % 2 == 0:
    ans = a
else:
    ans = abs(a - d)

print(ans)

Failing test case input:
13 0 3

Expected output:
13


Actual output:
1


Fixed submission (verdict: Accepted):
x, k, d = map(int, input().split())

x = abs(x)
kk = k - int(x/d)
if kk <= 0:
    print(x - k * d)
    exit()

a = x - int(x/d)*d
if kk % 2 == 0:
    ans = a
else:
    ans = abs(a - d)

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X,K,D = [int(x) for x in input().split()]

if abs(X) >= K * D:
    print(abs(X) - K * D)
else:
    K = K - int(abs(X) / D)
    X = int(abs(X) % D)
    if int(abs(X) % D) >= int(D / 2):
        if K % 2 == 0:
            print(X)
        else:
            print(D - X)
    else:
        print(X)

Failing test case input:
1000100100000000 1000101000000000 1000000001000000

Expected output:
999899902000000


Actual output:
100099000000


Fixed submission (verdict: Accepted):
X,K,D = [int(x) for x in input().split()]

if abs(X) >= K * D:
    print(abs(X) - K * D)
else:
    K = K - int(abs(X) / D)
    X = int(abs(X) % D)
    if X >= int(D / 2):
        if K % 2 == 0:
            print(X)
        else:
            print(D - X)
    else:
        if K % 2 != 0:
            print(D - X)
        else:
            print(X)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = map(int, input().split())
 
if (x - k*d > 0 and x > 0) or (x + k*d < 0 and x < 0):
    print(abs(x) - k*d )
else:
    if (x % d == 0) and (k % 2 == 0):
        print(abs(x))
    elif (x % d == 0) and (k % 2 == 1):
        print(0)
    elif (x - (x % d)) % d == k % 2:
        print(x % d)
    else:
        print(d - x % d)

Failing test case input:
1100100101000000 1010100001000001 1001000000001000

Expected output:
99100100999000


Actual output:
901899899002000


Fixed submission (verdict: Accepted):
x, k, d = map(int, input().split())
if (x - k*d > 0 and x > 0) or (x + k*d < 0 and x < 0):
    print(abs(x) - k*d )
else:
    if x % d == 0:
        if ((x/d) % 2) == (k % 2):
            print(0)
        else:
            print(d)
    else:
        y = abs(x)
        if (y % d < d - (y % d) and ((y - (y % d)) / d) % 2 == k % 2) or (y % d > d - (y % d) and ((y - (y % d)) / d) % 2 == k % 2):
            print(y % d)
        else:
            print(d - (y % d))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = map(int,input().split())

kd = k * d

if(x + kd < 0):
    print(0 - x - kd)
elif(x - kd > 0):
    print(x - kd)
else:
    if(x < 0):
        x *= -1
    xd = x % (d*2)
    xd2 = d*2 - xd
    print(min(xd,xd2))


Failing test case input:
1100111001010001 1010100001101001 1011001000101011

Expected output:
89110000908990


Actual output:
921890999192021


Fixed submission (verdict: Accepted):
x,k,d = map(int,input().split())

kd = k * d

if(x + kd < 0):
    print(0 - x - kd)
elif(x - kd > 0):
    print(x - kd)
else:
    if(x < 0):
        x *= -1
    if(k%2 == 1):
        x += d
    xd = x % (d*2)
    xd2 = d*2 - xd
    print(min(xd,xd2))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):



def main():
    X, K, D = map(int, input().split())
    r = X
    for i in range(D):
        if r > 0:
            r -= K
        else:
            if (D - i - 1) % 2 == 0:
                r = K
            break
    print(abs(r))


if __name__ == "__main__":
    main()


Failing test case input:
1101011100010001 1010111000110001 0110001100110000

Expected output:
109001001199999


Actual output:
919210900210001


Fixed submission (verdict: Accepted):


import math


def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    n = math.ceil(x / d)
    r = 0
    if n > k:
        r = x - (k * d)
    else:
        r = x - (n * d)
        k2 = k - n
        if k2 % 2 == 1:
            r += d
    print(abs(r))


if __name__ == "__main__":
    main()
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):


X,K,D=map(int,input().split())

move=X
A=X-move*D
B=X-(move+1)*D


if move+1<=K:
    if (K-(move+1))%2==0:
        print(abs(B))
    else:
        print(abs(A))
else:
    print(X-K*D)



Failing test case input:
1100110100000001 1010101001100001 1110001000001000

Expected output:
9890900000999


Actual output:
-1121213121323011210892000000999


Fixed submission (verdict: Accepted):


X,K,D=map(int,input().split())

move=min(abs(X)
ans=abs(X)-move*D

if move==K:
    print(ans)
else:
    if (K-move)%2==0:
        print(ans)
    else:
        print(abs(ans-D))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
X, K, D = map(int, input().split())

if X < 0: X = -X
ans = 0
if X - K*D >= 0:
  ans = X - K*D
else:
  K = K - math.floor(X / D)
  if K % 2 == 0: 
    ans = X - K*D
  else: 
    ans = D - (X - K*D)
    
print(ans)

Failing test case input:
1000111101000000 1010100001000001 1001000000001011

Expected output:
888899001011


Actual output:
1011110101002022212989910002022


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

X = abs(X)
ans = 0
if X - K*D >= 0:
  ans = X - K*D
else:
  count = X 
  K = K - (X 
  if K % 2 == 0: 
    ans = X - count*D
  else: 
    ans = D - (X - count*D)
    
print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

d = int(abs(X)/D)
if X > 0:
    r = X - d*D
    if abs(r-D) < abs(r):
        r = r-D
    min_count = int((X-r)/D)
else:
    r = X + d*D
    if abs(r+D) < abs(r):
        r = r+D
    min_count = int(abs(X-r)/D)

if K < min_count:
    print(int(abs(X) - K*D))
else:
    if (K - min_count) % 2 == 0:
        print(int(r))
    else:
        print(int(abs(r-D)))


Failing test case input:
1101011100010001 1010100000110001 1110001000010000

Expected output:
8989899999999


Actual output:
-8989899999999


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

d = int(abs(X)/D)
if X > 0:
    r = X - d*D
    if abs(r-D) < abs(r):
        r = r-D
    min_count = int((X-r)/D)
else:
    r = X + d*D
    if abs(r+D) < abs(r):
        r = r+D
    min_count = int(abs(X-r)/D)

if K < min_count:
    print(int(abs(X)) - K*D)
else:
    if (K - min_count) % 2 == 0:
        print(int(abs(r)))
    else:
        print(int(abs(abs(r)-D)))
Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    if mod == 0:
        if q % 2 == 0:
            ans = mod
        else:
            ans = D
    else:
        if q % 2 == 0:
            ans = mod
        else:
            ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1100110100000001 1010101001100001 1110001000001000

Expected output:
9890900000999


Actual output:
1100110100000001


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

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
X, K, D = map(int, input().split())
X = abs(X)

if X-K*D >= 0:
    print(X-K*D)
    sys.exit()

ans = X%D
ans2 = abs(ans-D)
print(min(ans, ans2))


Failing test case input:
1101011100010101 1010111000110011 0110001100110000

Expected output:
109001001199899


Actual output:
1000098910101


Fixed submission (verdict: Accepted):
import sys
X, K, D = map(int, input().split())
X = abs(X)

if X-K*D >= 0:
    print(X-K*D)
    sys.exit()

ans = X % D
K=K-(X
if K%2==0:
    print(ans)
else:
    print(abs(ans-D))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D > K):
  print(X-D*K)
else:
  if(int(X/D)%2 == 0):
    print(min_pos)
  else:
    print(abs(min_neg))

Failing test case input:
1000011101011000 1000111000110011 1110101000010010

Expected output:
110089898999010


Actual output:
1000011101011000


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

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D >= K):
  print(X-D*K)
else:
  if((K - (X-min_pos)/D)%2 == 0):
    print(min_pos)
  else:
    print(abs(min_neg))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
x,k,d=map(int,input().split())

x=abs(x)
ans=0
if x/d>k:
  ans=x-k*d
else:
  e= x/d
  k-=e
  x-=e*d
  if k%2==1:
    ans=abs(x-d)
  else:
    ans=x

print(ans)

Failing test case input:
1100111001000001 1010100001101001 1011001000000010

Expected output:
89110000999991


Actual output:
0.0


Fixed submission (verdict: Accepted):
x,k,d=map(int,input().split())

x=abs(x)
ans=0
if x>=d*k:
  ans=x-k*d
else:
  e= int(x/d)
  k-=e
  x-=e*d
  if k%2==1:
    x=abs(x-d)
  ans=x

print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

X = abs(X)

n = round(X/D)

if K<=n:
    ans = abs(X-K*D)
else:
    tmp = X-D*n
    if (K-n)%2==0:
        ans = abs(tmp)
    else:
        ans = abs(tmp-D)

print(ans)

Failing test case input:
1101110100000001 1010101001100000 1110001000000000

Expected output:
1101110100000001


Actual output:
1118891899999999


Fixed submission (verdict: Accepted):
import math

X, K, D = map(int, input().split())

X = abs(X)


n = math.floor(X/D)

if K<=n:
    ans = abs(X-K*D)
else:
    tmp = X-D*n
    if (K-n)%2==0:
        ans = abs(tmp)
    else:
        ans = abs(tmp-D)

print(ans)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

import math
X, K, D = list(map(int, input().split(" ")))

x = abs(X)
k = int(math.floor(x/D))
if X==K==D:
    print(X)
    exit()
elif k>=K:
    print(abs(x - K*D))
    exit()
x -= k*D
if K%2==0:
    print(abs(x))
else:
    print(abs(x - D))

Failing test case input:
1001011101010101 1010111000110011 0110101000010010

Expected output:
10102100920011


Actual output:
99998899089999


Fixed submission (verdict: Accepted):

import math
X, K, D = list(map(int, input().split(" ")))

x = abs(X)
k = int(math.floor(x/D))
if k>=K:
    print(abs(x - K*D))
    exit()
x -= k*D
if (K-k)%2==0:
    print(abs(x))
else:
    print(abs(x - D))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin
input = stdin.readline
X, K, D = map(int, input().split())

A=min(int((X/D+K)/2),K)
j=0
k=X
for i in range(A-1,A+1):
    j=abs(-K*D+2*i*D+X)
    if abs(j)<=abs(k) :k=abs(j)

print(k)


Failing test case input:
7 6 3

Expected output:
1


Actual output:
7


Fixed submission (verdict: Accepted):
from sys import stdin
input = stdin.readline
X, K, D = map(int, input().split())
A=int((K-X/D)/2)
if 0<=A and A<=K:print(min(abs(-K*D+2*A*D+X),abs(-K*D+2*(A+1)*D+X)))
else:print(min(abs(X+K*D),abs(X-K*D)))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = map(int, input().split())

mod1 = abs(x) % d
mod2 = mod1 - d
mod = min(mod1, abs(mod2))
modx = max(mod1, abs(mod2))
x1 = abs(x)

a = (x1-mod)/d

if mod1+k*d <= x1:
    print(x-k*d)
elif (k-a) % 2 == 0:
    print(mod)
else:
    print(modx)

Failing test case input:
1000011101011001 1000111000110011 1110101000010010

Expected output:
110089898999009


Actual output:
1000011101011001


Fixed submission (verdict: Accepted):
x, k, d = map(int, input().split())

x1 = abs(x)
mod1 = x1 % d
mod2 = mod1 - d
if mod1 > abs(mod2):
    mod = mod2
    modx = mod1
else:
    mod = mod1
    modx = mod2

a = abs(x1-mod) / d 

if k*d < x1-mod:
   print(x1-k*d)
elif (k-a) % 2 == 0:
    print(abs(mod))
else:
    print(abs(modx))
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
X, K, D = map(int, input().split())

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D >= K):
  print(X-D*K)
else:
  if(int(X/D)%2 == 0):
    print(min_pos)
  else:
    print(abs(min_neg))
    

Failing test case input:
1101011100010001 1010111000110001 1110001100010000

Expected output:
8989999999999


Actual output:
1101011100010001


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

X= abs(X)
min_pos = X%D
min_neg = min_pos - D

if(X/D >= K):
  print(X-D*K)
else:
  if((K - (X-min_pos)/D)%2 == 0):
    print(min_pos)
  else:
    print(abs(min_neg))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x, k, d = list(map(int, input().split()))

x = abs(x)
p = 0

if x ==0:
    print(0)
    exit()

if x/d > k:
    p = abs(x-(k*d))

else:
    p = x%d
    if (k - x/d)%2 == 1:
        p = abs(p-d)
print(p)

Failing test case input:
1000011000111111 1000111111000001 1010101000001010

Expected output:
10089999889899


Actual output:
1000011000111111


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

x = abs(x)
p = 0

if x/d >= k:
    p = x-(k*d)

else:
    p = x%d
    if (k - int(x/d))%2 == 1:
        p = p-d
print(abs(p))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d=map(int,input().split())

k_min=x
if k_min>=k:
  k_min=k

if x>0:
  d_min=x-((k_min)*d)
else:
  d_min=x+(-(k_min)*d)
dk=k-k_min
if dk%2==0:
  print(d_min)
else:
  print(abs(min(d_min+d,d_min-d)))

Failing test case input:
1101110100000001 1010101001100000 1110001000000000

Expected output:
1101110100000001


Actual output:
-1121213121321999998889899999999


Fixed submission (verdict: Accepted):
x,k,d=map(int,input().split())

k_min=abs(x
if k_min>=k:
  k_min=k
if x>0:
  d_min=x-((k_min)*d)
else:
  d_min=x+((k_min)*d)

dk=k-k_min
if dk%2==0:
  print(abs(d_min))
else:
  print(min(abs(d_min+d),abs(d_min-d)))

Problem: p02584
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
X, K, D = map(int, input().split())

q, mod = divmod(abs(X), abs(D))

ans = 0
if q <= K:
    if mod == 0:
        if q % 2 == 1:
            ans = D
        else:
            ans = mod
    else:
        if q % 2 == 0:
            ans = mod
        else:
            ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)


Failing test case input:
1000011100011100 1001111100110011 1010101000011010

Expected output:
10089899999910


Actual output:
1000011100011100


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

q, mod = divmod(abs(X), abs(D))

ans = 0
if q < K:
    amari = K - q
    l = amari % 2
    if l == 0:
        ans = mod
    else:
        ans = D - mod
else:
    div = q - K
    ans = div * D + mod

print(ans)
Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d=list(map(int,input().split()))
print(x,k,d)
result=abs(x)-k*d

if result<0:
    result%=2
print(result)

Failing test case input:
1100100101000000 1010100001000001 1001000000001001

Expected output:
99100100998999


Actual output:
1100100101000000 1010100001000001 1001000000001001
1


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

result=abs(x)-k*d
swithn=0

if result<0:
    if k%2==1:
        x-=d
    result=min(x%(2*d),-x%(2*d))
print(result)

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def solve(string):
    x, k, d = map(int, string.split())
    x = abs(x)
    if k % 2:
        x = min(x, x - d, x + d, key=abs)
        k -= 1
    if x < k * d:
        return str(min(x % (2 * d), abs((x % (2 * d)) - 2 * d)))
    else:
        return str(x - k * d)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Failing test case input:
0101011100010001 1010111000110001 1110001100010000

Expected output:
1008989999999999


Actual output:
101011100010001


Fixed submission (verdict: Accepted):
def solve(string):
    x, k, d = map(int, string.split())
    x = abs(x)
    if k % 2:
        x = min(x - d, x + d, key=abs)
        k -= 1
    if x < k * d:
        return str(min(x % (2 * d), abs((x % (2 * d)) - 2 * d)))
    else:
        return str(x - k * d)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main2():
    X, K, D = map(int, input().split())

    r, m = divmod(X, D)
    mi = m
    K -= r

    K = K % 2

    if K == 0:
        print(mi)
    else:
        print(min(abs(mi-D), abs(mi+D)))

if __name__ == "__main__":
    main2()

Failing test case input:
13 1 3

Expected output:
10


Actual output:
2


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

    X = abs(X)

    r, m = divmod(X, D)

    if r <= K:
        mi = X - D*r
        K -= r
    else:
        mi = X - D*K
        K = 0
    
    K = K % 2

    if K == 0:
        print(mi)
    else:
        print(min(abs(mi-D), abs(mi+D)))

if __name__ == "__main__":
    main2()

Problem: p02584
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
x,k,d = list(map(int, input().split()))
x = abs(x)
a,b = divmod(x, d)








print(abs(x))


Failing test case input:
1100011000111111 1000110111000001 1010111000001010

Expected output:
89900000110101


Actual output:
1100011000111111


Fixed submission (verdict: Accepted):
x,k,d = list(map(int, input().split()))
x = abs(x)
a,b = divmod(x, d)
a = min(a, k)
x -= a * d



x -= d * ((k-a) % 2)
print(abs(x))