ZhenlongDai/ACPR huggingface dataset:
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minbf = math.floor(sum(aa) / len(aa))
ansf = sum(map(lambda ea: abs(ea - minbf), aa))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:

Fixed submission (verdict: Accepted):
from statistics import median

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

aa = list(map(lambda e: e[1] - (e[0] + 1), enumerate(a)))
minb = median(aa)


ans = int(sum(map(lambda ea: abs(ea - minb), aa)))

print(ans)

Problem: p03311
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
c = [a[i]-i-1 for i in range(n)]
b = sum(c)
x = sum([abs(c[i]-b) for i in range(n)])
y = sum([abs(c[i]-b-1) for i in range(n)])
z = sum([abs(c[i]-b+1) for i in range(n)])
print(min([x,y,z]))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
c = [a[i]-i-1 for i in range(n)]
c.sort()
mn = s = sum(c[1:])-(n-1)*c[0]
for i in range(n-1):
    s += (2*i+2-n)*(c[i+1]-c[i])
    mn = min(mn,s)
print(mn)

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
B = [a-i for i, a in enumerate(A)]
m = sum(B)
print(min(sum(abs(b-m-i) for b in B)for i in range(-1,2)))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
23


Fixed submission (verdict: Accepted):
from statistics import median
N = int(input())
A = list(map(int, input().split()))
B = [a-i for i, a in enumerate(A)]
m = int(median(B))
print(sum(abs(b-m) for b in B))
Problem: p03311
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = [a[i] - (i+1) for i in range(n)]
c = sum(b)
ans = 0
for i in range(n):
    ans += abs(a[i] -(c + i+1))
print(ans)


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):



import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = [a[i] - (i+1) for i in range(n)]
b.sort()
if n % 2:
    c = b[n
else:
    c = (b[n
ans = 0
for i in range(n):
    ans += abs(a[i] -(c + i+1))
print(ans)

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, *A = map(int, open(0).read().split())
    X, Y = 0, 0
    for i in range(N):
        a = A[i] - i - 1
        X += a
        Y += a**2
    b = X 
    
    ans = 0
    for i in range(N):
        a = A[i] - i - 1
        ans += abs(a - b)
    print(ans)

if __name__ == '__main__':
  main()


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
def main():
    N, *A = map(int, open(0).read().split())
    B = [A[i] - i - 1 for i in range(N)]
    B.sort()
    b1 = B[(N-1)
    b2 = B[N
    ans1 = ans2 = 0
    for i in range(N):
        a = A[i] - i - 1
        ans1 += abs(a - b1)
        ans2 += abs(a - b2)
    print(min(ans1, ans2))

if __name__ == '__main__':
  main()
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
data = list(map(int, input().split()))
for i in range(N):
    data[i] -= (i + 1)
ave = sum(data) / N
if ave > 0:
    key = int(ave + 1)
    key1 = int(ave)
else:
    key = int(ave - 1)
    key1 = int(ave)
data.sort()
sumdata = 0
sumdata2 = 0
key = data[int(N / 2) - 1]
key2 = data[int(N / 2)]
print(data, key, key2)
for i in data:
    sumdata += abs(i - key)
    sumdata2 += abs(i - key2)



print(min([sumdata, sumdata2]))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
[0, 0, 0, 1, 1] 0 0
2


Fixed submission (verdict: Accepted):
N = int(input())
data = list(map(int, input().split()))
for i in range(N):
    data[i] -= (i + 1)
ave = sum(data) / N
if ave > 0:
    key = int(ave + 1)
    key1 = int(ave)
else:
    key = int(ave - 1)
    key1 = int(ave)
data.sort()
sumdata = 0
sumdata2 = 0
key = data[int(N / 2) - 1]
key2 = data[int(N / 2)]
for i in data:
    sumdata += abs(i - key)
    sumdata2 += abs(i - key2)



print(min([sumdata, sumdata2]))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def mm(N, A, x):
  S = 0
  for i in range(N):
    S += abs(A[i] - x)
  return S

N = int(input())
A = []
j = 0
for i in input().split():
  j += 1
  A.append(int(i)-j)
x = sum(A) 
print(min(mm(N, A, x), mm(N, A, x+1)))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
def mm(N, A, x):
  S = 0
  for i in range(N):
    S += abs(A[i] - x)
  return S

N = int(input())
A = []
j = 0
for i in input().split():
  j += 1
  A.append(int(i)-j)
A.sort()
if N % 2 == 0:
  print(mm(N, A, A[N
elif N == 1:
  print(0)
else:
  print(min(mm(N, A, A[N

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, A = int(input()), list(map(int, input().split()))
    for i in range(N):
        A[i] -= i + 1
    ave = sum(A) 
    a, b = ave, ave + 1
    c, d = 0, 0
    _abs = abs
    for el in A:
        c += _abs(el-a)
        d += _abs(el-b)
    print(min(c, d))
main()


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
import statistics
def main():
    N, A = int(input()), list(map(int, input().split()))
    for i in range(N):
        A[i] -= i + 1
    m = int(statistics.median(A))
    a, b = m, m + 1
    c, d = 0, 0
    for el in A:
        c += abs(el-a)
        d += abs(el-b)
    print(min(c, d))
main()

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

import statistics
import math
n = int(input())
A = list(map(int, input().split()))

aa = []

for i in range(n):
    aa.append(A[i] - 1 - i)
print(aa)
b = int(statistics.median(aa))

ans = 0

for a in aa:
    ans += abs(a-b)

print(ans)


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
[1, 0, 0, 1, 0]
2


Fixed submission (verdict: Accepted):

import statistics
import math
n = int(input())
A = list(map(int, input().split()))

aa = []

for i in range(n):
    aa.append(A[i] - 1 - i)

b = int(statistics.median(aa))

ans = 0

for a in aa:
    ans += abs(a-b)

print(ans)
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A = [A[n]-n for n in range(N)]
ave_A = sum(A)
A = [abs(a - ave_A) for a in A]
ans = abs(sum(A))
A = [abs(a  -1) for a in A]
ans = min(ans, abs(sum(A)))
print(ans)

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
23


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A = [A[n]-n for n in range(N)]
A.sort()
if N % 2 == 1:
  A = [abs(a - A[N
  ans = sum(A)
else:
  temp = A
  A = [abs(a - A[N
  ans = sum(A)
  A = [abs(a - temp[N
  ans = min(ans, sum(A))

print(ans)

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
lis = list(map(int,input().split()))
cou = 0
co = 0
num = math.ceil(sum(lis))
nu = math.floor(sum(lis))
for i in range(n):
  cou += abs(lis[i]-(num + i + 1))
  co += abs(lis[i]-(nu + i + 1))
print(min(cou,co))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
83


Fixed submission (verdict: Accepted):
import math
n = int(input())
lis = list(map(int,input().split()))
if n == 1:
  print("0")
  exit()
for i in range(n):lis[-(i+1)] += i
lis.sort()
cou = 0
co = 0
num = lis[math.ceil(n/2)]
nu = lis[math.floor(n/2)]
for i in range(n):
  cou += abs(lis[i]-num)
  co += abs(lis[i]-nu)
print(min(cou,co))

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

tmp = 0
for i in range(N):
    tmp += A[i]-(i+1)

tmp 

ans = 0
for i in range(N):
    ans += abs(A[i]-(tmp+i+1))

print(ans)

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
B = []
for i in range(N):
    B.append(A[i]-(i+1))

B.sort()
if (N % 2 == 1):
    b = B[N
else:
    b = round((B[N

ans = 0
for i in range(N):
    ans += abs(B[i] - b)

print(ans)
Problem: p03311
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))

aa = [ai - i-1 for i,ai in enumerate(a)]

def tri_search(f:"f(x:float)->float", left, right, iter=100)->float:
    for _ in range(iter):
        ml = (left*2 + right) / 3
        mr = (left + right*2) / 3
        if f(ml) < f(mr):
            right = mr
        else:
            left = ml
    
    return (right + left) / 2

def f(x):
    ret = 0
    x = int(x+0.5)
    for aai in aa:
        ret += abs(aai - x)
    return ret

b = tri_search(f, -10**9, 10**9)
print(min(f(b), f(b)+1, f(b)-1))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
1


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

aa = [ai - i-1 for i,ai in enumerate(a)]

def tri_search(f:"f(x:float)->float", left, right, iter=100)->float:
    for _ in range(iter):
        ml = (left*2 + right) / 3
        mr = (left + right*2) / 3
        if f(ml) < f(mr):
            right = mr
        else:
            left = ml
    
    return (right + left) / 2

def f(x):
    ret = 0
    x = int(x+0.5)
    for aai in aa:
        ret += abs(aai - x)
    return ret

b = tri_search(f, -10**9, 10**9)
print(min(f(b), f(b+1), f(b-1)))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n):
    a[i] -= i + 1
    s += a[i]
b = s 
r1=0
r2=0
for i in range(n):
    r1+=abs(a[i]-b)
    r2+=abs(a[i]-b-1)
print(min(r1,r2))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
b1 = a[n 
b2 = a[(n 
r1=0
r2=0
for i in range(n):
    r1+=abs(a[i]-b1)
    r2+=abs(a[i]-b2)
print(min(r1,r2))

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

A = [A[i]-(i+1) for i in range(N)]

ave1 = sum(A)
ave2 = (sum(A)+N)
ave3 = ave1 - 1

ans1 = 0
for i in range(N):
    ans1 +=abs(A[i]-ave1)

ans2 = 0
for j in range(N):
    ans2 += abs(A[i]-ave2)

ans3 = 0
for k in range(N):
    ans3 += abs(A[i]-ave3)
    
print (min(ans1, ans2, ans3))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
5


Fixed submission (verdict: Accepted):


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

A = [A[i]-(i+1) for i in range(N)]

A.sort()

center1 = A[N
if N == 1:
    center2 = 10 ** 9
else:
    center2 = A[(N+2)

ans1 = 0
for i in range(N):
    ans1 +=abs(A[i]-center1)
    
ans2 = 0
for j in range(N):
    ans2 += abs(A[j]-center2)
    
print (min(ans1, ans2))
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A2 = []
for i, a in enumerate(A):
    A2.append(a-i)
m = sum(A2)
an = 0
for a in A2:
    an += abs(m-a)
ans = an
an = 0
for a in A2:
    an += abs(m+1-a)
ans = min(ans, an)
print(ans)


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
28


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A2 = []
for i, a in enumerate(A):
    A2.append(a-i)
A2.sort()
m = A2[(N-1)
ans = 0
for a in A2:
    ans += abs(m-a)
print(ans)

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, *A = map(int, open(0).read().split())
    X, Y = 0, 0
    for i in range(N):
        a = A[i] - i - 1
        X += a
        Y += a**2
    b = X 
    
    ans1 = ans2 = 0
    for i in range(N):
        a = A[i] - i - 1
        ans1 += abs(a - b)
        ans2 += abs(a - b - 1)
    print(min(ans1, ans2))

if __name__ == '__main__':
  main()


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
def main():
    N, *A = map(int, open(0).read().split())
    B = [A[i] - i - 1 for i in range(N)]
    B.sort()
    b1 = B[(N-1)
    b2 = B[N
    ans1 = ans2 = 0
    for i in range(N):
        a = A[i] - i - 1
        ans1 += abs(a - b1)
        ans2 += abs(a - b2)
    print(min(ans1, ans2))

if __name__ == '__main__':
  main()

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

l = sorted([ x - (idx+1) for x,idx in enumerate(A)])
print(l)

import statistics
median = statistics.median(l)
print(median)

ans = 0
for x in l:
  ans += abs(x - median)
  
print(int(ans))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
[-3, -3, -2, -2, -2]
-2
2


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

l = sorted([ x - (idx+1) for x,idx in enumerate(A)])


import statistics
median = statistics.median(l)


ans = 0
for x in l:
  ans += abs(x - median)
  
print(int(ans))

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

c = [0] * n
for i in range(n):
    c[i] = a[i] - (i+1)

b = sum(c) 
ans = 0
for i in range(n):
    ans += abs(c[i] - b)

print(ans)


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


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

c = [0] * n
for i in range(n):
    c[i] = a[i] - (i+1)

c.sort()
b = c[n
ans = 0
for j in range(n):
    ans += abs(c[j] - b)

print(ans)
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - i for i in range(N)]
b1 = sum(A) 
b2 = b1+1
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))



Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
28


Fixed submission (verdict: Accepted):
N = int(input())
As = list(map(int, input().split()))
A = [As[i] - (i+1) for i in range(N)]
A.sort()
b1 = A[N
b2 = A[N
ans1 = 0
ans2 = 0
for i in range(N):
    ans1 += abs(A[i] -b1)
    ans2 += abs(A[i] - b2)
print(min(ans1, ans2))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
a = [i-i-1 for idx,i in enumerate(a)]
import statistics as st
b = st.median(a)
print(sum([abs(i-b) for i in a]))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
a = [i-idx-1 for idx,i in enumerate(a)]
import statistics as st
b = st.median(a)
print(int(sum([abs(i-b) for i in a])))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
B = [A[i]-i-1 for i in range(N)]

ave = sum(B)
ans1,ans2 = 0,0
for i in range(N):
    ans1 += abs(B[i]-ave)
    ans2 += abs(B[i]-ave-1)
print(min(ans1,ans2))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
B = [A[i]-i-1 for i in range(N)]
B.sort()

ave1,ave2 = B[N
ans1,ans2 = 0,0
for i in range(N):
    ans1 += abs(B[i]-ave1)
    ans2 += abs(B[i]-ave2)
print(min(ans1,ans2))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
Ap = [int(x) for x in input().split()]
A = [Ap[i]  -i-1 for i in range(N)]

sumA = sum(A)
if sumA % N == 0:
    b = sumA
    print( sum( [abs(x-b) for x in A] ) )
else:
    b1 = sumA
    b2 = b1 + 1
    print( min( sum( [abs(x-b) for x in A] ) for b in [b1,b2]))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
Ap = [int(x) for x in input().split()]
A = sorted([Ap[i]  -i-1 for i in range(N)])

if N % 2 != 0:
    b = A[(N+1)
    print( sum( [abs(x-b) for x in A] ) )
else:
    mf,mb = A[N
    if mb - mf >= 2:    b = mb -1
    else:  b = mb
    print( sum( [abs(x-b) for x in A] ) )
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    A[i]-=(i+1)

num=sum(A)
num2=sum(A)
B=[]
for i in range(n):
    A[i]-=num
    B.append(A[i]-1)
for i in range(n):
    A[i]=abs(A[i])
    B[i]=abs(B[i])


print(min(sum(A),sum(B)))



Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


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

A.sort()
if len(A)%2==1:
    num = A[len(A)
else:
    num = (A[len(A)
for i in range(n):
    A[i]-=num
for i in range(n):
    A[i]=abs(A[i])

print(sum(A))

Problem: p03311
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = input_int_list()
    for i in range(n):
        A[i] = A[i] - (i + 1)
    b = sum(A) 

    tmp0 = 0
    tmp1 = 0
    for a in A:
        tmp0 += abs(a - b)
        tmp1 += abs(a - b - 1)

    print(min(tmp0, tmp1))

    return


if __name__ == "__main__":
    main()


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    A = input_int_list()
    for i in range(n):
        A[i] = A[i] - (i + 1)

    A.sort()

    if n % 2 == 0:
        mid = (A[(n - 1) 
    else:
        mid = A[(n - 1) 

    tmp0 = 0
    tmp1 = 0

    for a in A:
        tmp0 += abs(a - mid)
        tmp1 += abs(a - mid - 1)

    print(min(tmp0, tmp1))

    return


if __name__ == "__main__":
    main()

Problem: p03311
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
  A[i] -= i+1


def calc(b):
  res = 0
  for i in range(N):
    res += abs(A[i]-b)
  return res

m = sum(A)
print(min(calc(m),calc(m+1)))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
  A[i] -= i+1
A.sort()


def calc(b):
  res = 0
  for i in range(N):
    res += abs(A[i]-b)
  return res

if N % 2 == 1:
  print(calc(A[N
else:
  print(min(calc(A[N
Problem: p03311
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
*a, =map(int,input().split())
a=[a[i]-(i+1) for i in range(n)]
a=sorted(a)
c1=sum(a)
c2=c1+1
ans=float('inf')

for c in [c1,c2]:
    tmp=0
    for i in range(n):
        tmp+=abs(a[i]-c)
    ans=min(ans, tmp)
print(ans)

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


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

c1=a[n
c2=a[n
ans=float('inf')

for c in [c1,c2]:
    tmp=0
    for i in range(n):
        tmp+=abs(a[i]-c)
    ans=min(ans, tmp)
print(ans)

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
    A[i]-=(i+1)

num=sum(A)
num2=sum(A)
B=[]
for i in range(n):
    A[i]-=num
    B.append(A[i]+1)
for i in range(n):
    A[i]=abs(A[i])
    B[i]=abs(B[i])


print(min(sum(A),sum(B)))



Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
3


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

A.sort()
if len(A)%2==1:
    num = A[len(A)
else:
    num = (A[len(A)
for i in range(n):
    A[i]-=num
for i in range(n):
    A[i]=abs(A[i])

print(sum(A))

Problem: p03311
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
c = [a[i]-i-1 for i in range(n)]
b = sum(c)
x = sum([abs(c[i]-b) for i in range(n)])
y = sum([abs(c[i]-b-1) for i in range(n)])
print(min(x,y))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
c = [a[i]-i-1 for i in range(n)]
c.sort()
mn = s = sum(c[1:])-(n-1)*c[0]
for i in range(n-1):
    s += (2*i+2-n)*(c[i+1]-c[i])
    mn = min(mn,s)
print(mn)

Problem: p03311
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

a = [ai - i for i, ai in enumerate(a)]
ave = sum(a) 
ans1 = sum(abs(ai - ave) for ai in a)
ans2 = sum(abs(ai - ave - 1) for ai in a)
print(min(ans1, ans2))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
28


Fixed submission (verdict: Accepted):
from statistics import median_low

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

a = [ai - i for i, ai in enumerate(a)]
med = median_low(a)
print(sum(abs(ai - med) for ai in a))
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

c = 0
for i in range(n):
    c += a[i] - i - 1

b = c
ret0 = 0
ret1 = 0
ret2 = 0
for i in range(n):
    ret0 += abs(a[i] - b - i)
    ret1 += abs(a[i] - b - i - 1)
    ret2 += abs(a[i] - b - i - 2)

print(min(ret0, ret1,ret2))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
3


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

c = [i for i in range(n)]
for i in range(n):
    c[i] = a[i] - i - 1

b = statistics.median(c)
ret0 = 0
ret1 = 0
ret2 = 0
for i in range(n):
    ret0 += abs(a[i] - b - i)
    ret1 += abs(a[i] - b - i - 1)
    ret2 += abs(a[i] - b - i - 2)

print(int(min(ret0, ret1,ret2)))

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

b = sum(A)
ans = 0
for i in range(N):
    ans += abs(A[i] - (b + i + 1))
print(ans)

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
83


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

B = []
for i in range(N):
    B.append(A[i]-i)
B.sort()
b = B[N

ans = 0
for i in range(N):
    ans += abs(A[i] - (b + i + 1))
print(ans)

Problem: p03311
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
ans_1=0
l=[0]*n
for i in range(1,n+1):
    l[i-1]=a[i-1]-i
c=sum(l)
ans_2=0
ans_3=0
for i in range(n):
    ans_1+=abs(a[i]-(c)-(i+1))
for i in range(n):
    ans_2+=abs(a[i]-(c-1)-(i+1))
for i in range(n):
    ans_3+=abs(a[i]-(c+1)-(i+1))
print(min(ans_1,ans_2,ans_3))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
for i in range(1,n+1):
    l[i-1]=a[i-1]-i
l.sort()
ans=0
if n%2==1:
    for i in range(n):
        ans+=abs(l[i]-(l[n
    print(ans)
else:
    ans_1=0
    ans_2=0
    for i in range(n):
        ans_1+=abs(l[i]-(l[n
    for i in range(n):
        ans_2+=abs(l[i]-(l[n
    print(min(ans_1,ans_2))

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

def f(a, n):
    b = sum(a) 
    b2 = (1+n) 
    
    res = []
    for x in [b, b2, b-b2, b2-b]:
        s = (x+i for i in range(1, n+1))
        sadness = sum(abs(ai - xi) for (ai, xi) in zip(a, s))
        res.append(sadness)
        
    return min(res)
    
n = int(input())
a = [int(i) for i in input().split()]
print(f(a, n))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
28


Fixed submission (verdict: Accepted):
import statistics

def f(a, n):
    a2 = [ai - (i+1) for (i,ai) in enumerate(a)]
    b = int(statistics.median(a2))
    
    sadness = sum(abs(ai - b) for ai in a2)
    
    b += 1
    sadness2 = sum(abs(ai - b) for ai in a2)

    
    return min(sadness, sadness2)
    
n = int(input())
a = [int(i) for i in input().split()]
print(f(a, n))
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
B = [a-i for i, a in enumerate(A)]
m = sum(B)
print(min(sum(abs(b-m) for b in B), sum(abs(b-m-1) for b in B)))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
28


Fixed submission (verdict: Accepted):
from statistics import median
N = int(input())
A = list(map(int, input().split()))
B = [a-i for i, a in enumerate(A)]
m = int(median(B))
print(sum(abs(b-m) for b in B))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    N, *A = map(int, open(0).read().split())
    X, Y = 0, 0
    for i in range(N):
        a = A[i] - i - 1
        X += a
        Y += a**2
    b = X 
    
    ans1 = ans2 = 0
    sign = 1 if X >= 0 else -1
    for i in range(N):
        a = A[i] - i - 1
        ans1 += abs(a - b)
        ans2 += abs(a - b - sign)
    print(min(ans1, ans2))

if __name__ == '__main__':
  main()


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
def main():
    N, *A = map(int, open(0).read().split())
    B = [A[i] - i - 1 for i in range(N)]
    B.sort()
    b1 = B[(N-1)
    b2 = B[N
    ans1 = ans2 = 0
    for i in range(N):
        a = A[i] - i - 1
        ans1 += abs(a - b1)
        ans2 += abs(a - b2)
    print(min(ans1, ans2))

if __name__ == '__main__':
  main()

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import statistics

def f(a, n):
    b = statistics.median(a)
    s = ((b+i) for i in range(1, n+1))
    sadness = sum(abs(ai - xi) for (ai, xi) in zip(a, s))
    return sadness
    
n = int(input())
a = [int(i) for i in input().split()]
print(f(a, n))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
13


Fixed submission (verdict: Accepted):
import statistics

def f(a, n):
    a2 = [ai - (i+1) for (i,ai) in enumerate(a)]
    b = int(statistics.median(a2))
    
    sadness = sum(abs(ai - b) for ai in a2)
    
    b += 1
    sadness2 = sum(abs(ai - b) for ai in a2)

    
    return min(sadness, sadness2)
    
n = int(input())
a = [int(i) for i in input().split()]
print(f(a, n))

Problem: p03311
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

a = [ai - i for i, ai in enumerate(a)]
ave = sum(a) 
ans1 = sum(abs(ai - ave) for ai in a)
ans2 = sum(abs(ai - ave + 1) for ai in a)
print(min(ans1, ans2))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
23


Fixed submission (verdict: Accepted):
from statistics import median_low

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

a = [ai - i for i, ai in enumerate(a)]
med = median_low(a)
print(sum(abs(ai - med) for ai in a))
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
sum = 0
for i in range(n): sum += a[i] - (i + 1)
b = sum 
ans = 0
for i in range(n): ans += abs(a[i] - (b + i + 1))
print(ans)

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
for i in range(n): a[i] -= i + 1
a.sort()
b = a[(n - 1) 
ans = 0
for i in range(n): ans += abs(a[i] - b)
print(ans)

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


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

for i in range(N):
    A[i] -= i + 1

b = sum(A) 
bb = b + 1

ans = 0
ansans = 0

for a in A:
    ans += abs(a - b)
    ansans += abs(a - bb)


print(min(ans, ansans))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):


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

if N ==1:
    print(0)
    exit()

for i in range(N):
    A[i] -= i + 1

A.sort()

b = A[N
bb = A[N

ans = 0
ansans = 0

for a in A:
    ans += abs(a - b)
    ansans += abs(a - bb)

print(min(ans, ansans))

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
B = [A[i]-i-1 for i in range(N)]

ave = sum(B)
ans1,ans2,ans3 = 0,0,0
for i in range(N):
    ans1 += abs(B[i]-ave)
    ans2 += abs(B[i]-ave-1)
    ans3 += abs(B[i]-ave+1)
print(min(ans1,ans2,ans3))

Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
B = [A[i]-i-1 for i in range(N)]
B.sort()

ave1,ave2 = B[N
ans1,ans2 = 0,0
for i in range(N):
    ans1 += abs(B[i]-ave1)
    ans2 += abs(B[i]-ave2)
print(min(ans1,ans2))

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

c = 0
for i in range(n):
    c += a[i] - i - 1

b = c
ret1 = 0
ret2 = 0
for i in range(n):
    ret1 += abs(a[i] - b - i - 1)
    ret2 += abs(a[i] - b - 1 - i - 1)

print(min(ret1,ret2))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


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

c = [i for i in range(n)]
for i in range(n):
    c[i] = a[i] - i - 1

b = statistics.median(c)
ret0 = 0
ret1 = 0
ret2 = 0
for i in range(n):
    ret0 += abs(a[i] - b - i)
    ret1 += abs(a[i] - b - i - 1)
    ret2 += abs(a[i] - b - i - 2)

print(int(min(ret0, ret1,ret2)))
Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A_dash = []
for i, A_i in enumerate(A):
    A_dash.append(A_i-(i+1))

A_set = set(A_dash)
grav = sum(A_dash)
left, right = 0, 0
for i, A_i in enumerate(A_dash):
    left += abs(A_i - (grav))
    right += abs(A_i - (grav + 1))
print(min(left, right))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A_dash = []
for i, A_i in enumerate(A):
    A_dash.append(A_i-(i+1))
A_dash.sort()

med = A_dash[N

ans = 0
for i, A_i in enumerate(A_dash):
    ans += abs(A_i - (med))

print(ans)

Problem: p03311
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
A = [int(v)-i for i, v in enumerate(input().split(), start=1)]


b0 = sum(A)
b1 = math.ceil(sum(A)/N)

print(min(sum([abs(a-b0) for a in A]), sum([abs(a-b1) for a in A])))


Failing test case input:
5
2 2 3 5 5

Expected output:
2

Actual output:
3


Fixed submission (verdict: Accepted):
import math
N = int(input())
A = sorted([int(v)-i for i, v in enumerate(input().split(), start=1)])

if N % 2 == 1:
    ans = sum([abs(a-A[N
else:
    b0 = (A[N
    b1 = math.ceil(A[N
    ans = min(sum([abs(a-b0) for a in A]), sum([abs(a-b1) for a in A]))

print(ans)
Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
H, W = list(map(int, input().split(' ')))
tiles = [list(map(int, input().split(' '))) for i in range(H)]

dp = [[0 for j in range(W)] for i in range(H)]
max_width = 0
for i in range(H): dp[i][0] = (tiles[i][0] + 1)%2
for j in range(W): dp[0][j] = (tiles[0][j] + 1)%2
for i in range(H):
    for j in range(W):
        if tiles[i][j] == 1:
            dp[i][j] == 0
        else:
            dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]) + 1
            max_width = max(max_width, dp[i][j])
print(max_width**2)


Failing test case input:
1 5
1 0 1 0 0
1 0 0 0 1
0 0 0 1 -1
0 -1 0 1 0

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
H, W = list(map(int, input().split(' ')))
tiles = [list(map(int, input().split(' '))) for i in range(H)]

dp = [[0 for j in range(W)] for i in range(H)]
max_width = 0
for i in range(H):
    dp[i][0] = (tiles[i][0] + 1)%2
    if max_width == 0 and dp[i][0] == 1: max_width = 1
for j in range(W):
    dp[0][j] = (tiles[0][j] + 1)%2
    if max_width == 0 and dp[0][j] == 1: max_width = 1
for i in range(1, H):
    for j in range(1, W):
        if tiles[i][j] == 1:
            dp[i][j] == 0
        else:
            dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1]) + 1
            max_width = max(max_width, dp[i][j])
print(max_width**2)

Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):


H,W = [int(i) for i in input().split()]
table = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    table[i] = [1 - int(j) for j in input().split()]

ans = 0
for i in range(1,H):
    for j in range(1,W):
        if table[i][j] == 1:
            table[i][j] = min(table[i-1][j-1], table[i][j-1], table[i-1][j]) + 1
            ans = max(table[i][j], ans)

print(ans*ans)



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

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):


H,W = [int(i) for i in input().split()]
table = [[0 for i in range(W)] for j in range(H)]

ans = 0

for i in range(H):
    table[i] = [1 - int(j) for j in input().split()]

for i in range(H):
    for j in range(W):
        if table[i][j] == 1:
            ans = 1

for i in range(1,H):
    for j in range(1,W):
        if table[i][j] == 1:
            table[i][j] = min(table[i-1][j-1], table[i][j-1], table[i-1][j]) + 1
            ans = max(table[i][j], ans)

print(ans*ans)
Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[1 for i in range(W)] for i in range(H)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H):
    for j in range(1,W):
        if tile[i-1][j]==1 or tile[i][j-1]==1 or tile[i-1][j-1]==1:
            buf[i][j] = 1
        elif tile[i-1][j]==tile[i][j-1]:
            buf[i][j] = buf[i-1][j-1]+1
        else:
            buf[i][j] = min(buf[i-1][j] , buf[i][j-1])+1

        if buf[i][j] > maxsquare:
            maxsquare = buf[i][j]

for i in buf:
    print(i)

print(maxsquare**2)

Failing test case input:
3 5
0 0 1 0 0
1 0 0 -1 0
0 0 0 1 1
0 0 0 0 1

Expected output:
4


Actual output:
[1, 1, 1, 1, 1]
[1, 1, 1, 1, 2]
[1, 1, 2, 2, 1]
4


Fixed submission (verdict: Accepted):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[0 for i in range(W+1)] for i in range(H+1)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H+1):
    for j in range(1,W+1):
        if tile[i-1][j-1]!=1:
            buf[i][j] = min(buf[i-1][j],buf[i][j-1],buf[i-1][j-1]) + 1

            if buf[i][j] > maxsquare:
                maxsquare = buf[i][j]

print(maxsquare**2)

Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):

from itertools import product
H, W = tuple(map(int, input().split()))

C = [tuple(map(int, input().split())) for _ in range(H)]
S = [[1]*W for _ in range(H)]
for h, w in product(range(H), range(W)):
    if C[h][w] == 1:
        S[h][w] = 0

for h, w in product(range(H), range(W)):
    if S[h][w]:
        S[h][w] = min(S[h-1][w-1], S[h-1][w], S[h][w-1]) + 1

result = 0
for sh in S:
    result = max(max(sh), result)

print(result**2)

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

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):

from itertools import product
H, W = tuple(map(int, input().split()))

C = [tuple(map(int, input().split())) for _ in range(H)]
S = [[1]*W for _ in range(H)]
for h, w in product(range(H), range(W)):
    if C[h][w] == 1:
        S[h][w] = 0

for h, w in product(range(1, H), range(1, W)):
    if S[h][w]:
        S[h][w] = min(S[h-1][w-1], S[h-1][w], S[h][w-1]) + 1

result = 0
for sh in S:
    result = max(max(sh), result)

print(result**2)
Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[1 for i in range(W)] for i in range(H)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H):
    for j in range(1,W):
        if tile[i-1][j]==1 or tile[i][j-1]==1 or tile[i-1][j-1]==1:
            buf[i][j] = 1
        elif tile[i-1][j]==tile[i][j-1]:
            buf[i][j] = buf[i-1][j-1]+1
        else:
            buf[i][j] = min(buf[i-1][j] , buf[i][j-1])+1

        if buf[i][j] > maxsquare:
            maxsquare = buf[i][j]

print(maxsquare**2)

Failing test case input:
4 5
0 -1 1 0 0
1 -1 3 0 0
0 0 2 1 0
0 0 0 1 0

Expected output:
4


Actual output:
9


Fixed submission (verdict: Accepted):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[0 for i in range(W+1)] for i in range(H+1)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H+1):
    for j in range(1,W+1):
        if tile[i-1][j-1]!=1:
            buf[i][j] = min(buf[i-1][j],buf[i][j-1],buf[i-1][j-1]) + 1

            if buf[i][j] > maxsquare:
                maxsquare = buf[i][j]

print(maxsquare**2)

Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[1 for i in range(W)] for i in range(H)]
maxsquare = 1

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H):
    for j in range(1,W):
        if tile[i][j]!=1:
            if tile[i-1][j]==1 or tile[i][j-1]==1 or tile[i-1][j-1]==1:
                buf[i][j] = 1
            elif tile[i-1][j]==tile[i][j-1]:
                buf[i][j] = buf[i-1][j-1]+1
            else:
                buf[i][j] = min(buf[i-1][j] , buf[i][j-1])+1

            if buf[i][j] > maxsquare:
                maxsquare = buf[i][j]


print(maxsquare**2)

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

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[0 for i in range(W+1)] for i in range(H+1)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H+1):
    for j in range(1,W+1):
        if tile[i-1][j-1]!=1:
            buf[i][j] = min(buf[i-1][j],buf[i][j-1],buf[i-1][j-1]) + 1

            if buf[i][j] > maxsquare:
                maxsquare = buf[i][j]

print(maxsquare**2)
Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
H, W = map(int, input().split())
c = []
for i in range(H):
    c.append([int(i) for i in input().split()])
dp = [[0 for i in range(W)] for i in range(H)]
dp[0][0] = 1 if c[0][0] == 0 else 0
for j in range(W):
    if c[0][0] == 1:
        dp[0][j] = 0
    else:
        dp[0][j] = 1

for j in range(H):
    if c[0][0] == 1:
        dp[j][0] = 0
    else:
        dp[j][0] = 1

for i in range(1, H):
    for j in range(1, W):
        dp[i][j] = min(dp[i-1][j], dp[i-1][j-1], dp[i][j-1]) + 1

print(dp[H-1][W-1])


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

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
H, W = map(int, input().split())
c = []
for i in range(H):
    c.append([int(i) for i in input().split()])
dp = [[0 for i in range(W)] for i in range(H)]
maxwidth = 0
for i in range(H):
    for j in range(W):
        dp[i][j] = (c[i][j] + 1) % 2
        maxwidth |= dp[i][j]

for i in range(1, H):
    for j in range(1, W):
        if c[i][j]:
            dp[i][j] = 0
        else:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-1], dp[i][j-1]) + 1
            maxwidth = max(maxwidth,dp[i][j])

print(maxwidth**2)

Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[1 for i in range(W)] for i in range(H)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H):
    for j in range(1,W):
        if tile[i][j]!=1:
            if tile[i-1][j]==1 or tile[i][j-1]==1 or tile[i-1][j-1]==1:
                buf[i][j] = 1
            elif tile[i-1][j]==tile[i][j-1]:
                buf[i][j] = buf[i-1][j-1]+1
            else:
                buf[i][j] = min(buf[i-1][j] , buf[i][j-1])+1

            if buf[i][j] > maxsquare:
                maxsquare = buf[i][j]


print(maxsquare**2)

Failing test case input:
4 5
0 -1 0 1 1
1 -1 3 0 0
0 0 2 1 0
0 0 0 2 0

Expected output:
4


Actual output:
9


Fixed submission (verdict: Accepted):
H,W = map(int,input().split())
tile = [[0 for i in range(W)] for i in range(H)]
buf = [[0 for i in range(W+1)] for i in range(H+1)]
maxsquare = 0

for i in range(H):
    tile[i] = list(map(int,input().split()))

for i in range(1,H+1):
    for j in range(1,W+1):
        if tile[i-1][j-1]!=1:
            buf[i][j] = min(buf[i-1][j],buf[i][j-1],buf[i-1][j-1]) + 1

            if buf[i][j] > maxsquare:
                maxsquare = buf[i][j]

print(maxsquare**2)
Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):



H, W = map(int, input().split())
C = list()

for h in range(H):
    C.append(list(map(int, input().split())))

dp = dict()
for h in range(H+1):
    dp[(h, 0)] = 0

for w in range(W+1):
    dp[(0, w)] = 0

for h in range(1, H+1):
    for w in range(1, W+1):
        dp[(h, w)] = min(dp[(h-1, w-1)], dp[(h-1, w)], dp[(h, w-1)]) + 1

print(dp[(H, W)])

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

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):



H, W = map(int, input().split())
C = list()
maxWidth = 0

for h in range(H):
    C.append(list(map(int, input().split())))

dp = dict()
for h in range(H+1):
    dp[(h, 0)] = 0

for w in range(W+1):
    dp[(0, w)] = 0

for h in range(1, H+1):
    for w in range(1, W+1):
        if C[h-1][w-1] == 1:
            dp[(h, w)] = 0
        else:
            dp[(h, w)] = min(dp[(h-1, w-1)], dp[(h-1, w)], dp[(h, w-1)]) + 1
            maxWidth = max(dp[(h, w)], maxWidth)

print(maxWidth**2)

Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):
h, w = map(int, input().split())
floor = [[1] + list(map(int, input().split())) for i in range(h)]
max_square, prev = 0, [0] * (w + 1)
for i in range(h):
    current = [0] * (w + 1)
    for j in range(1, w + 1):
        if floor[i][j]:
            current[j] = 0
            continue
        current[j] = min(prev[j - 1], prev[j], current[j - 1]) + 1
    prev = current
    max_square = max(max_square, max(current))

print(max_square ** max_square)

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

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
h, w = map(int, input().split())
floor = [[1] + list(map(int, input().split())) for i in range(h)]
max_square, prev = 0, [0] * (w + 1)
for i in range(h):
    current = [0] * (w + 1)
    for j in range(1, w + 1):
        if floor[i][j]:
            current[j] = 0
            continue
        current[j] = min(prev[j - 1], prev[j], current[j - 1]) + 1
    prev = current
    max_square = max(max_square, max(current))

print(max_square ** 2)
Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):



H, W = map(int, input().split())
C = list()
maxWidth = 0

for h in range(H):
    C.append(list(map(int, input().split())))

dp = dict()
for h in range(H+1):
    dp[(h, 0)] = 0

for w in range(W+1):
    dp[(0, w)] = 0

for h in range(1, H+1):
    for w in range(1, W+1):
        if C[h-1][w-1] == 1:
            dp[(h, w)] = 0
        else:
            dp[(h, w)] = min(dp[(h-1, w-1)], dp[(h-1, w)], dp[(h, w-1)]) + 1
            maxWidth = max(dp[(h, w)], maxWidth)

print(maxWidth)

Failing test case input:
4 5
0 0 1 0 0
1 0 0 0 1
0 0 0 1 1
-1 -1 0 0 0

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):



H, W = map(int, input().split())
C = list()
maxWidth = 0

for h in range(H):
    C.append(list(map(int, input().split())))

dp = dict()
for h in range(H+1):
    dp[(h, 0)] = 0

for w in range(W+1):
    dp[(0, w)] = 0

for h in range(1, H+1):
    for w in range(1, W+1):
        if C[h-1][w-1] == 1:
            dp[(h, w)] = 0
        else:
            dp[(h, w)] = min(dp[(h-1, w-1)], dp[(h-1, w)], dp[(h, w-1)]) + 1
            maxWidth = max(dp[(h, w)], maxWidth)

print(maxWidth**2)

Problem: p02326
Buggy submission (Python3, verdict: Wrong Answer):




import sys


def solve():
    dp = [[0] * W for _ in range(H)]
    max_width = 0

    
    
    
    
    

    for i in range(1, H):
        for j in range(1, W):
            if not int(carpet_info[i][j]):
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
                max_width = max(max_width, dp[i][j])

    return max_width


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    H, W = map(int, _input[0].split())
    carpet_info = list(map(lambda x: x.split(), _input[1:]))
    print(solve())

Failing test case input:
3 5
0 0 1 0 0
0 0 0 -1 1
1 0 0 0 1
0 -1 0 0 -1

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):




import sys


def solve():
    dp = [[0] * W for _ in range(H)]
    max_width = 0
    for m in range(H):
        for n in range(W):
            dp[m][n] = (int(carpet_info[m][n]) + 1) % 2
            max_width |= dp[m][n]

    for i in range(1, H):
        for j in range(1, W):
            if not int(carpet_info[i][j]):
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
                max_width = max(max_width, dp[i][j])
                
    return pow(max_width, 2)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    H, W = map(int, _input[0].split())
    carpet_info = list(map(lambda x: x.split(), _input[1:]))
    print(solve())