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

Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort(reverse=True)

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]
  ans_list+=lc[:(x+y)]

  ans_list.sort(reverse=True)


  # print(ans_list)
  return sum(ans_list[:x+y])

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort()

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]

  ans_list.sort(reverse=True)
  # print(ans_list)
  i=0
  for _ in range(c):
    if len(lc)==0:
      break
    if x+y<len(lc):
      lc.pop()
    else:
      while True:
        if len(ans_list)<=i:
          break
        _c=lc.pop()
        if ans_list[i]<_c:
          ans_list[i]=_c
        else:
          lc.append(_c)
        i+=1

  # print(ans_list)
  return sum(ans_list)

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,y,a,b,c=LI()
  la=LI()
  lb=LI()
  lc=LI()

  la.sort(reverse=True)
  lb.sort(reverse=True)
  lc.sort(reverse=True)

  ans_list=[]
  ans_list+=la[:x]
  ans_list+=lb[:y]

  ans_list.sort(reverse=True)
  i=1
  for _ in range(c):
    if a+b<len(lc):
      lc.pop()
    else:
      _c=lc.pop()
      if ans_list[-i]<=_c:
        ans_list[-i]=_c
        i+=1

  return sum(ans_list)

# main()
print(main())
Problem p02743 (python)

Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c=LI()

  if c-a-b<=0:
    return 'No'

  if 4*a*b<(c-a-b)**2:
    return 'Yes'
  return 'No'

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c=LI()

  if 4*a*b<(c-a-b)**2:
    return 'Yes'
  aaaa

# main()
print(main())
Problem p02814 (python)

Fixed submission:
# https://atcoder.jp/contests/abc150/tasks/abc150_d
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# GCD -- START --
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
# GCD --- END ---

# LCM -- START --
def lcm(x,y):
  return x*y//gcd(x,y)
# LCM --- END ---

def f(x):
  a=0
  while x%2==0:
    x//=2
    a+=1
  return a

def main():
  n,m=LI()
  _l=LI()
  l=[x//2 for x in _l]

  t=f(l[0])
  for i in range(n):
    b=l[i]
    if t!=f(b):
      return 0
    l[i]>>=t
  m>>=t

  _lcm=1
  for x in l:
    _lcm=lcm(_lcm,x)
    if _lcm>m:
      return 0

  # print(m,_lcm)
  m//=_lcm
  return (m+1)//2

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# GCD -- START --
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x
# GCD --- END ---

# LCM -- START --
def lcm(x,y):
  return x*y//gcd(x,y)
# LCM --- END ---

def main():
  # X=ak(p+0.5)
  #  =ak*p+0.5*ak
  # akとpは整数よりak*pは整数
  # 0.5*akが整数になるにはakは偶数（制約の指定もあり）
  # X=(ak/2)*(2p+1)
  # 2p+1は奇数なのでXとak'の2で割れる回数は一致する
  # 2で割れる回数が一致しない例
  # 6と8なら
  # 6,3,9,15,21,27,...
  # 8,4,12,20,28,36,...
  # 一致しない
  # 全体を2^tで割れる（割れないなら0）
  # X'=(ak/2)'*(2p+1)
  # (X'=X/(2^t),(ak/2)'=(ak/2)/(2^t))
  # M/(2^t)以下で
  # (ak/2)'の公倍数を奇数倍したものが何個あるかを数える

  n,m=LI()
  m/=2
  _l=LI()
  l=[x//2 for x in _l]

  a=l[0]
  x=0
  while True:
    if a%(2**x)!=0:
      x-=1
      break
    x+=1

  c=2**x
  for i in range(n):
    b=l[i]
    if b%c!=0 or b%(c*2)==0:
      # print(b,c)
      return 0

    l[i]=b//c

  _lcm=l[0]
  for x in l[1:]:
    _lcm=lcm(_lcm,x)

  # print(m,_lcm)
  return math.ceil(m/_lcm)

# main()
print(main())
Problem p02900 (python)

Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l

def main():
  a,b=LI()

  if a==1 and b==1:
    return 1

  a=getPrimeList(a)
  b=getPrimeList(b)

  a=list(set(a))
  b=list(set(b))

  c=a+b
  c.sort()

  ans=1
  y=c[0]
  cnt=1
  for x in c[1:]:
    if x==y:
      cnt+=1
    else:
      y=x
      cnt=1

    if cnt==2:
      ans+=1

  return ans

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l

def main():
  a,b=LI()

  a=getPrimeList(a)
  b=getPrimeList(b)

  a=list(set(a))
  b=list(set(b))

  c=a+b
  c.sort()

  ans=1
  y=c[0]
  cnt=1
  for x in c[1:]:
    if x==y:
      cnt+=1
    else:
      y=x
      cnt=1

    if cnt==2:
      ans+=1

  return ans

# main()
print(main())
Problem p02936 (python)

Fixed submission:
import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

nmax=2*10**5+10
graph=[[] for _ in range(nmax)]
level=[-1]*nmax

def dfs(n,s,l):
  if len(graph[s])==0:
    return
  for e in graph[s]:
    if level[e]==-1:
      level[e]=level[s]+1
    if level[e]>level[s]:
      l[e]+=l[s]
      dfs(n,e,l)

def main():
  n,q=LI()
  for _ in range(n-1):
    a,b=LI()
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  l=[0]*n
  for _ in range(q):
    a,b=LI()
    l[a-1]+=b

  level[0]=0
  dfs(n,0,l)

  return ' '.join([str(x) for x in l])

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

cost=[0]*200010
G=[[] for _ in range(200010)]
visited=[False]*200010
visited[0]=True

def dfs(s):
  global cost
  global G
  global visited
  for e in G[s]:
    if visited[e]==False:
      cost[e]+=cost[s]
      visited[e]=True
      dfs(e)
      visited[e]=False

def main():
  global cost
  global G
  global visited
  n,q=LI()
  for _ in range(n-1):
    a,b=LI()
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

  for i in range(q):
    p,x=LI()
    p-=1
    cost[p]+=x
  dfs(0)

  return ' '.join([str(x) for x in cost[:n]])

# main()
print(main())
Problem p02972 (python)

Fixed submission:
import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  ans=[0]*n

  ind=n
  for i in range(n):
    sm=0
    for j in range(2,n+1):
      if ind*j>n:
        break
      else:
        sm+=ans[ind*j-1]
    ans[ind-1]=(l[ind-1]+sm)%2
    ind-=1
    # print(ans,ind)

  # print(ans)

  _ans=[]
  for i,x in enumerate(ans):
    if x==1:
      _ans.append(i+1)

  ln=len(_ans)
  print(ln)
  if ln!=0:
    print(' '.join([str(x) for x in _ans]))

main()
# print(main())

Buggy submission (verdict: Runtime Error):
# ABC134-D

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  a=1
  ind=0
  ad=l[0]
  while True:
    if ind+a<n:
      ind+=a
      ad+=l[ind]
    else:
      if ad%2!=l[a-1]:
        # print(ad,l[a-1])
        print(-1)
        exit()
      else:
        a+=1
        ad=0
        ind=a-1
        if a==n:
          break

  ans=[]
  for i,x in enumerate(l):
    if x==1:
      ans.append(i+1)

  print(len(ans))
  if len(ans)==0:
    exit()
  print(' '.join([str(x) for x in ans]))

main()
# print(main())
Problem p03061 (python)

Fixed submission:
# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

# struct
class struct:
  def __init__(self,a,b,c):
    self.a=a
    self.b=b
    self.c=c

n=int(input())
if n==2:
  a,b=map(int,input().split())
  print(max(a,b))
  exit()
elif n==3:
  a,b,c=map(int,input().split())
  print(max(gcd(a,b),gcd(a,c),gcd(b,c)))
  exit()
else:
  l=list(map(int,input().split()))
  a=l[0]
  b=l[1]
  c=l[2]
  d=l[3]
  l2=[]
  l2.append(struct(a,b,gcd(a,b)))
  l2.append(struct(a,c,gcd(a,c)))
  l2.append(struct(a,d,gcd(a,d)))
  l2.append(struct(b,c,gcd(b,c)))
  l2.append(struct(b,d,gcd(b,d)))
  l2.append(struct(c,d,gcd(c,d)))
  l2=sorted(l2,key=lambda x:(x.c,x.a,x.b))
  l3=[l2[0].a,l2[0].b,l2[1].a,l2[1].b]
  jama=10000000000000000
  if l3.count(l3[0])>1:
    jama=l3[0]
  if l3.count(l3[1])>1:
    jama=l3[1]
  if l3.count(l3[2])>1:
    jama=l3[2]
  if l3.count(l3[3])>1:
    jama=l3[3]
  mein=100000000000000000
  if jama==a:
    mein=gcd(gcd(b,c),d)
  if jama==b:
    mein=gcd(gcd(a,c),d)
  if jama==c:
    mein=gcd(gcd(a,c),d)
  if jama==d:
    mein=gcd(gcd(b,c),a)
  for x in l[4:]:
    xx=gcd(mein,x)
    yy=gcd(mein,jama)
    if xx<yy:
      jama=x
      mein=yy
    else:
      mein=xx
  print(mein)

Buggy submission (verdict: Runtime Error):
# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

# struct
class struct:
  def __init__(self,a,b,c):
    self.a=a
    self.b=b
    self.c=c

n=int(input())
if n==2:
  a,b=map(int,input().split())
  print(max(a,b))
  exit()
elif n==3:
  a,b,c=map(int,input().split())
  print(max(gcd(a,b),gcd(a,c),gcd(b,c)))
  exit()
else:
  l=list(map(int,input().split()))
  a=l[0]
  b=l[1]
  c=l[2]
  d=l[3]
  l2=[]
  l2.append(struct(a,b,gcd(a,b)))
  l2.append(struct(a,c,gcd(a,c)))
  l2.append(struct(a,d,gcd(a,d)))
  l2.append(struct(b,c,gcd(b,c)))
  l2.append(struct(b,d,gcd(b,d)))
  l2.append(struct(c,d,gcd(c,d)))
  l2=sorted(l2,key=lambda x:(x.c,x.a,x.b))
  aa=l2[0].a
  l3=[l2[0].c,l2[1].c,l2[2].c,l2[3].c,l2[4].c,l2[5].c]
  l3=list(set(l3))
  bb=l3[1]
  for x in l:
    xx=gcd(bb,x)
    yy=gcd(bb,aa)
    if xx<yy:
      aa=x
      bb=yy
  print(bb)
Problem p03074 (python)

Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=1000000007
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarize_list(sl):

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append(c)
      a=x
      c=1
  res.append(c)

  return res
# Summarize count of factor within list --- END ---

def main():
  n,k=LI()
  s=list(S())

  l=summarize_list(s)
  # print(l)

  # 1 0 1 0... の形にする
  if s[0]=='0':
    l=[0]+l

  # ...0 1 0 1 の形にする
  if s[-1]=='0':
    l+=[0]

  # 累積和
  for i in range(len(l)-1):
    l[i+1]+=l[i]

  l=[0]+l

  # print(l)

  ans=0
  left=0
  while True:
    right=min(len(l)-1,left+2*k+1)
    if left>=len(l):
      return ans

    # print(right,left)
    ans=max(ans,l[right]-l[left])

    left+=2

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=l

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append(c)
      a=x
      c=1
  res.append(c)

  return res

def main():
  n,k=LI()
  s=list(S())

  l=summarize_list(s)

  for i in range(len(l)-1):
    l[i+1]+=l[i]
  l=[0]+l

  mx=-inf
  if s[0]=='1':
    haba=2*k+1
    for i in range(len(l)-haba+1):
      if i%2==0:
        mx=max(mx,l[i+haba]-l[i])
  else:
    a

  return mx

# main()
print(main())

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
s=input()
s+='a'
l=[]
a=s[0]

if a=='0':
  f=0
else:
  f=1

for x in s[1:]:
  if a[0]!=x:
    l.append(len(a))
    a=x
  else:
    a+=x

if len(l)%2==0:
  pass
else:
  l=l+[0]

l2=[]

if f==1:
  pass
else:
  l2=[0]+l2

for i in range(len(l)):
  if i%2==0:
    l2.append(l[i]+l[i+1])

mx=sum(l2[:2*(k-1)+1])
a=l2[0]
for i in range(len(l2)-1):
  print(i)
  x=l2[i+k+1]
  if a<x:
    mx+=x
    mx-=a
    a=l2[i]

print(mx)
Problem p03150 (python)

Fixed submission:
s=input()
x='keyence'
if s==x:
  print('YES')
  exit()
if s.count(x)>0:
  p=s.split('keyence')
  if p[0]=='' or p[1]=='':
    print('YES')
    exit()
  elif p[0]+p[1]=='keyence':
    print('YES')
    exit()
for i in range(1,len(x)):
  a=x[:i]
  b=x[i:]
  if s.count(a)>0 and (s.index(a)==0 and s[len(s)-len(b):]==b):
    print('YES')
    exit()
  else:
    continue
print('NO')

Buggy submission (verdict: Runtime Error):
s=input()
x='keyence'
if s==x:
  print('YES')
  exit()
if s.count(x)>0:
  p=s.split('keyence')
  if p[0]=='' or p[1]=='':
    print('YES')
    exit()
  elif p[0]+p[1]=='keyence':
    print('YES')
    exit()
for i in range(1,len(x)):
  a=x[:i]
  b=x[i:]
  if s.index(a)==0 and s[len(s)-len(b):]==b:
    print('YES')
    exit()
  else:
    continue
print('NO')
Problem p03157 (python)

Fixed submission:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[False]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if visited[i][j]:
        continue
      if field[i][j]!='#':
        continue
      q=collections.deque()
      q.append((i,j))
      b=0
      wh=0
      while q:
        y,x=q.popleft()
        if visited[y][x]:
          continue
        if field[y][x]=='#':
          b+=1
        else:
          wh+=1
        visited[y][x]=True
        for dy,dx in dd:
          ny=y+dy
          nx=x+dx
          if not (0<=ny<h and 0<=nx<w):
            continue
          if field[y][x]==field[ny][nx]:
            continue
          if visited[ny][nx]:
            continue
          q.append((ny,nx))
      ans+=b*wh
      # print(i,j,b,wh,ans)
  return ans

# main()
print(main())

Buggy submission (verdict: Runtime Error):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        q=collections.deque()
        visited=[[False]*w for _ in range(h)]
        q.append((i,j))
        while q:
          y,x=q.popleft()
          if visited[y][x]:
            continue
          visited[y][x]=True
          for dy,dx in dd:
            ny=y+dy
            nx=x+dx
            if 0<=ny<h and 0<=nx<w:
              if field[y][x]==field[ny][nx]:
                continue
              if visited[ny][nx]:
                continue
              if field[ny][nx]=='.':
                # ans+=1
              q.append((ny,nx))
    # print(ans)
  return ans

# main()
print(main())
Problem p03160 (python)

Fixed submission:
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b

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

l2=[struct(0,0) for _ in range(n)]
l2[0].a=l[0]
l2[1].a=l[1]
l2[1].b=abs(l[0]-l[1])

i=2
for x in l[2:]:
  l2[i].a=x
  l2[i].b=min(abs(l2[i-2].a-x)+l2[i-2].b,
    abs(l2[i-1].a-x)+l2[i-1].b)
  i+=1

print(l2[-1].b)

Buggy submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  dp=[inf]*10
  dp[0]=0
  dp[1]=0
  dp[2]=abs(l[1]-l[0])

  for i in range(2,n):
    dp[i+1]=min(dp[i-1]+abs(l[i]-l[i-2]),dp[i]+abs(l[i]-l[i-1]))

  return dp[n]

print(main())

Buggy submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  dp=[0]*110

  dp[1]=0
  dp[2]=abs(l[0]-l[1])
  for i in range(2,n):
    dp[i+1]=min(dp[i]+abs(l[i]-l[i-1]),dp[i-1]+abs(l[i]-l[i-2]))

  return dp[n]

print(main())

Buggy submission (verdict: Runtime Error):
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b

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

l2=[struct(0,0) for _ in 3]
l2[0].a=l[0]
l2[1].a=l[1]
l2[1].b=abs(l[0]-l[1])

for x in l[2:]:
  l[0]=l[1]
  l[1]=l[2]
  l2[2].a=x
  l2[2].b=min(abs(l2[0].a-x)+l2[0].b,
    abs(l2[1].a-x)+l2[1].b)

print(l2[2].b)
Problem p03161 (python)

Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  dp=[inf]*100010
  dp[0]=0
  for i in range(n):
    for j in range(1,k+1):
      if i+j<n:
        dp[i+j]=min(dp[i+j],dp[i]+abs(l[i+j]-l[i]))

  return dp[n-1]

print(main())

Buggy submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  dp=[inf]*11
  dp[0]=0

  for j in range(n):
    for i in range(1,k+1):
      if i+j<n:
        dp[i+j]=min(dp[i+j],dp[j]+abs(l[i+j]-l[j]))

  return dp[n-1]

print(main())