Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03644 (python)

Fixed submission:
import math
print(2**math.floor(math.log(int(input()))/math.log(2)))

Buggy submission (verdict: Runtime Error):
import math
print(2**math.floor(math.log2(int(input()))))
Problem p03651 (python)

Fixed submission:
from fractions import gcd
n,k=map(int,input().split())
g=0
m=0
for a in map(int,input().split()):
    g=gcd(g,a)
    m=max(m,a)

print("POSSIBLE" if(k%g==0 and k<=m) else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n,k=map(int,input().split())
g=0
m=0
for a in map(int,input().split()):
  	m=max(m,a)
    g=gcd(g,a)

print("POSSIBLE" if(k%g==0 and k<=m) else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
from fractions import gcd
n,k=map(int,input().split())
g=0
for a in map(int,input().split()):
    if(k==a):
        print("POSSIBLE")
        return
    g=gcd(g,a)

print("POSSIBLE" if(k%g==0) else "IMPOSSIBLE")
Problem p03673 (python)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
if n%2:
    print(*l[::-2], end=' ')
    print(*l[1::2])
else:
    print(*l[::-2], end=' ')
    print(*l[0::2])

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],*A[N%2::2])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
if n%2:
    print(*l[::-2],*l[1::2])
else:
    print(*l[::-2],*l[0::2])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
if n%2:
    print(*l[::-2],*l[1::2])
else:
    print(*l[::-2],*l[0::2])
Problem p03730 (python)

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

a,b,c = map(int,input().split())
print("YES") if c%gcd(a,b)==0 else print("NO")

Buggy submission (verdict: Runtime Error):
import math
a,b,c = map(int,input().split())
print("YES") if c%math.gcd(a,b)==0 else print("NO")
Problem p03738 (python)

Fixed submission:
a,b = [int(input()) for _ in range(2)]
print("GREATER") if a>b else print("LESS") if a<b else print("EQUAL")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print("GREATER") if a>b else print("LESS") if a<b else print("EQUAL")
Problem p03952 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

def resolve():
    n,x=map(int,input().split())
    if(x!=1 and x!=2*n-1):
        print("Yes")
    else:
        print("No")
        return

    if(n==2):
        print(1,2,3)
        return

    if(x!=2):
        ans=[i for i in range(1,2*n) if(i not in [x-2,x-1,x,x+1])]
        ans=ans[:n-2]+[x-2,x,x+1,x-1]+ans[n-2:]
        print(*ans)
    else:
        ans=[i for i in range(5,2*n)]
        ans=ans[:n-2]+[1,2,4,3]+ans[n-2:]
        print(*ans)
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from statistics import median
def median_pyramid(p):
    N=len(p)
    assert(N&1)
    while(N!=1):
        p=[median((p[i],p[i+1],p[i+2])) for i in range(N-2)]
        N-=2
    return p[0]

def resolve():
    n,x=map(int,input().split())
    if(x!=1 and x!=2*n-1):
        print("Yes")
    else:
        print("No")
        return

    if(n==1):
        print(1,2,3)
        return

    if(x!=2):
        ans=[i for i in range(1,2*n) if(i not in [x-2,x-1,x,x+1])]
        ans=ans[:n-2]+[x-2,x,x+1,x-1]+ans[n-2:]
        print(*ans)
    else:
        ans=[i for i in range(5,2*n)]
        ans=ans[:n-2]+[1,2,4,3]+ans[n-2:]
        print(*ans)
resolve()
Problem p03999 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=sys.stdin.readline
def resolve():
    s=input()
    n=len(s)
    ans=0
    from itertools import product
    for A in product(range(2),repeat=n-1):
        k=s[0]
        for i in range(n-1):
            k+='+' if A[i] else ''
            k+=s[i+1]
        ans+=eval(k)
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    s=input()
    n=len(s)
    ans=0
    from itertools import product
    for A in product(range(2),repeat=n-1):
        k=s[0]
        for i in range(n-1):
            k+='+' if A[i] else ''
            k+=s[i+1]
        ans+=eval(k)
    print(ans)
resolve()
Problem p04014 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def f(b,n):
    if(n<b): return n
    return f(b,n//b)+n%b

def resolve():
    n=int(input())
    s=int(input())

    if(s>n):
        print(-1)
        return
    if(s==n):
        print(n+1)
        return

    # 2 <= b <= sqrt(n) を全探索
    k=int(n**.5)
    for b in range(2,k+2):
        if(f(b,n)==s):
            print(b)
            return

    # sqrt(n) < b <= n を考える
    B=[]
    for p in range(1,k+1):
        if((n-s)%p): continue
        b=(n-s)//p+1
        if(b<2): continue
        if(f(b,n)==s):
            B.append(b)

    print(min(B) if(B) else -1)
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def f(b,n):
    if(n<b): return n
    return f(b,n//b)+n%b

def resolve():
    n=int(input())
    s=int(input())

    if(s>n):
        print(-1)
        return
    if(s==n):
        print(n+1)
        return

    k=int(n**.5)
    for b in range(2,k+1):
        if(f(b,n)==s):
            print(b)
            return

    B=[]
    for p in range(1,b):
        q=s-p
        if(0>q or b-1<q): continue
        if((n-q)%p): continue
        t=(n-q)//p
        if(k<t<=n):
            B.append(t)

    print(min(B) if(B) else -1)
resolve()
Problem p02534 (python)

Fixed submission:
x = int(input())

if(x < 1 or x > 5):
  print("")
else:
  for i in range(x):
    print("ACL",end='')

Buggy submission (verdict: Runtime Error):
a,b,c,d=(int(x) for x in input().split())

if(a < 0 or c < 0 or b < 0 or d < 0):
    print("")
else:
    if(b <= d):
	    if(b >= c and c >= a):
  		    print("Yes")
	    else:
  		    print("No")
    else:
        if(c <= a & a <= d):
            print("Yes")
        else:
          	print("No")
Problem p02534 (python)

Fixed submission:
K=int(input())
print("ACL"*K)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())

notcalled=list(range(1,N+1))
nets=[]
for _ in range(M):
    a,b=map(int, input().split())
    if a in notcalled and b in notcalled:
        nets.append([a,b])
        del notcalled[notcalled.index(a)]
        del notcalled[notcalled.index(b)]
    elif a in notcalled:
        for net in nets:
            if b in net:
                net.append(a)
        del notcalled[notcalled.index(a)]
    elif b in notcalled:
        for net in nets:
            if a in net:
                net.append(b)
        del notcalled[notcalled.index(b)]
    else:
        for net in nets:
            f=True
            if a in net or b in net:
                if f:
                    q=net.copy
                    del net
                else:
                    net.extend(q)

nets.extend(notcalled)
print(len(nets)-1)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())

notcalled=list(range(N))
nets=[]
for _ in range(M):
    a,b=map(int, input().split())
    if a in notcalled and b in notcalled:
        nets.append([a,b])
        del notcalled[notcalled.index(a)]
        del notcalled[notcalled.index(b)]
    elif a in notcalled:
        for net in nets:
            if b in net:
                net.append(a)
        del notcalled[notcalled.index(a)]
    elif b in notcalled:
        for net in nets:
            if a in net:
                net.append(b)
        del notcalled[notcalled.index(b)]
    else:
        for net in nets:
            f=True
            if a in net or b in net:
                if f:
                    q=net.copy
                    del net
                else:
                    net.extend(q)

nets.extend(notcalled)
print(len(nets)-1)
Problem p02534 (python)

Fixed submission:
K = int(input())
A = ""
for i in range(K):
  A += "ACL"
  
print(A)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
 
ans = []
 
i = 0
while(i<=N-1):
  a = A[i]
  T = 1
  b = i
  while (b<=N-2):
    if ( abs(a-A[b+1]) <= K ):
      T += 1
      a = A[b+1]
    else:
      T += 0
    b += 1
  ans.append(T)
  i += 1
  
print(max(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
 
ans = []
 
i = 0
while(i<=N-1):
  a = A[i]
  T = 1
  b = i
  while (b<=N-2):
    if ( abs(a-A[b+1]) <= K ):
      T += 1
      a = A[b+1]
    else:
      T += 0
    b += 1
  ans.append(T)
  i += 1
  
print(max(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]


ans = []

i = 0
while(i<=N-2):
  a = A[i]
  T = 1
  while (i<=N-3):
    if ( abs(a-A[i+1]) <= K ):
      T += 1
      a = A[i]
    i += 1
  ans.append(T)
  i += 1
  
print(max(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]


ans = []

i = 0
while(i<=N-2):
  a = A[i]
  T = 1
  while (i<=N-2):
    if ( abs(a-A[i]) <= K ):
      T += 1
      a = A[i]
    i += 1
  ans.append(T)
  i += 1
  
print(max(ans))

Buggy submission (verdict: Runtime Error):
K = int(input())
A = ""
for i in range(K):
  A += ACL
  
print(A)
Problem p02687 (python)

Fixed submission:
S = str(input())
if(S == "ARC"):
  print("ABC")
else:
  print("ARC")

Buggy submission (verdict: Runtime Error):
p = 0
N = int(input())
A = list(map(int , input().split()))
for i in range(N):
  for j in range(N):
    sa = abs(i-j)
    wa = A[i]+A[j]
    
    if(sa == wa):
      p += 1
print(p//2)

Buggy submission (verdict: Runtime Error):
X = int(input())
 
for a in range(-119 , 120 , 1):
  A = a**5
  for b in range(-119 , 120 , 1):
    B = b**5
    if(A-B==X):
      print(a, b)
      exit()
    else:
      continue

Buggy submission (verdict: Runtime Error):
X = int(input())
a = 1
b = 1
while True:  
  if(a**5 - b**5 == X):
    print(a , b)
    break
  a += 1
  for i in range(X):
    b += 1
    if(a**5 - b**5 == X):
      print(a , b)
      exit()
while True:
  if(a**5 - b**5 == X):
    print(a , b)
    break
  b -= 1
  for j in range(X):
    b -= 1
    if(a**5 - b**5 == X):
      print(a , b)
      exit()
Problem p02536 (python)

Fixed submission:

import sys
sys.setrecursionlimit(10000)

class UnionFindTree:
	def __init__(self,size):
		"""
		size個の集合を作成
		負の値は、ルートで集合の個数
		正の値は、次の要素
		"""
		self.table=[-1 for _ in range(size)]

	def find(self,x):
		"""
		グループ番号を取得
		"""
		# 本質的には、木を上に辿るだけ
		# ただし、通常、UnionFindでは経路圧縮を行うのが普通らしい
		if self.table[x] < 0:
			# 一個上がルートならば、それを返して終わり
			return x
		else:
			# そうでなければ、ルートまで辿るついでに経路圧縮
			self.table[x] = self.find(self.table[x])
			return self.table[x]
		return x

	# 併合
	def union(self,x,y):
		# s1,s2は正
		# table[s1],table[s2]は負
		s1=self.find(x)
		s2=self.find(y)
		if s1!=s2:
			# 個数が小さい方をルートにくっつける
			# ルートサイズは負なので、ルートが大きい方が個数が小さい?
			if self.table[s2]<=self.table[s1]:
				# s1が小さい
				self.table[s1]+=self.table[s2]
				self.table[s2]=s1
			else:
				# s2が小さい
				self.table[s2]+=self.table[s1]
				self.table[s1]=s2
			return True
		return False

	def groupCount(self):
		ret=0
		for i in range(len(self.table)):
			if self.table[i] < 0:
				ret+=1
		return ret

N,M=map(int,input().split())

UF=UnionFindTree(N)

for _ in range(M):
	A,B=map(int,input().split())
	UF.union(A-1,B-1)


print(UF.groupCount()-1)

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10000)

class UnionFindTree:
	def __init__(self,size):
		"""
		size個の集合を作成
		負の値は、ルートで集合の個数
		正の値は、次の要素
		"""
		self.table=[-1 for _ in range(size)]

	def find(self,x):
		"""
		グループ番号を取得
		"""
		# 本質的には、木を上に辿るだけ
		# ただし、通常、UnionFindでは経路圧縮を行うのが普通らしい
		if self.table[x] < 0:
			# 一個上がルートならば、それを返して終わり
			return x
		else:
			# そうでなければ、ルートまで辿るついでに経路圧縮
			self.table[x] = self.find(self.table[x])
			return self.table[x]
		return x

	# 併合
	def union(self,x,y):
		# s1,s2は正
		# table[s1],table[s2]は負
		s1=self.find(x)
		s2=self.find(y)
		if s1!=s2:
			# 個数が小さい方をルートにくっつける
			# ルートサイズは負なので、ルートが大きい方が個数が小さい?
			if self.table[s2]<=self.table[s1]:
				# s1が小さい
				self.table[s1]+=self.table[s2]
				self.table[s2]=s1
			else:
				# s2が小さい
				self.table[s2]+=self.table[s1]
				self.table[s1]=s2
			return True
		return False

	def groupCount(self):
		ret=0
		for i in range(len(self.table)):
			if self.table[i] < 0:
				ret+=1
		return ret

N,M=map(int,input().split())

UF=UnionFindTree(N)

for n in range(M):
	A,B=map(int,input().split())
	UF.union(A,B)


print(UF.groupCount()-1)
Problem p02588 (python)

Fixed submission:
N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={}


for n in range(N):
	tmpA = float(input())
	tmpA = round(tmpA*(10**PRECISION_DIGITS))
	#print(tmpA)

	two = 0
	five = 0
	while (tmpA % 2) == 0:
		two += 1
		tmpA /= 2
	while (tmpA % 5) == 0:
		five += 1
		tmpA /= 5

	if (two,five) in cnt:
		cnt[(two,five)]+=1
	else:
		cnt[(two,five)]=1

keys=sorted(cnt.keys())
# print(keys)
ans = 0
for t1 in keys:
	for t2 in keys:
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 18 <= t1[0]+t2[0] and 18 <= t1[1]+t2[1]:
			cnt1 = cnt[(t1[0],t1[1])]
			cnt2 = cnt[(t2[0],t2[1])]
			if t1 < t2:
				ans += int(cnt1*cnt2)
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int(cnt1*(cnt1-1)/2)


print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N=int(input())
A=[]
PRECISION_DIGITS=9
NO_ENTRY = 0
cnt=np.full((PRECISION_DIGITS*2,PRECISION_DIGITS*2),NO_ENTRY,int)
# cnt=np.zeros((PRECISION_DIGITS*2,PRECISION_DIGITS*2),int)

# print(cnt)

for n in range(N):
	tmpA = float(input())
	tmpA = int(tmpA*10**PRECISION_DIGITS)
	#print(tmpA)

	five = 0
	two = 0
	# (10**9) -> (two,five)=(9,9)
	# min = 10**-9, ignore < 10**9 ???
	while (tmpA % 5) == 0 and five < PRECISION_DIGITS*2:
		five += 1
		tmpA //= 5
	while (tmpA % 2) == 0 and two < PRECISION_DIGITS*2:
		two += 1
		tmpA //= 2

	if cnt[two][five] == 0:
		cnt[two][five]=1
	else:
		cnt[two][five]+=1

# print(cnt)
ans = 0

for x1 in range(PRECISION_DIGITS*2):
	for y1 in range(PRECISION_DIGITS*2):
		if cnt[x1][y1] == NO_ENTRY:
			continue

		for x2 in range(PRECISION_DIGITS*2):
			for y2 in range(PRECISION_DIGITS*2):
				if cnt[x2][y2] == NO_ENTRY:
					continue
				# 2**a(a>=0) and 5**b(b>=0) => integer
				if 0 <= x1+x2 - PRECISION_DIGITS*2 and 0 <= y1+y2 -PRECISION_DIGITS*2:
					if x1 == x2 and y1 == y2:
						# same entry
						# Total number of combinations choose 2 items
						# nC2 = n*(n-1)/2
						ans += int((cnt[x1][y1]*(cnt[x2][y2]-1))//2)
					else:
						ans += cnt[x1][y1]*cnt[x2][y2]

		# count up completed entry
		cnt[x1][y1] = NO_ENTRY

print(ans)
Problem p03070 (python)

Fixed submission:
import numpy as np

MOD=998244353
N=int(input())
A=np.array([int(input()) for _ in range(N)])
TOTAL=pow(3,N,MOD)
ASum=sum(A)
sumEnd=0
sumEnd=ASum//2+1

dp=np.array([0 for _ in range(sumEnd)],dtype=np.int64)
dp[0] = 1

for n in range(N):
	dp[A[n]:] += dp[:-A[n]]*2 % MOD

plus = 0
if ASum % 2 == 0:
	# 合計が偶数
	dpOther=np.array([0 for _ in range(sumEnd+1)],dtype=np.int64)
	dpOther[0] = 1
	for n in range(N):
		dpOther[A[n]:] += dpOther[:-A[n]] % MOD
	plus = (dpOther[ASum//2]*3) % MOD

exceptCnt=0
for s in range(0,sumEnd):
	exceptCnt = (exceptCnt + dp[s]*3) % MOD

exceptCnt -= plus
print((TOTAL - exceptCnt) % MOD )

Buggy submission (verdict: Runtime Error):
import numpy as np

MOD=998244353
N=int(input())
A=np.array([int(input()) for _ in range(N)],dtype=np.uint32)

TOTAL=pow(3,N,MOD)
ASum=np.sum(A)

# dp=[[0 for _ in range(ASum+1)] for _ in range(2)]
dp=np.zeros((2,ASum+1),dtype=np.uint32)
dp[0][0] = 2
dp[0][A[0]] = 1

# dpOther=[[0 for _ in range(ASum+1)] for _ in range(2)]
dpOther=np.zeros((2,ASum+1),dtype=np.uint32)
dpOther[0][0] = 1
dpOther[0][A[0]] = 1

prev=0
current=1
curMax=A[0]
# for n in range(1,N):
for n, a in enumerate(A):
	if n==0:
		continue
	# curMax += a
	current = n % 2
	prev = (n+1) % 2
	# for e in range(curMax+1):
	dp[current,:] = dp[prev,:]*2 % MOD
	dp[current,a:] += dp[prev,:-a] % MOD

	if ASum %2 == 0:
		dpOther[current,:] = dpOther[prev,:] % MOD
		dpOther[current,a:] += dpOther[prev,:-a] % MOD

sumStart = 0
plus = 0

if ASum % 2 == 0:
	# 合計が偶数
	sumStart=ASum//2
	plus = (dpOther[current][ASum//2]*3) % MOD
else:
	# 合計が奇数の場合、ceil
	sumStart=ASum//2+1

exceptCnt=0
for s in range(sumStart,ASum+1):
	exceptCnt = (exceptCnt + dp[current][s]*3) % MOD

exceptCnt -= plus

print((TOTAL - exceptCnt) % MOD )
Problem p03087 (python)

Fixed submission:
N,Q=map(int,input().split())

S=input()

# 最初からNまでに何個ACがあったか
cnt=[0 for _ in range(N)]

prev=""

for i in range(N):
	if S[i]=="C":
		if prev=="A":
			cnt[i]+=1
	if i!=0:
		cnt[i]+=cnt[i-1]
	prev = S[i]

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = cnt[R-1]-cnt[L-1]
 	print(ans)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())

S=input()

# 最初からNまでに何個ACがあったか
cnt=[0 for _ in range(N)]

prevA=False

for i in range(N):
	if S[i]=="C":
		if prev=="A":
			cnt[i]+=1
	if i!=0:
		cnt[i]+=cnt[i-1]
	prev = S[i]

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = cnt[R-1]-cnt[L-1]
 	print(ans)
Problem p03095 (python)

Fixed submission:
N=int(input())
S=list(map(lambda x: ord(x),input()))
MOD = 10**9 + 7 # 1e9 + 7

# 各文字列について、出現回数+1(1つ取るか、一切とらない)
# それを全部かければ良い

AppearCount = [ 0 for _ in range(26)]

for n in range(N):
	AppearCount[S[n]-ord('a')] += 1

ans = 1
bFirst = True

for a in AppearCount:
	if a != 0:
		ans *= (a+1)
		while MOD < ans:
			ans -= MOD

ans -= 1

while MOD <= ans:
	ans -= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=list(map(lambda x: ord(x),input()))
MOD = 10e9 + 7


# 各文字列について、出現回数+1(1つ取るか、一切とらない)
# それを全部かければ良い

AppearCount = [ 0 for _ in range(26)]

for n in range(N):
	AppearCount[S[n]-ord('a')] += 1

ans = 1

for n in range(N):
	if AppearCount[n] != 0:
		ans *= (AppearCount[n]+1)
		if MOD <= ans:
			ans -= MOD

print(ans-1)
Problem p03309 (python)

Fixed submission:
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	# print(b)
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
		# print(A[n])
		# print(n)
		# print(val)
		# print(abs(A[n]-(b+n+1)))
		# print("")
	return val

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

M=[]

for i,a in enumerate(A):
	#if a - (i+1) not in M:
	M.append( a - (i+1) )

M.sort()
lenM=len(M)

if lenM==1:
	ans=calcVal(M[0])

elif lenM==2:
	ans=min(calcVal(M[0]),calcVal(M[1]))


else:
	med1=lenM//2-1
	med2=lenM//2
	#print(M)
	ans=min(calcVal(M[med1]),calcVal(M[med2]),calcVal(0))



print(ans)

Buggy submission (verdict: Runtime Error):
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
		# print(A[n])
		# print(n)
		# print(val)
		# print(abs(A[n]-(b+n+1)))
		# print("")
	return val

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

M=[]

for i,a in enumerate(A):
	M.append( a - (i+1) )

M.sort()

if N%2==0:
	med1=N//2
	med2=N//2+1
	if N <= med2:
		med2 = med1
	ans=min(calcVal(M[med1]),calcVal(M[med2]),calcVal(0))

else:
	med=(N+1)//2
	print(M[med])
	ans = min(calcVal(M[med]),calcVal(0))


print(ans)

Buggy submission (verdict: Runtime Error):
# 整数列A 
# abs(A1-(b+1))+abs(A2-(b+2))+...+abs(An-(b+N))の最小値
# bは任意
# すなわち、その時のbを求めれば良い問題

# 結局、bを、Ai-iの中央値にすれば最適解。

def calcVal(b):
	val = 0
	for n in range(N):
		val += abs(A[n]-(b+n+1))
	return val

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

M=[]

for i,a in enumerate(A):
	M.append( a - (i+1) )

M.sort()

if N%2==0:
	med1=N//2
	med2=N//2+1
	ans=min(calcVal(M[med1]),calcVal(M[med2]))

else:
	med=(N+1)//2
	ans = calcVal(M[med])


print(ans)
Problem p02534 (python)

Fixed submission:
k = int(input())
print('ACL'*k)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
l = []
cnt = 0
for i in range (m):
    a, b = map(int, input().split()) 
    if (a in l) or (b in l):
        l.append(a)
        l.append(b)
        
    else:
        l.append(a)
        l.append(b)
        cnt += 1
        
    l =list(set(l))

l = set(l)
x = n - len(l) 

print(cnt+x-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
l = []
cnt = 0
for i in range (m):
    a, b = map(int, input().split()) 
    if (a in l) or (b in l):
        l.append(a)
        l.append(b)
        
    else:
        l.append(a)
        l.append(b)
        cnt += 1
        
    l =list(set(l))

l = set(l)
x = n - len(l) 

print(cnt+x-1)
Problem p02641 (python)

Fixed submission:
x,n=map(int,input().split())
l=list(map(int,input().split()))
if x not in l:
    print(x)
elif n==0:
    print(x)
else:
    a=101
    p1=0
    for i in range(102):
        if i not in l:
            if abs(x-i)<a:
                a=abs(x-i)
                p1=i

    print(p1)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
p=0
if x==0:
  print(n)
elif n not in l:
  print(n)
else:
  for i in range(101):
    if abs(x-i)>abs(x-p) and i not in p:
      p=i
  print(p)

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
if n == 0:
    print(0)
else:
    l = list(map(int, input().split()))
    l.sort()
    k1 = [i for i in range(min(l), max(l) + 1) if i not in l]
    d = {}
    for i in range(len(k1)):
        d[k1[i]] =max(k1[i],k)-min(k1[i],k)
    k2 = min(d, key=d.get)
    if len(d)==0 or len(k1)<=1:
        print(0)
    else:
        print(k2)

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
if n == 0:
    print(0)
else:
    l = list(map(int, input().split()))
    l.sort()
    k1 = [i for i in range(min(l), max(l) + 1) if i not in l]
    d = {}
    for i in range(len(k1)):
        d[k1[i]] =max(k1[i],k)-min(k1[i],k)
    k2 = min(d, key=d.get)
    if len(d)==0 or len(k1)==0:
        print(0)
    else:
        print(k2)

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
if n == 0:
    print(0)
else:
    l = list(map(int, input().split()))
    l.sort()
    k1 = [i for i in range(min(l), max(l) + 1) if i not in l]
    d = {}
    for i in range(len(k1)):
        d[k1[i]] =max(k1[i],k)-min(k1[i],k)
    k2 = min(d, key=d.get)
    if len(d)==0:
      print(0)
    else:
      print(k2)

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
if n == 0:
    print(0)
else:
    l = list(map(int, input().split()))
    l.sort()
    k1 = [i for i in range(min(l), max(l) + 1) if i not in l]
    d = {}
    for i in range(len(k1)):
        d[k1[i]] =max(k1[i],k)-min(k1[i],k)
    k2 = min(d, key=d.get)
    print(k2)

Buggy submission (verdict: Runtime Error):
k,n=map(int,input().split())
if n==0:
    print(0)
else:
    l=list(map(int,input().split()))
    l.sort()
    k1=[i for i in range(min(l),max(l)+1) if i not in l]
    d={}
    for i in range(len(k1)):
        d[k1[i]]=abs(k1[i]-k)
    k2=min(d,key=d.get)
    print(k2)