ZhenlongDai/ACPR huggingface dataset:
Problem: p03959
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print(0)
    quit()

n = inp()
a = inpl()
b = inpl()
de = [-1] * n
mx = [INF] * n
now = -1
for i in range(n):
    if a[i] > now:
        now = a[i]
        de[i] = now
    else:
        mx[i] = now
now = -1
for i in range(n)[::-1]:
    if b[i] > now:
        now = b[i]
        if de[i] != -1 and de[i] != now:
            err()
        de[i] = now
    else:
        mx[i] = min(mx[i], now)
res = 1
for i in range(n):
    if de[i] == -1:
        res *= mx[i]
        res %= mod
print(res)

Failing test case input:
5
3 1 1 0 2
8 10 -1 1 -21

Expected output:
0


Actual output:
1000000006


Fixed submission (verdict: Accepted):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print(0)
    quit()

n = inp()
a = inpl()
b = inpl()
if a[-1] != b[0]: err()
de = [-1] * n
mx = [INF] * n
now = -1
for i in range(n):
    if a[i] > now:
        now = a[i]
        de[i] = now
    else:
        mx[i] = now
now = -1
for i in range(n)[::-1]:
    if b[i] > now:
        now = b[i]
        if de[i] != -1 and de[i] != now:
            err()
        de[i] = now
    else:
        if now < de[i]: err()
        mx[i] = min(mx[i], now)
res = 1
for i in range(n):
    if de[i] == -1:
        res *= mx[i]
        res %= mod
print(res)
Problem: p03959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
mod = 10 ** 9 + 7

N = int(input())
T = [0] + list(map(int, input().split()))
A = list(map(int, input().split())) + [0]

H = [0] * N
for i in range(1, N):
    if T[i - 1] < T[i]:
        H[i - 1] = T[i]
for i in range(N - 1, -1, -1):
    if A[i + 1] < A[i]:
        if H[i] == 0 or H[i] == A[i]:
            H[i] = A[i]
        else:
            print(0)
            exit()

ans = 1
T.pop(0)
A.pop(-1)
for h, t, a in zip(H, T, A):
    if h == 0:
        ans *= min(t, a)
        ans %= mod
print(ans)

Failing test case input:
5
16 0 4 -1 2
19 24 -3 0 -11

Expected output:
0


Actual output:
11


Fixed submission (verdict: Accepted):
mod = 10 ** 9 + 7

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

H = [0] * N
for i in range(N):
    if i == 0 or T[i - 1] < T[i]:
        H[i] = T[i]

for i in range(N - 1, -1, -1):
    if i == N - 1 or A[i] > A[i + 1]:
        H[i] = A[i]
    
ans = 1
for i in range(N):
    if H[i] == 0:
        H[i] = min(T[i], A[i])
        ans *= min(T[i], A[i])
        ans %= mod

flag = True
M = 0
for i in range(N):
    M = max(M, H[i])
    flag &= (M == T[i])
M = 0
for i in range(N - 1, -1, -1):
    M = max(M, H[i])
    flag &= (M == A[i])

if flag is True:
    print(ans)
else:
    print(0)

Problem: p03959
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
arr = [[1] * n for _ in range(4)]
t = list(map(int, input().split()))
a = list(map(int, input().split()))[::-1]

MOD = 10**9 + 7

max_t = 0
max_a = 0

for i in range(n):
    if max_t < t[i]:
        arr[0][i] = t[i]
        arr[1][i] = t[i]
        max_t = t[i]
    else:
        arr[1][i] = t[i]
    if max_a < a[i]:
        arr[2][i] = a[i]
        arr[3][i] = a[i]
        max_a = a[i]
    else:
        arr[3][i] = a[i]

arr[2] = arr[2][::-1]
arr[3] = arr[3][::-1]

ans = 1
for i in range(n):
    ans *= (min(arr[1][i], arr[3][i]) - max(arr[0][i], arr[2][i]) + 1)
    ans %= MOD

print(ans)

Failing test case input:
5
16 0 1 -1 0
19 24 -3 0 -14

Expected output:
0


Actual output:
966


Fixed submission (verdict: Accepted):
n = int(input())
arr = [[1] * n for _ in range(4)]
t = list(map(int, input().split()))
a = list(map(int, input().split()))[::-1]

MOD = 10**9 + 7

max_t = 0
max_a = 0

for i in range(n):
    if max_t < t[i]:
        arr[0][i] = t[i]
        arr[1][i] = t[i]
        max_t = t[i]
    else:
        arr[1][i] = t[i]
    if max_a < a[i]:
        arr[2][i] = a[i]
        arr[3][i] = a[i]
        max_a = a[i]
    else:
        arr[3][i] = a[i]

arr[2] = arr[2][::-1]
arr[3] = arr[3][::-1]

ans = 1
for i in range(n):
    ans *= max(min(arr[1][i], arr[3][i]) - max(arr[0][i], arr[2][i]) + 1, 0)
    ans %= MOD

print(ans)
Problem: p03959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
mod = 10**9 + 7
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

Min = [1] * N
Max = [float("inf")] * N
tp = 0
for i, t in enumerate(T):
    if t != tp:
        Min[i] = max(Min[i], t)
    Max[i] = min(Max[i], t)
    tp = t
ap = 0
for i, a in zip(range(N-1, -1, -1), A[::-1]):
    if a != ap:
        Min[i] = max(Min[i], a)
    Max[i] = min(Max[i], a)
    ap = a
ans = 1
for mi, ma in zip(Min, Max):
    ans = ans * (ma-mi+1) % mod
print(ans)


Failing test case input:
5
7 -1 1 -1 0
38 3 -8 0 -1

Expected output:
0


Actual output:
999999287


Fixed submission (verdict: Accepted):
mod = 10**9 + 7
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

Min = [1] * N
Max = [float("inf")] * N
tp = 0
for i, t in enumerate(T):
    if t != tp:
        Min[i] = max(Min[i], t)
    Max[i] = min(Max[i], t)
    tp = t
ap = 0
for i, a in zip(range(N-1, -1, -1), A[::-1]):
    if a != ap:
        Min[i] = max(Min[i], a)
    Max[i] = min(Max[i], a)
    ap = a
ans = 1
for mi, ma in zip(Min, Max):
    ans = ans * max(ma-mi+1, 0) % mod
print(ans)

Problem: p03959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))


x = [1 for _ in range(N)]
for i in range(1,N):
    if i == 0:
        x[i] = 1
    elif T[i - 1] < T[i]:
        x[i] = 1
    else:
        x[i] = T[i]

y = [1 for _ in range(N)]
for i in range(N - 2, -1, -1):
    if i == N - 1:
        y[i] == 1
    if A[i] > A[i + 1]:
        y[i] = 1
    else:
        y[i] = A[i]

ans = 1

for i in range(N):
    ans = ans * min(x[i], y[i]) % int(1e9 + 7)

print(ans)

11333
33121


Failing test case input:
5
1 2 1 1 4
8 4 2 2 -2

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))


x = [1 for _ in range(N)]
for i in range(1, N):
    if i == 0:
        x[i] = 1
    elif T[i - 1] < T[i]:
        x[i] = 1
    else:
        x[i] = T[i]

y = [1 for _ in range(N)]
for i in range(N - 2, -1, -1):
    if i == N - 1:
        y[i] == 1
    if A[i] > A[i + 1]:
        y[i] = 1
    else:
        y[i] = A[i]

ans = 1

for i in range(N):
    ans = ans * min(x[i], y[i]) % int(1e9 + 7)


for x,y,t,a in zip(x,y,T,A):
    if x == 1 and t > a:
        ans = 0
    if y == 1 and t < a:
        ans = 0


print(ans)
Problem: p03959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    
    t = list(map(int,input().split()))
    a = list(map(int,input().split()))
    MOD = 10**9+7
    
    tt,tl = 0,[False for _ in range(N)]
    for x,num in enumerate(t):
        if num > tt:
            tl[x] = True
            tt = num
            
    at,al = 0,[False for _ in range(N)]
    for x,num in enumerate(a[::-1]):
        if num > at:
            al[-x-1] = True
            at = num
            
    print(tl,al)
    ans,now = 1,0
    for i in range(N):
        print(i,now)
        if tl[i] == True and al[i] == True:
            if now < t[i] == a[i]:
                now = min(t[i],a[i])
            else:
                print(-1)
                exit()
        elif tl[i] == True and al[i] == False:
            if now > t[i]:
                print(-1)
                exit()
            else:
                now = t[i]
        elif tl[i] == False and al[i] == True:
            if now < a[i]:
                print(-1)
                exit()
            else:
                now = a[i]
        else:
            ans *= min(t[i],a[i])
            ans %= MOD
    
    print(ans)

if __name__ == "__main__":
    main()


Failing test case input:
5
7 -1 1 -2 -2
20 3 -2 -1 -2

Expected output:
0


Actual output:
[True, False, False, False, False] [True, True, False, False, False]
0 0
-1


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    
    t = list(map(int,input().split()))
    a = list(map(int,input().split()))
    MOD = 10**9+7
    
    tt,tl = 0,[False for _ in range(N)]
    for x,num in enumerate(t):
        if num > tt:
            tl[x] = True
            tt = num
            
    at,al = 0,[False for _ in range(N)]
    for x,num in enumerate(a[::-1]):
        if num > at:
            al[-x-1] = True
            at = num

    ans,now = 1,0
    for i in range(N):
        if tl[i] == True and al[i] == True:
            if now < t[i] == a[i]:
                now = a[i]
            else:
                print(0)
                exit()
        elif tl[i] == True and al[i] == False:
            if t[i] > a[i]:
                print(0)
                exit()
            else:
                now = t[i]
        elif tl[i] == False and al[i] == True:
            if t[i] < a[i]:
                print(0)
                exit()
            else:
                now = a[i]
        else:
            ans *= min(t[i],a[i])
            ans %= MOD
    
    print(ans)

if __name__ == "__main__":
    main()
Problem: p03959
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
mount = [0]*n
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mount[0] = a[0]
mount[-1] = b[-1]
pat = 1
mod = 10**9+7
for i in range(1,n):
  if a[i] > a[i-1]:
    if mount[i] != 0 and mount[i] != a[i]:
      print(0)
      exit()
    else:
      mount[i] = a[i]
  if b[n-i-1] > b[n-i]:
    if mount[n-i-1] != 0 and mount[n-i-1] != b[n-i-1]:
      print(0)
      exit()
    else:
      mount[n-i-1] = b[n-i-1]
for i in range(n):
  if mount[i] == 0:
    dx = 1
    while mount[i+dx] == 0:
      dx += 1
    this = min(mount[i-1],mount[i+dx])
    pat = pat*(this**dx)%mod
    for j in range(dx):
      mount[i+j] = this
a2 = [0]*n
b2 = [0]*n
a2[0] = mount[0]
b2[-1] = mount[-1]
for i in range(1,n):
  a[i] = max(mount[i],a[i-1])
  b[n-i-1] = max(mount[n-i-1],b[n-i])
if a != a2 or b != b2:
  print(0)
else:
  print(pat)

Failing test case input:
10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5

Expected output:
884111967

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
mount = [0]*n
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mount[0] = a[0]
mount[-1] = b[-1]
pat = 1
mod = 10**9+7
for i in range(1,n):
  if a[i] > a[i-1]:
    if mount[i] != 0 and mount[i] != a[i]:
      print(0)
      exit()
    else:
      mount[i] = a[i]
  if b[n-i-1] > b[n-i]:
    if mount[n-i-1] != 0 and mount[n-i-1] != b[n-i-1]:
      print(0)
      exit()
    else:
      mount[n-i-1] = b[n-i-1]
for i in range(n):
  if mount[i] == 0:
    dx = 1
    while mount[i+dx] == 0:
      dx += 1
    this = min(mount[i-1],mount[i+dx])
    pat = pat*(this**dx)%mod
    for j in range(dx):
      mount[i+j] = this
a2 = [0]*n
b2 = [0]*n
a2[0] = mount[0]
b2[-1] = mount[-1]
for i in range(1,n):
  a2[i] = max(mount[i],a2[i-1])
  b2[n-i-1] = max(mount[n-i-1],b2[n-i])
if a != a2 or b != b2:
  print(0)
else:
  print(pat)
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



n,m = map(int,input().split())

lis = [0] * m

state = [0] * n

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

start = [ [] for i in range(m) ]
end = [ [] for i in range(m)]

allsum = 0
for i in range(n-1):

    if a[i+1] == (a[i]+1)%m:
        continue

    start[a[i] % m].append(i)
    end[(a[i+1]-1) % m].append(i)

    allsum += (a[i+1]-a[i]) % m


imosnum = 0
plus = 0



for i in range(2*m):

    plus += imosnum

    lis[i%m] += plus

    for j in end[i%m]:
        if state[j] == 1:
            plus -= ((a[j+1]-(a[j]+1))%m)
            state[j] = 2
            imosnum -= 1

    for j in start[i%m]:
        if state[j] == 0:
            imosnum += 1
            state[j] = 1

    

print (allsum - max(lis))


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

Expected output:
24


Actual output:
22


Fixed submission (verdict: Accepted):



n,m = map(int,input().split())

lis = [0] * m

state = [0] * n

a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1

start = [ [] for i in range(m) ]
end = [ [] for i in range(m)]

allsum = 0
for i in range(n-1):

    allsum += (a[i+1]-a[i]) % m
    if a[i+1] == (a[i]+1)%m:
        continue

    start[(a[i]+1) % m].append(i)
    end[a[i+1] % m].append(i)

    


imosnum = 0
plus = 0



for i in range(2*m):

    plus += imosnum

    lis[i%m] += plus

    for j in end[i%m]:
        if state[j] == 1:
            plus -= ((a[j+1]-(a[j]+1))%m)
            state[j] = 2
            imosnum -= 1

    for j in start[i%m]:
        if state[j] == 0:
            imosnum += 1
            state[j] = 1

    

if (allsum - max(lis) < 0):
    print (asxacscd)

print (allsum - max(lis))
Problem: p03677
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from itertools import accumulate

n, m = map(int, input().split())
A = list(map(int, input().split()))
L = [0]*(2*m)
B = []
cnt = 0
for i in range(n-1):
  a, b = A[i], A[i+1]
  a -= 1
  b -= 1
  if a < b:
    cnt += b-a
    if b-a == 1:
      continue
    L[a+2] += 1
    L[b+1] += -1
    B.append((b+1, -(b-a-1)))
    a += m
    b += m
    L[a+2] += 1
    if b < 2*m-1:
      L[b+1] += -1
      B.append((b+1, -(b-a-1)))
  else:
    b += m
    cnt += b-a
    if b-a == 1:
      continue
    L[a+2] += 1
    L[b+1] += -1
    B.append((b+1, -(b-a-1)))
L = list(accumulate(L))
for i, b in B:
  L[i] += b
L = list(accumulate(L))
ans = cnt - max(L)
print(ans)

Failing test case input:
10 10
10 9 8 7 6 7 4 3 2 1

Expected output:
39


Actual output:
41


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
from itertools import accumulate

n, m = map(int, input().split())
A = list(map(int, input().split()))
L = [0]*(2*m)
B = []
cnt = 0
for i in range(n-1):
  a, b = A[i], A[i+1]
  a -= 1
  b -= 1
  if a < b:
    cnt += b-a
    if b-a == 1:
      continue
    L[a+2] += 1
    L[b+1] += -1
    B.append((b+1, -(b-a-1)))
  else:
    b += m
    cnt += b-a
    if b-a == 1:
      continue
    L[a+2] += 1
    L[b+1] += -1
    B.append((b+1, -(b-a-1)))
L = list(accumulate(L))
for i, b in B:
  L[i] += b
L = list(accumulate(L))
c = 0
for i in range(m):
  c = max(c, L[i]+L[m+i])
ans = cnt - c
print(ans)
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



n,m = map(int,input().split())

lis = [0] * m

state = [0] * n

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

start = [ [] for i in range(m) ]
end = [ [] for i in range(m)]

allsum = 0
for i in range(n-1):

    if a[i+1] == a[i]+1:
        continue

    start[a[i] % m].append(i)
    end[(a[i+1]-1) % m].append(i)

    allsum += (a[i+1]-a[i]) % m


imosnum = 0
plus = 0



for i in range(2*m):

    plus += imosnum

    lis[i%m] += plus

    for j in end[i%m]:
        if state[j] == 1:
            plus -= ((a[j+1]-(a[j]+1))%m)
            state[j] = 2
            imosnum -= 1

    for j in start[i%m]:
        if state[j] == 0:
            imosnum += 1
            state[j] = 1

    

print (allsum - max(lis))

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

Expected output:
24


Actual output:
22


Fixed submission (verdict: Accepted):



n,m = map(int,input().split())

lis = [0] * m

state = [0] * n

a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1

start = [ [] for i in range(m) ]
end = [ [] for i in range(m)]

allsum = 0
for i in range(n-1):

    allsum += (a[i+1]-a[i]) % m
    if a[i+1] == (a[i]+1)%m:
        continue

    start[(a[i]+1) % m].append(i)
    end[a[i+1] % m].append(i)

    


imosnum = 0
plus = 0



for i in range(2*m):

    plus += imosnum

    lis[i%m] += plus

    for j in end[i%m]:
        if state[j] == 1:
            plus -= ((a[j+1]-(a[j]+1))%m)
            state[j] = 2
            imosnum -= 1

    for j in start[i%m]:
        if state[j] == 0:
            imosnum += 1
            state[j] = 1

    

if (allsum - max(lis) < 0):
    print (asxacscd)

print (allsum - max(lis))
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



n,m = map(int,input().split())

lis = [0] * m

state = [0] * n

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

start = [ [] for i in range(m) ]
end = [ [] for i in range(m)]

allsum = 0
for i in range(n-1):

    start[a[i] % m].append(i)
    end[(a[i+1]-1) % m].append(i)

    allsum += (a[i+1]-a[i]) % m


imosnum = 0
plus = 0



for i in range(2*m):

    plus += imosnum

    lis[i%m] += plus

    for j in end[i%m]:
        if state[j] == 1:
            plus -= ((a[j+1]-a[j])%m-1)
            state[j] = 2
            imosnum -= 1

    for j in start[i%m]:
        if state[j] == 0:
            imosnum += 1
            state[j] = 1

    

print (allsum - max(lis))

Failing test case input:
10 10
3 7 3 7 10 5 4 5 2 1

Expected output:
27


Actual output:
14


Fixed submission (verdict: Accepted):



n,m = map(int,input().split())

lis = [0] * m

state = [0] * n

a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1

start = [ [] for i in range(m) ]
end = [ [] for i in range(m)]

allsum = 0
for i in range(n-1):

    allsum += (a[i+1]-a[i]) % m
    if a[i+1] == (a[i]+1)%m:
        continue

    start[(a[i]+1) % m].append(i)
    end[a[i+1] % m].append(i)

    


imosnum = 0
plus = 0



for i in range(2*m):

    plus += imosnum

    lis[i%m] += plus

    for j in end[i%m]:
        if state[j] == 1:
            plus -= ((a[j+1]-(a[j]+1))%m)
            state[j] = 2
            imosnum -= 1

    for j in start[i%m]:
        if state[j] == 0:
            imosnum += 1
            state[j] = 1

    

if (allsum - max(lis) < 0):
    print (asxacscd)

print (allsum - max(lis))
Problem: p03677
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
arr=list(map(int,input().split()))
imos1=[0]*(m*2+2)
imos2=[0]*(m*2+2)
imos3=[0]*(m*2+2)
for i in range(n-1):
  cost=(m+arr[i+1]-arr[i])%m
  if arr[i]<arr[i+1]:
    imos1[arr[i]]+=1+cost
    imos1[arr[i+1]+1]-=1+cost
    imos2[arr[i]+1]+=-1
    imos2[arr[i+1]+1]+=1
    imos3[arr[i+1]+1]+=cost
    if arr[i]!=1:
      imos1[1]+=cost
      imos1[arr[i]]-=cost
    if arr[i+1]!=m:
      imos1[arr[i+1]+1]+=cost
      imos1[m+1]-=cost    
  else:
    imos1[arr[i]]+=1+cost
    imos1[m+arr[i+1]+1]-=1+cost
    imos2[arr[i]+1]+=-1
    imos2[m+arr[i+1]+1]+=1
    imos3[m+arr[i+1]+1]+=cost
    imos1[arr[i+1]+1]+=cost
    imos1[arr[i]]-=cost
for i in range(1,m*2+2):
  imos2[i]+=imos2[i-1]
for i in range(m*2+2):
  imos1[i]+=imos2[i]
  imos1[i]+=imos3[i]
for i in range(1,m*2+2):
  imos1[i]+=imos1[i-1]
xs=[0]*(m+1)
xs[0]=10**18
for i in range(1,m+1):
  xs[i]=imos1[i]+imos1[m+i]
print(min(xs))

Failing test case input:
7 19
2 9 3 18 2 14 4 0 4 1

Expected output:
34


Actual output:
35


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
arr=list(map(int,input().split()))
imos1=[0]*(m*2+2)
imos2=[0]*(m*2+2)
imos3=[0]*(m*2+2)
for i in range(n-1):
  cost=(m+arr[i+1]-arr[i])%m
  if arr[i]<arr[i+1]:
    imos1[arr[i]]+=cost
    imos1[arr[i]+m]-=cost
    imos2[arr[i]+2]+=-1
    imos2[arr[i+1]+1]+=1
    imos3[arr[i+1]+1]+=cost-1
  else:
    imos1[arr[i]]+=cost
    imos1[arr[i]+m]-=cost
    imos2[arr[i]+2]+=-1
    imos2[arr[i+1]+m+1]+=1
    imos3[arr[i+1]+m+1]+=cost-1
for i in range(1,m*2+2):
  imos2[i]+=imos2[i-1]
for i in range(m*2+2):
  imos1[i]+=imos2[i]
  imos1[i]+=imos3[i]
for i in range(1,m*2+2):
  imos1[i]+=imos1[i-1]
xs=[0]*(m+1)
xs[0]=10**18
for i in range(1,m+1):
  xs[i]=imos1[i]+imos1[m+i]
print(min(xs))
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>1:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if (g-s)%m>1:
        if g>=s:
            if ans>s:
                val+=1+(g-ans)%m
            else:
                val+=(g-ans)%m
        else:
            if ans>s or g>=ans:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
    else:
        val+=(g-s)%m


print(val)

Failing test case input:
4 43
6 9 3 14 2 16 4 0 4 2

Expected output:
15


Actual output:
18


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>1:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>=imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if (g-s)%m>1:
        if g>=s:
            if g>=ans>s:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
        else:
            if ans>s or g>=ans:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
    else:
        val+=(g-s)%m


print(val)
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n, m = map(int, input().split())
a = list(map(int, input().split()))

imos = [0] * (2 * m)
diff = [0] * (2 * m)
res = 0
for i in range(n - 1):
    l = a[i] - 1
    r = a[i + 1] - 1
    if l > r:
        r += m
    imos[l + 2] += 1
    imos[r + 1] -= 1
    diff[r + 1] = r - l - 1
    res += r - l

ans = [0] * (2 * m)
tmp = 0

for i in range(2 * m):
    tmp += imos[i]
    if i - 1 >= 0:
        ans[i] += ans[i - 1] + tmp
    else:
        ans[i] += tmp
    ans[i] -= diff[i]
    
max_ = 0
for i in range(m):
    max_ = max(max_, ans[i] + ans[i + m])
print(res - max_)

Failing test case input:
10 10
3 7 3 7 10 5 4 5 2 1

Expected output:
27


Actual output:
23


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

imos = [0] * (2 * m)
diff = [0] * (2 * m)
res = 0
for i in range(n - 1):
    l = a[i] - 1
    r = a[i + 1] - 1
    if l > r:
        r += m
    imos[l + 2] += 1
    imos[r + 1] -= 1
    diff[r + 1] += r - l - 1
    res += r - l

ans = [0] * (2 * m)
tmp = 0
for i in range(2 * m):
    tmp += imos[i]
    if i - 1 >= 0:
        ans[i] += ans[i - 1] + tmp
    else:
        ans[i] += tmp
    ans[i] -= diff[i]
    
max_ = 0
for i in range(m):
    max_ = max(max_, ans[i] + ans[i + m])
print(res - max_)

Problem: p03677
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M 
Y = [0] * M 

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+1, M-1)
        tri(0, b)
        box(0, b, b-a-1)

ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

Y = acc(Y)
X = [X[i] + Y[i] for i in range(M)]
X = acc(X)

ans -= max(X)
print(ans)

Failing test case input:
2 19
10 9 8 7 1 14 4 3 2 1

Expected output:
1


Actual output:
9


Fixed submission (verdict: Accepted):
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M 
Y = [0] * M 

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+2, M-1)
        tri(0, b)
        box(0, b, -a+M-2)
        
    

def rev():
    ret = acc(Y)
    ret = [X[i] + ret[i] for i in range(M)]
    return acc(ret)
    
ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

X = rev()

ans -= max(X)
print(ans)
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from heapq import *

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x-1, a))
lr = []
cnt = 0

for i in range(n-1):
    ai, aj = a[i], a[i+1]
    
    if ai<aj:
        lr.append((ai, aj))
        cnt += aj-ai
    else:
        lr.append((ai-m, aj))
        lr.append((ai, m-1))
        cnt += m+aj-ai
    
lr.sort(key=lambda t: t[0])
idx = 0
ans = cnt
decre = 0
pq = []

for i in range(m):
    while len(pq)>0 and pq[0][0]<i:
        r, l = heappop(pq)
        decre -= r-l
        
    while idx<len(lr) and i>=lr[idx][0]:
        decre += i-lr[idx][0]-1
        heappush(pq, (lr[idx][1], lr[idx][0]))
        idx += 1
    
    ans = min(ans, cnt-decre)
    decre += len(pq)

print(ans)

Failing test case input:
4 19
15 6 10 13 2 14 3 3 3 1

Expected output:
8


Actual output:
9


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
from heapq import *

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x-1, a))
lr = []
cnt = 0

for i in range(n-1):
    ai, aj = a[i], a[i+1]
    
    if ai<aj:
        lr.append((ai+1, aj))
        cnt += aj-ai
    else:
        lr.append((ai-m+1, aj))
        lr.append((ai+1, m-1))
        cnt += m+aj-ai
    
lr.sort(key=lambda t: t[0])

idx = 0
ans = cnt
decre = 0
pq = []

for i in range(m):
    while len(pq)>0 and pq[0][0]<i:
        r, l = heappop(pq)
        
        decre -= r-l+1
        
    while idx<len(lr) and i>=lr[idx][0]:
        decre += i-lr[idx][0]
        
        heappush(pq, (lr[idx][1], lr[idx][0]))
        idx += 1
    
    ans = min(ans, cnt-decre)
    decre += len(pq)

print(ans)
Problem: p03677
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M 
Y = [0] * M 

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+1, M-1)
        tri(0, b)
        box(0, b, b-a)
        
    

def rev():
    ret = acc(Y)
    ret = [X[i] + ret[i] for i in range(M)]
    return acc(ret)
    
ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

X = rev()

ans -= max(X)
print(ans)

Failing test case input:
7 19
10 9 3 9 2 14 4 0 4 1

Expected output:
32


Actual output:
36


Fixed submission (verdict: Accepted):
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M 
Y = [0] * M 

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+2, M-1)
        tri(0, b)
        box(0, b, -a+M-2)
        
    

def rev():
    ret = acc(Y)
    ret = [X[i] + ret[i] for i in range(M)]
    return acc(ret)
    
ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

X = rev()

ans -= max(X)
print(ans)
Problem: p03677
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [b-1 for b in a]
imos = [0 for _ in range(m+1)]
base = 0
for i in range(n-1):
	x, y = a[i], a[i+1]
	z, w = (x+2)%m, (y+1)%m
	if w == 0:
		w = m
	if z < w:
		imos[z] += 1
		imos[w] -= w-z+1
		if w < m:
			imos[w+1] += w-z
	else:
		imos[z] += 1
		imos[m] -= m-z+1
		imos[0] += 1
		base += m-z
		imos[w] -= m+w-z+1
		if w < m:
			imos[w+1] += m+w-z


for i in range(m):
	imos[i+1] += imos[i]
imos[0] += base
for i in range(m):
	imos[i+1] += imos[i]
res = max(imos[:m])
ans = 0
for i in range(n-1):
	if a[i+1] > a[i]:
		ans += a[i+1] - a[i]
	else:
		ans += a[i+1] + m - a[i]

ans -= res
print(ans)

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

Expected output:
24


Actual output:
14


Fixed submission (verdict: Accepted):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [b-1 for b in a]
imos = [0 for _ in range(m+1)]
base = 0
for i in range(n-1):
	x, y = a[i], a[i+1]
	if y-x == 1 or x+1-m == y:
		continue
	z, w = (x+2)%m, (y+1)%m
	if w == 0:
		w = m
	if z < w:
		imos[z] += 1
		imos[w] -= w-z+1
		if w < m:
			imos[w+1] += w-z
	else:
		imos[z] += 1
		imos[m] -= m-z+1
		imos[0] += 1
		base += m-z
		imos[w] -= m+w-z+1
		if w < m:
			imos[w+1] += m+w-z


for i in range(m):
	imos[i+1] += imos[i]
imos[0] += base
for i in range(m):
	imos[i+1] += imos[i]
res = max(imos[:m])
ans = 0
for i in range(n-1):
	if a[i+1] > a[i]:
		ans += a[i+1] - a[i]
	else:
		ans += a[i+1] + m - a[i]

ans -= res
print(ans)
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>2:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if (g-s)%m>2:
        if g>=s:
            if ans>s:
                val+=1+(g-ans)%m
            else:
                val+=(g-ans)%m
        else:
            if ans>s or g>=ans:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
    else:
        val+=(g-s)%m


print(val)

Failing test case input:
7 19
4 17 6 4 2 14 4 0 0 1

Expected output:
37


Actual output:
39


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>1:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>=imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if (g-s)%m>1:
        if g>=s:
            if g>=ans>s:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
        else:
            if ans>s or g>=ans:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
    else:
        val+=(g-s)%m


print(val)
Problem: p03677
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
aa = inpl()

yama_height = [0]*(2*M)
yama_num = [0]*(2*M)
SUM = 0
for i in range(1,N):
	na = aa[i]
	ba = aa[i-1]
	if na < ba:
		na += M
	SUM += (na-ba)
	yama_height[na] = na - (ba + 1)
	yama_num[na] -= 1
	yama_num[ba+1] += 1

tmp = 0
for i in range(2*M):
	tmp += yama_num[i]
	yama_num[i] = tmp

ans_list = [0]*(M)
tmp = 0
for i in reversed(range(2*M)):
	tmp += yama_height[i]
	tmp -= yama_num[i]
	ans_list[i%M] += tmp

print(SUM-max(ans_list))


Failing test case input:
4 8
1 5 1 5

Expected output:
6


Actual output:
9


Fixed submission (verdict: Accepted):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
aa = inpl()
for i in range(N):
	aa[i] -= 1

yama_height = [0]*(2*M)
yama_num = [0]*(2*M)
SUM = 0
for i in range(1,N):
	na = aa[i]
	ba = aa[i-1]
	if na < ba:
		na += M
	SUM += (na-ba)
	yama_height[na] += na - (ba + 1)
	yama_num[na] -= 1
	yama_num[ba+1] += 1

tmp = 0
for i in range(2*M):
	tmp += yama_num[i]
	yama_num[i] = tmp

ans_list = [0]*(M)
tmp = 0
for i in reversed(range(2*M)):
	tmp += yama_height[i]
	tmp -= yama_num[i]
	ans_list[i%M] += tmp

print(SUM-max(ans_list))
Problem: p03677
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
aa = inpl()
for i in range(N):
	aa[i] -= 1

yama_height = [0]*(2*M)
yama_num = [0]*(2*M)
SUM = 0
for i in range(1,N):
	na = aa[i]
	ba = aa[i-1]
	if na < ba:
		na += M
	SUM += (na-ba)
	yama_height[na] = na - (ba + 1)
	yama_num[na] -= 1
	yama_num[ba+1] += 1

tmp = 0
for i in range(2*M):
	tmp += yama_num[i]
	yama_num[i] = tmp

ans_list = [0]*(M)
tmp = 0
for i in reversed(range(2*M)):
	tmp += yama_height[i]
	tmp -= yama_num[i]
	ans_list[i%M] += tmp

print(SUM-max(ans_list))


Failing test case input:
10 14
10 9 8 7 1 7 4 3 2 1

Expected output:
41


Actual output:
55


Fixed submission (verdict: Accepted):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
aa = inpl()
for i in range(N):
	aa[i] -= 1

yama_height = [0]*(2*M)
yama_num = [0]*(2*M)
SUM = 0
for i in range(1,N):
	na = aa[i]
	ba = aa[i-1]
	if na < ba:
		na += M
	SUM += (na-ba)
	yama_height[na] += na - (ba + 1)
	yama_num[na] -= 1
	yama_num[ba+1] += 1

tmp = 0
for i in range(2*M):
	tmp += yama_num[i]
	yama_num[i] = tmp

ans_list = [0]*(M)
tmp = 0
for i in reversed(range(2*M)):
	tmp += yama_height[i]
	tmp -= yama_num[i]
	ans_list[i%M] += tmp

print(SUM-max(ans_list))
Problem: p03677
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>2:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if g>=s:
        if ans>s:
            val+=1+(g-ans)%m
        else:
            val+=(g-ans)%m
    else:
        if ans>s or g>=ans:
            val+=1+(g-ans)%m
        else:
            val+=(g-s)%m

print(val)


Failing test case input:
2 8
1 8 1 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>1:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>=imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if (g-s)%m>1:
        if g>=s:
            if g>=ans>s:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
        else:
            if ans>s or g>=ans:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
    else:
        val+=(g-s)%m


print(val)
Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h,w=map(int,input().split())
if h%2 == 0 or w%2 == 0:
  print(h*w/2)
else:
  print(int(h*w/2)+1)
  

Failing test case input:
1000000110 1110000000

Expected output:
555000061050000000


Actual output:
5.5500006105e+17


Fixed submission (verdict: Accepted):
h,w=map(int,input().split())
if h == 1 or w == 1:
  print(1)
elif h%2 == 0 or w%2 == 0:
  print(h*w
else:
  print(h*w

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

H, W = map(int, input().split())
ans = math.ceil(H / 2) * math.ceil(W / 2) + H 
print(ans - 1)


Failing test case input:
1000000111 1010000000

Expected output:
505000056055000000


Actual output:
252500029280000110


Fixed submission (verdict: Accepted):
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

H, W = map(int, input().split())
if H >= 2 and W >= 2:
    ans = math.ceil(H / 2) * math.ceil(W / 2) + (H 
else:
    ans = 1
print(ans)

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

from math import ceil
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
    exit()
ans = 0
ans += ceil(W / 2) * ceil(H / 2)
ans += W 
print(ans)

Failing test case input:
1000000111 1010010000

Expected output:
505005056055555000


Actual output:
252502529290290000


Fixed submission (verdict: Accepted):

from math import ceil
H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
else:
    ans = 0
    ans += ceil(W / 2) * ceil(H / 2)
    ans += (W 
    print(ans)

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def resolve():
    h, w = map(int, input().split())
    dy = h 
    if h == 1:
        count = w
    elif h % 2 == 1:
        count = w * dy + (w-1)
    else:
        count = w * dy

    print(count)

if __name__ == '__main__':
    resolve()

Failing test case input:
0011000100 0110000100

Expected output:
605006050005000


Actual output:
1210012100010000


Fixed submission (verdict: Accepted):
def resolve():
    h, w = map(int, input().split())
    dy = h 
    if h == 1 or w == 1:
        count = 1
    elif h % 2 == 1:
        count = w * dy + (w - (w 
    else:
        count = w * dy

    print(count)


if __name__ == '__main__':
    resolve()
Problem: p02742
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
H,W=map(int,input().split())
import math

A=[0,math.ceil(W/2)]
c=W*math.ceil(H/2)+A[H%2]

print(c)


Failing test case input:
0001000111 1110100000

Expected output:
555111610550000


Actual output:
555112720650000


Fixed submission (verdict: Accepted):
H,W=map(int,input().split())
import math

A=[0,math.ceil(W/2)]
if (H-1)*(W-1)!=0:
  c=W*math.floor(H/2)+A[H%2]
else:
  c=1
print(c)

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




def main():
    h, w = map(int, input().split())
    ans = (h * w) / 2
    if h % 2 == w % 2 == 1:
        ans = ans + 1
    print("%d" % ans)


if __name__ == '__main__':
    main()


Failing test case input:
1011000100 1010000100

Expected output:
510555101050005000


Actual output:
510555101050004992


Fixed submission (verdict: Accepted):




def main():
    h, w = map(int, input().split())
    if h == 1 or w == 1:
        ans = 1
    elif h % 2 == 0:
        ans = (h 
    elif w % 2 == 0:
        ans = (w 
    else:
        ans = h * (w 
    print("%d" % ans)


if __name__ == '__main__':
    main()

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h,w=map(int,input().split())
result = h*w
if result%2==0:
    print(result/2)
else:
    print(int(result/2)+1)

Failing test case input:
0011000100 1010000100

Expected output:
5555051050005000


Actual output:
5555051050005000.0


Fixed submission (verdict: Accepted):
h,w=map(int,input().split())
result = h*w
if h==1 or w==1:
    print(1)
elif result%2==0:
    print(int(result
else:
    print(int(result

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def resolve():
    h, w = map(int, input().split())
    dy = h 
    if h == 1:
        count = w 
    elif w == 1:
        count = h 
    elif h % 2 == 1:
        count = w * dy + (w-1)
    else:
        count = w * dy

    print(count)

if __name__ == '__main__':
    resolve()

Failing test case input:
1000000111 1000000000

Expected output:
500000055500000000


Actual output:
1000000111999999999


Fixed submission (verdict: Accepted):
def resolve():
    h, w = map(int, input().split())
    dy = h 
    if h == 1 or w == 1:
        count = 1
    elif h % 2 == 1:
        count = w * dy + (w - (w 
    else:
        count = w * dy

    print(count)


if __name__ == '__main__':
    resolve()

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
h,w = map(int,(input().split()))
h = math.floor(h)
w = math.floor(w)
sum = h * w

if h == 1 and w ==1:
    print("1")
elif h % 2 == 0:
    result = math.floor(sum /2)
    print(result)
else:
    result = math.floor(sum /2 + 1)
    print(result)

Failing test case input:
0001000111 1111101000

Expected output:
555612166105500


Actual output:
555612166105501


Fixed submission (verdict: Accepted):
import math
h,w = map(int,input().split())


if w == 1 or h == 1 :
    print("1")
elif (h * w ) % 2 == 0:
    result = h * w /2
    result = math.ceil(result)
    print(str(result))
elif (h * w )% 2 != 0:
    result = ((h * w) 
    result = math.ceil(result)
    print(str(result))
Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h,w = [int(i) for i in input().split()]
a = (w + 1) 
n = (h + 1) 
r = a*n
if h % 2 == 0:
    r += (a-1)*n
else:
    r += (a-1)*(n-1)
print(r)

Failing test case input:
0011000100 1010000100

Expected output:
5555051050005000


Actual output:
22220206231020301


Fixed submission (verdict: Accepted):
h,w = [int(i) for i in input().split()]
r = h*w
if r % 2 == 1:
    r += 1
if h <= 1 or w <= 1:
    print(1)
else:
    print(r

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
h,w = map(int,(input().split()))
h = math.floor(h)
w = math.floor(w)
sum = h * w

if h == 1:
    print("1")
elif h % 2 == 0:
    result = math.floor(sum /2)
    print(result)
else:
    result = math.floor(sum /2 + 1)
    print(result)

Failing test case input:
1001000101 0111101100

Expected output:
55606106160605550


Actual output:
55606106160605552


Fixed submission (verdict: Accepted):
import math
h,w = map(int,input().split())


if w == 1 or h == 1 :
    print("1")
elif (h * w ) % 2 == 0:
    result = h * w /2
    result = math.ceil(result)
    print(str(result))
elif (h * w )% 2 != 0:
    result = ((h * w) 
    result = math.ceil(result)
    print(str(result))

Problem: p02742
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
H,W=map(int,input().split())


if (H*W)%2==0:
    print(int(H*W/2))

else:
    print(int((H*W+1)/2))

Failing test case input:
1011000111 1110100000

Expected output:
561155611610550000


Actual output:
561155611610550016


Fixed submission (verdict: Accepted):
H,W=map(int,input().split())

if H==1 or W==1:
    print(1)

elif (H*W)%2==0:
    print(H*W

else:
    print((H*W+1)

Problem: p02742
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
H,W=map(int,input().split())
if (H*W)%2==0:
    print(int(H*W/2))
else:
    print(math.ceil(H*W/2))

Failing test case input:
1000000111 1110010000

Expected output:
555005061605555000


Actual output:
555005061605555008


Fixed submission (verdict: Accepted):
import math
H,W=map(int,input().split())
if H==1 or W==1:
    print(1)
elif (H*W)%2==0:
    print(H*W
else:
    print(math.ceil(H*W/2))

Problem: p02742
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
H, W = map(int, input().split())
if W > 0:
	HW = H*W
	print(sum(divmod(HW, 2)))
else:
  print(0)

Failing test case input:
-3 -13

Expected output:
20


Actual output:
0


Fixed submission (verdict: Accepted):
H, W = map(int, input().split())
if H!=1 and W!=1:
	HW = H*W
	print(sum(divmod(HW, 2)))
else:
  print(1)