Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
ans=1

def fib(n):
  if n==1:
    return 1
  elif n<=0:
    return 0
  tmp1,tmp2=1,2
  for _ in range(n-2):
    tmp1,tmp2=tmp2,tmp1+tmp2
  return tmp2

for i in range(m):
  if i==0 and a[0]==1:
    pass
  if i==0 and a[0]!=1:
    ans*=a[i]-1
  elif i>0:
  	ans*=fib(a[i]-a[i-1]-2)
  ans%=1000000007

ans*=fib(n-a[-1]-1)
ans%=1000000007
print(ans)

Fixed submission:
import math

def fib(n):
  if n==1:
    return 1
  elif n<=0:
    return 0
  tmp1,tmp2=1,2
  for _ in range(n-2):
    tmp1,tmp2=tmp2,tmp1+tmp2
  return tmp2

n,m=map(int,input().split())
if m==0:
  print(fib(n)%1000000007)
  exit()
a=[int(input()) for _ in range(m)]
ans=1

if n==2 and a[0]==1:
  print(1)
  exit()

for i in range(m):
  if i==0 and a[0]==1:
    pass
  if i==0 and a[0]!=1:
    ans*=fib(a[i]-1)
  elif i>0 and a[i]-a[i-1]==2:
    pass
  elif i>0 and a[i]-a[i-1]!=2:
  	ans*=fib(a[i]-a[i-1]-2)
  ans%=1000000007
  
if n-a[-1]>1: 
  ans*=fib(n-a[-1]-1)
ans%=1000000007
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
ans=1

def fib(n):
  if n==1:
    return 1
  elif n<=0:
    return 0
  tmp1,tmp2=1,2
  for _ in range(n-2):
    tmp1,tmp2=tmp2,tmp1+tmp2
  return tmp2

for i in range(m):
  if i==0 and a[0]==1:
    pass
  if i==0 and a[0]!=1:
    ans*=a[i]-1
  elif i>0:
  	ans*=fib(a[i]-a[i-1]-2)
  ans%=1000000007

ans*=fib(n-a[-1]-1)
ans%=1000000007
print(ans)

Fixed submission:
import math

def fib(n):
  if n==1:
    return 1
  elif n<=0:
    return 0
  tmp1,tmp2=1,2
  for _ in range(n-2):
    tmp1,tmp2=tmp2,tmp1+tmp2
  return tmp2

n,m=map(int,input().split())
if m==0:
  print(fib(n)%1000000007)
  exit()
a=[int(input()) for _ in range(m)]
ans=1

if n==2 and a[0]==1:
  print(1)
  exit()

for i in range(m):
  if i==0 and a[0]==1:
    pass
  if i==0 and a[0]!=1:
    ans*=fib(a[i]-1)
  elif i>0 and a[i]-a[i-1]==2:
    pass
  elif i>0 and a[i]-a[i-1]!=2:
  	ans*=fib(a[i]-a[i-1]-2)
  ans%=1000000007
  
if n-a[-1]>1: 
  ans*=fib(n-a[-1]-1)
ans%=1000000007
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
def gcd_l(a):
  tmp=a[0]
  for i in range(len(a)):
    tmp=gcd(tmp,a[i])
  return tmp
tmp=gcd_l(a)
for i in range(n):
  b=[a[j] for j in range(len(a)) if i!=j]
  tmp=max(gcd_l(b),tmp)
print(tmp)

Fixed submission:
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
def gcd_l(a):
  tmp=a[0]
  for i in range(len(a)):
    tmp=gcd(tmp,a[i])
  return tmp
tmp=gcd_l(a[1:])
p=set()
for i in range(1,int(a[0]**0.5)+1):
  if a[0]%i==0:
    if i>tmp:
      p.add(i)
    if a[0]//i>tmp:
      p.add(a[0]//i)
if len(p)==0:
  print(tmp)
  exit()
p=sorted(list(p),reverse=True)
for x in p:
  b=[not a[i]%x for i in range(n)]
  if sum(b)==n-1:
    print(x)
    exit()
print(tmp)
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=s[:i+1].count('AC')

for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])

Fixed submission:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=a[i-1]
  if s[i-1:i+1]=='AC':
    a[i]+=1

for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q =map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]

p=[s[i]+s[i+1]=='AC' for i in range(n-1)]

for i in range(q):
  cnt=sum(p[l[i][0]-1:l[i][1]-1])
  print(cnt)


Fixed submission:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=a[i-1]
  if s[i-1:i+1]=='AC':
    a[i]+=1

for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q =map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]

p=[i+1 for i in range(n-1) if s[i]+s[i+1]=='AC']

for i in range(q):
  cnt=sum([l[i][0]<=x<l[i][1] for x in p])
  print(cnt)


Fixed submission:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=a[i-1]
  if s[i-1:i+1]=='AC':
    a[i]+=1

for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,q =map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]

p=[s[i]+s[i+1] for i in range(n-1)]

for i in range(q):
  print(sum([x=='AC' for x in p[l[i][0]-1:l[i][1]-1]]))

Fixed submission:
n,q=map(int,input().split())
s=input()
l=[list(map(int,input().split())) for _ in range(q)]
a=[0]*n

for i in range(n):
  a[i]=a[i-1]
  if s[i-1:i+1]=='AC':
    a[i]+=1

for i in range(q):
  print(a[l[i][1]-1]-a[l[i][0]-1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
h=list(map(int,input().split()))
arr=[x for x in h]
cnt=0

while 1:
  for i in range(n):
    if h[i]!=0:
      s=i
      break
  e=s
  for i in range(s,n-1):
    if h[s]<=h[i+1]:
      e+=1
    else:
      break
  h=[h[i]-1 if s<=i<=e else h[i] for i in range(n)]
  cnt+=1
  if all([x==0 for x in h]):
    break
print(cnt)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
arr=[x for x in h]
cnt=0

while 1:
  if all([x==0 for x in h]):
    break
  for i in range(n):
    if h[i]!=0:
      s=i
      break
  e=s
  for i in range(s,n-1):
    if h[s]<=h[i+1]:
      e+=1
    else:
      break
  h=[h[i]-1 if s<=i<=e else h[i] for i in range(n)]
  cnt+=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
k,s=map(int,input().split())

cnt=0
for x,y,z in itertools.product(range(k+1),range(k+1),range(k+1)):
  if x+y+z==s:
    cnt+=1
print(cnt)

Fixed submission:
import itertools
k,s=map(int,input().split())

arr=[]
cnt=0

for x in range(k+1):
  for y in range(x,k+1):
    z=s-x-y
    if y<=z<=k:
      if x==y==z:
        cnt+=1
      elif x==y or y==z or z==x:
        cnt+=3
      else:
        cnt+=6
print(cnt)
Buggy python submission (verdict: Runtime Error):
def main():
    n,x,m=map(int,input().split())
    visited=[0]*m
    visit_sum=[0]*m
    i=1
    sm=x
    visited[x]=1
    visit_sum[x]=x
    work=x
    while i < n:
        work**=2
        work%=m
        sm+=work
        i+=1
#        print(sm,work)
        if not visited[work]:
            visited[work]=i
            visit_sum[work]=sm
        else :
            break
    else :
        print(sm)
        exit()
    loop_sum=sm-visit_sum[work]
    loop_num=i-visited[work]
    initial_sum=visit_sum[visited.index(visited[work]-1)]

    out=initial_sum
#    print(out)
    out+=(n-visited[work]+1)//loop_num*loop_sum
#    print(out)
    work_num=(n-visited[work]+1)%loop_num
    if work_num>0:
        out+=visit_sum[visited.index(visited[work]-1+work_num)]-initial_sum
    print(out)

main()

Fixed submission:
def main():
    n,x,m=map(int,input().split())
    visited=[0]*m
    visit_sum=[0]*m
    i=1
    sm=x
    visited[x]=1
    visit_sum[x]=x
    work=x
    while i < n:
        work**=2
        work%=m
        sm+=work
        i+=1
#        print(sm,work)
        if not visited[work]:
            visited[work]=i
            visit_sum[work]=sm
        else :
            break
    else :
        print(sm)
        exit()
    loop_sum=sm-visit_sum[work]
    loop_num=i-visited[work]
    if visited[work]!=1: 
        initial_sum=visit_sum[visited.index(visited[work]-1)]
    else :
        initial_sum=0

    out=initial_sum
#    print(out)
    out+=(n-visited[work]+1)//loop_num*loop_sum
#    print(out)
    work_num=(n-visited[work]+1)%loop_num
    if work_num>0:
        out+=visit_sum[visited.index(visited[work]-1+work_num)]-initial_sum
        
    print(out)

main()
Buggy python submission (verdict: Time Limit Exceeded):
def divi(n):
    if n in prime: return 2
    sm=1
    for x in prime:
        token=0
        while n%x==0:
            n=n//x
            token+=1
        if token : sm*=(token+1)
        if n==1 : break
    return sm


n=int(input())
lst=[True for i in range(n+1)]
lst[0]=False
lst[1]=False

for i in range(2,n+1):
    if lst[i] :
        j=2*i
        while j<=n:
            lst[j]=False
            j+=i
prime=[i for i in range(n+1) if lst[i]]

sm=1
for i in range(2,n+1):
    sm+=i*divi(i)
print(sm)

Fixed submission:
n=int(input())
sm=0
for i in range(1,n+1):
    sm+=i*(n//i)*(n//i+1)//2
print(sm)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as comb

n,k=map(int,input().split())
p=list(map(int,input().split()))

min=None
for x in comb(range(n),k):
    sm=0
    for i in range(len(x)):
        sm+=p[x[i]]
    if not min : min=sm
    if sm<min : min=sm
print(min)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
sm=sum(p[:k])
print(sm)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
ref=[0 for _ in range(mx-2)]
for j in range(n):
    work=b[j]
    for i in range(mx-2):
        ref[i]+=int(work[i])
        ref[i]%=2

for j in range(n):
    work=b[j]
    for i in range(mx-2):
        if int(work[i])==ref[i]:out[j]+="0"
        else : out[j]+="1"

c=[str(int(y,2)) for y in out]
print(" ".join(c))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
for i in range(mx-2):
    tot=0
    for j in range(n):
        tot+=int(b[j][i])
    tot=tot%2
    for j in range(n):
        if tot==int(b[j][i]):out[j]+="0"
        else : out[j]+="1"
c=[str(int(y,2)) for y in out]
print(" ".join(c))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
for i in range(mx-2):
    tot=0
    for j in range(n):
        tot+=int(b[j][i])
    tot=tot%2
    for j in range(n):
        if tot==int(b[j][i]):out[j]+="0"
        else : out[j]+="1"
c=[str(int(y,2)) for y in out]
print(" ".join(c))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
mx=len(bin(max(a)))
b=["0"*(mx-len(bin(x)))+bin(x)[2:] for x in a]

out=["" for _ in range(n)]
for i in range(mx-2):
    tot=0
    for j in range(n):
        tot+=int(b[j][i])
    tot=tot%2
    for j in range(n):
        if tot==int(b[j][i]):out[j]+="0"
        else : out[j]+="1"
c=[str(int(y,2)) for y in out]
print(" ".join(c))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
l.sort()
work=[]
while l:
    if len(l)==1 or l[1]!=l[0]:work.append(l[0])
    l=[x for x in l[1:] if x%l[0]!=0]
print(len(work))

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
m=l[-1]
work=[0]*(m+1)
for i in l:
    if work[i]<=1:
        for j in range(i,m+1,i):
            work[j]+=1
sm=0
for s in l:
    if work[s]==1: sm+=1
print(sm)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
sm=0
for i in range(n):
    var=l[i]
    for j in range(n):
        if i==j:continue
        if var%l[j]==0:
            break
    else: sm+=1
print(sm)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
m=l[-1]
work=[0]*(m+1)
for i in l:
    if work[i]<=1:
        for j in range(i,m+1,i):
            work[j]+=1
sm=0
for s in l:
    if work[s]==1: sm+=1
print(sm)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
sm=0
for i in range(n):
    var=l[i]
    for j in range(n):
        if i==j:continue
        if var%l[j]==0:
            break
    else: sm+=1
print(sm)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
l.sort()
m=l[-1]
work=[0]*(m+1)
for i in l:
    if work[i]<=1:
        for j in range(i,m+1,i):
            work[j]+=1
sm=0
for s in l:
    if work[s]==1: sm+=1
print(sm)
Buggy python submission (verdict: Runtime Error):
n,s=map(int,input().split())
a=list(map(int,input().split()))
d=[[0]*(s+1) for _ in range(n+1)]
d[0][0]=1
for j in range(0,s+1):
    for i in range(1,n+1):
        d[i][j]=2*d[i-1][j]
        if a[i-1]<=j:
            d[i][j]+=d[i-1][j-a[i-1]]
        d[i][j]=d[i][j]%998244353
print(d[n][s])

Fixed submission:
a,b=map(int,input().split())
print(a*b)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n=int(input())
lst=deque([])
counter=0
for _ in range(n):
    s=input()
    if s in lst : continue
    lst.append(s)
    counter+=1

print(counter)

Fixed submission:
n=int(input())
lst=set([])
counter=0
for _ in range(n):
    s=input()
    if s in lst : continue
    lst.add(s)
    counter+=1

print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
lst=[]
counter=0
for _ in range(n):
    s=input()
    if s in lst : continue
    lst.append(s)
    counter+=1

print(counter)

Fixed submission:
n=int(input())
lst=set([])
counter=0
for _ in range(n):
    s=input()
    if s in lst : continue
    lst.add(s)
    counter+=1

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
lst=list(map(int,input().split()))
for i in range(1,n+1):
    print(lst.count(i))

Fixed submission:
from collections import Counter

n=int(input())
lst=Counter(list(map(int,input().split())))
for i in range(1,n+1):
    if i in lst : print(lst[i])
    else : print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
sm=0
for x in [(x,y,z) for x in range(10) for y in range(10) for z in range(10)]:
    token=0
    for i in range(n):
        if x[token]==int(s[i]):
            token+=1
            if token==3 : break
    if token==3 : sm+=1
print(sm)

Fixed submission:
n=int(input())
s=input()
sm=0
for x in [(x,y,z) for x in range(10) for y in range(10) for z in range(10)]:
    token=0
    for i in range(n):
        if x[token]==int(s[i]):
            token+=1
            if token==3 : break
    if token==3 : sm+=1
print(sm)
Buggy python submission (verdict: Runtime Error):
def main():
    n=int(input())
    lst=list(map(int,input().split()))
    mod=10**9+7
    sm=1
    color=[0,0,0]
    for x in lst:
        sm*=color.count(x)
        sm%=mod
        color[color.index(x)]+=1
    print(sm)

main()

Fixed submission:
def main():
    n=int(input())
    lst=list(map(int,input().split()))
    mod=10**9+7
    sm=1
    color=[0,0,0]
    for x in lst:
        if x not in color : sm=0;break
        sm*=color.count(x)
        sm%=mod
        color[color.index(x)]+=1
    print(sm)

main()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from collections import deque

def main():
    inf=float("inf")
    sm=1
    n=int(input())
    alst=[inf]*n
    work=[inf]*n
    index_list=[inf]*n
    for i in range(n):
        a=int(input())
        alst[i]=a
        j=bisect_left(work,a)
        work[j]=a
        index_list[j]=i
    alst=[x for i,x in enumerate(alst) if not i in index_list]

    while alst:
        sm+=1
        n=len(alst)
        work=[inf]*n
        index_list=[inf]*n
        for i in range(n):
            a=alst[i]
            j=bisect_left(work,a)
            work[j]=a
            index_list[j]=i
        alst=[x for i,x in enumerate(alst) if not i in index_list]
    print(sm)

main()

Fixed submission:
from bisect import bisect_right

def main():
    inf=float("inf")
    n=int(input())
    alst=[int(input()) for _ in range(n)]
    work=[inf]*n
    for i in range(n-1,-1,-1):
        j=bisect_right(work,alst[i])
        work[j]=alst[i]
    print(n-work.count(inf))

main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    n,m,q=map(int,input().split())
    lst=np.zeros((n,n),dtype=int)

    for _ in range(m):
        s,t=map(int,input().split())
        lst[:s,t-1:]+=1
    
    for _ in range(q):
        s,t=map(int,input().split())
        print(lst[s-1][t-1])

main()

Fixed submission:
import numpy as np

def main():
    n,m,q=map(int,input().split())
    lst=np.zeros((n,n),dtype=int)

    for _ in range(m):
        s,t=map(int,input().split())
        lst[s-1][t-1]+=1
    lst=lst.cumsum(axis=1)[::-1].cumsum(axis=0)[::-1]

    for _ in range(q):
        s,t=map(int,input().split())
        print(lst[s-1][t-1])

main()
Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())
n=10**5

work=[1 if i%2==1 else 0 for i in range(n+1)]
primes=[2]
lst=[0]*(n+1)
work[1]==0

for i in range(3,n,2):
    if not work[i]: continue
    primes.append(i)
    index=1
    while i*index<=n:
        work[i*index]=0
        index+=1

for i in primes[1:]:
    if (i+1)//2 in primes:
        lst[i]=1

for _ in range(q):
    left,right=map(int,input().split())
    print(sum(lst[left:right+1]))

Fixed submission:
q=int(input())
n=10**5

work=[1 if i%2==1 else 0 for i in range(n+1)]
primes=[2]
lst=[0]*(n+1)
work[1]==0

for i in range(3,n,2):
    if not work[i]: continue
    primes.append(i)
    index=1
    while i*index<=n:
        work[i*index]=0
        index+=1

for i in primes[1:]:
    if (i+1)//2 in primes:
        lst[i]=1

for i in range(3,n+1):
    lst[i]+=lst[i-1]

for _ in range(q):
    left,right=map(int,input().split())
    print(lst[right]-lst[left-1])

Buggy python submission (verdict: Time Limit Exceeded):
q=int(input())
n=10**5

work=[1 if i%2==1 else 0 for i in range(n+1)]
primes=[2]
lst=[0]*(n+1)
work[1]==0

for i in range(3,n,2):
    if not work[i]: continue
    primes.append(i)
    index=1
    while i*index<=n:
        work[i*index]=0
        index+=1

for i in primes[1:]:
    if (i+1)//2 in primes:
        lst[i]=1

for _ in range(q):
    left,right=map(int,input().split())
    print(sum(lst[left:right+1]))


Fixed submission:
q=int(input())
n=10**5

work=[1 if i%2==1 else 0 for i in range(n+1)]
primes=[2]
lst=[0]*(n+1)
work[1]==0

for i in range(3,n,2):
    if not work[i]: continue
    primes.append(i)
    index=1
    while i*index<=n:
        work[i*index]=0
        index+=1

for i in primes[1:]:
    if (i+1)//2 in primes:
        lst[i]=1

for i in range(3,n+1):
    lst[i]+=lst[i-1]

for _ in range(q):
    left,right=map(int,input().split())
    print(lst[right]-lst[left-1])
Buggy python submission (verdict: Runtime Error):
from itertools import combinations

n,k=map(int,input().split())
lst=list(map(int,input().split()))

work=lst[0]
ini=[x-work for x in lst]
ini_seen=[0]
work=0
for i in range(1,n):
    if ini[i]>work:
        work=ini[i]
        ini_seen.append(i)

mn=None
for x in combinations(range(n-len(ini_seen)),k-len(ini_seen)):
    sm=0
    work=0
    xtoken=0
    count=1
    for i in range(1,n):
        if i in ini_seen:
            count+=1
            if work<ini[i] : work=ini[i]
            else:
                work+=1
                sm+=work-ini[i]
        elif i==x[xtoken]+count:
            work+=1
            sm+=work-ini[i]
            xtoken+=1
            if xtoken==k-len(ini_seen):break



    if not mn : mn=sm
    if mn>sm : mn=sm
print(mn)


Fixed submission:
from itertools import combinations

n,k=map(int,input().split())
lst=list(map(int,input().split()))

work=lst[0]
ini=[x-work for x in lst]
ini_seen=[0]
work=0
for i in range(1,n):
    if ini[i]>work:
        work=ini[i]
        ini_seen.append(i)

mn=None
for x in combinations(range(n-len(ini_seen)),k-len(ini_seen)):
    sm=0
    work=0
    xtoken=0
    count=1
    for i in range(1,n):
        if i in ini_seen:
            count+=1
            if work<ini[i] : work=ini[i]
            else:
                work+=1
                sm+=work-ini[i]
        elif xtoken<len(x) and i==x[xtoken]+count:
            work+=1
            sm+=work-ini[i]
            xtoken+=1
    if not mn : mn=sm
    if mn>sm : mn=sm
print(mn)
Buggy python submission (verdict: Time Limit Exceeded):
def drop(lst,h,w):
    for i in range(w-1,-1,-1):
        work=[lst[j][i] for j in range(h)]
        work=[x for x in work if x]
        for j in range(h-1,-1,-1):
            if work: lst[j][i]=work.pop()
            else : lst[j][i]=None

def chain(lst,h,w,k):
    sm=0
    for j in range(h):
        train=1
        for i in range(w-1):
            if not lst[j][i] :
                train=1
                continue
            if lst[j][i]==lst[j][i+1]:
                train+=1
            else :
                if train>=k:
                    sm+=lst[j][i]*train
                    lst[j][i-train+1:i+1]=[None]*train
                train=1
        if train>=k:
            sm+=lst[j][-1]*train
            lst[j][-train:]=[None]*train
    return sm


def procedure(lst,h,w,k,x):
    lst[x[0]][x[1]]=None
    drop(lst,h,w)
    sm=0
    i=0
    point=chain(lst,h,w,k)
    while point:
        sm+=(2**i)*point
        drop(lst,h,w)
        point=chain(lst,h,w,k)
        i+=1
        #print(lst)
    return sm


def main():
    h,w,k=map(int,input().split())
    lst=[[int(x) for x in input()] for _ in range(h)]
    mx=0

    for i in range(1,h):
        for j in range(w):
            work=[[lst[i][j] for j in range(w)] for i in range(h)]
            sm=procedure(work,h,w,k,(i,j))
            if mx<sm : mx=sm
    print(mx)


main()

Fixed submission:
def drop(lst,h,w):
    for i in range(w-1,-1,-1):
        work=[lst[j][i] for j in range(h)]
        work=[x for x in work if x]
        for j in range(h-1,-1,-1):
            if work: lst[j][i]=work.pop()
            else : lst[j][i]=None

def chain(lst,h,w,k):
    sm=0
    for j in range(h):
        train=1
        for i in range(w-1):
            if not lst[j][i] :
                train=1
                continue
            if lst[j][i]==lst[j][i+1]:
                train+=1
            else :
                if train>=k:
                    sm+=lst[j][i]*train
                    lst[j][i-train+1:i+1]=[None]*train
                train=1
        if train>=k:
            sm+=lst[j][-1]*train
            lst[j][-train:]=[None]*train
    return sm


def procedure(lst,h,w,k,x):
    lst[x[0]][x[1]]=None
    drop(lst,h,w)
    sm=0
    i=0
    point=chain(lst,h,w,k)
    while point:
        sm+=(2**i)*point
        drop(lst,h,w)
        point=chain(lst,h,w,k)
        i+=1
        #print(lst)
    return sm


def main():
    h,w,k=map(int,input().split())
    lst=[[int(x) for x in input()] for _ in range(h)]
    mx=0

    for i in range(1,h):
        for j in range(w):
            work=[[lst[i][j] for j in range(w)] for i in range(h)]
            sm=procedure(work,h,w,k,(i,j))
            if mx<sm : mx=sm
    print(mx)


main()
Buggy python submission (verdict: Time Limit Exceeded):
def manipulate(x, k):
	return abs(x - k)
	

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

while n > k / 2:
	if k == 1:
		n = 0
		break
		
	n = manipulate(n % k, k)
	
print(n)

Fixed submission:
def manipulate(x, k):
	return abs(x - k)

n, k = list(map(int, input().split()))
n = n % k

while n > k / 2:	
	n = manipulate(n, k)
	
print(n)

Buggy python submission (verdict: Time Limit Exceeded):
def manipulate(x, k):
	return abs(x - k)
	

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

while n > k / 2:
	if k == 1:
		n = 0
		break
		
	if k == 0:
		break
		
	n = manipulate(n, k)
	
	
print(n)

Fixed submission:
def manipulate(x, k):
	return abs(x - k)

n, k = list(map(int, input().split()))
n = n % k

while n > k / 2:	
	n = manipulate(n, k)
	
print(n)

Buggy python submission (verdict: Time Limit Exceeded):
def manipulate(x, k):
	return abs(x - k)
	

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

while n > k / 2:
	if k == 1:
		n = 0
		break
		
	n = manipulate(n, k)
	
	
print(n)

Fixed submission:
def manipulate(x, k):
	return abs(x - k)

n, k = list(map(int, input().split()))
n = n % k

while n > k / 2:	
	n = manipulate(n, k)
	
print(n)