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

Fixed submission:
n, w = map(int, input().split())
INF = float('inf')
P = []
for _ in range(n):
    iw, iv = map(int, input().split())
    P.append([iw, iv])

dp = [[INF for i in range(10 ** 5 + 1)] for j in range(n + 1)]
dp[0][0] = 0
for i in range(1, n + 1):
    for j in range(10 ** 5 + 1):
        if j - P[i - 1][1] >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - P[i - 1][1]] + P[i - 1][0])
        else:
            dp[i][j] = dp[i - 1][j]

ans = 10 ** 5
while dp[n][ans] > w:
    ans -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
dp=[-1]*(W+1)
dp[0]=0
for _ in range(N):
    w,v=map(int,input().split())
    for i in range(W+1)[::-1]:
        if dp[i]!=-1 and i+w<=W:
            dp[i+w]=max(dp[i+w],dp[i]+v)
print(max(dp))
Problem p03168 (python)

Fixed submission:
n= int(input())
p =[float(x) for x in input().split()]
dp = [[0 for i in range(n+1)]for j in range(n+1)]
dp[0][0]=1.0

for i in range(n):
    for j in range(n):
        dp[i+1][j+1]+=dp[i][j]*p[i]
        dp[i+1][j]+=dp[i][j]*(1-p[i])
an=0
for i in range((n+1)//2,n+1):
    an+=dp[n][i]
print(an)

Buggy submission (verdict: Runtime Error):
n= int(input())
p =[float(x) for x in range(int(input()))]
dp = [[0 for i in range(n+1)]for j in range(n+1)]
dp[0][0]=1.0

for i in range(n):
    for j in range(n):
        dp[i+1][j+1]+=dp[i][j]*p[i]
        dp[i+1][j]+=dp[i][j]*(1-p[i])
an=0
for i in range((n+1)//2,n+1):
    an+=dp[n][i]
print(an)

Buggy submission (verdict: Runtime Error):
n= int(input())
p =[int(x) for x in range(int(input()))]
q= [1-int(x) for x in range(int(input()))]
dp = [[0 for i in range(n+1)]for j in range(n+1)]

dp[0][0]=1
for i in range(n):
    for j in range(n):
        dp[i+1][j+1]+=dp[i][j]*p[i]
        dp[i+1][j]+=dp[i][j]*(1-p[i])
an=0
for i in range((n+1)//2,n+1):
    an+=dp[n][i]
print(an)
Problem p02588 (python)

Fixed submission:
#from collections import deque,defaultdict
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 # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

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

OFS=20
KK = 41
n = inn()
d = [[0]*KK for i in range(KK)]
for i in range(n):
    a = ins()
    p = a.find('.')
    if p<0:
        v = int(a)
        k = 0
    else:
        b = a[:p]+a[p+1:]
        v = int(b)
        k = len(a)-1-p
    x2 = 0
    while v%2==0:
        x2 += 1
        v //= 2
    x2 = min(x2,OFS)
    x5 = 0
    while v%5==0:
        x5 += 1
        v //= 5
    x5 = min(x5,OFS)
    d[x2-k+OFS][x5-k+OFS] += 1

#if DBG:
#    for i in range(KK):
#        for j in range(KK):
#            if d[i][j]!=0:
#                ddprint(f"i {i-OFS} j {j-OFS} {d[i][j]}")

ans = 0
h = {}
for p in range(KK):
    for q in range(KK):
        sm = 0 if p<OFS or q<OFS else (d[p][q]*(d[p][q]-1)//2)
        #if sm>0:
        #ddprint(f"p {p-OFS} q {q-OFS} d {d[p][q]} {sm=}")
        for r in range(-p+2*OFS,KK):
            #if r==p:
            #    continue
            for s in range(-q+2*OFS,KK):
                if (r,s)==(p,q) or (r,s,p,q) in h:
                    continue
                h[(p,q,r,s)] = 1
                sm += d[p][q]*d[r][s]
                #if d[p][q]*d[r][s]>0:
                #    ddprint(f"p {p-OFS} q {q-OFS} r {r-OFS} s {s-OFS} d {d[p][q]} {d[r][s]}")
        ans += sm
print(ans)

Buggy submission (verdict: Runtime Error):
#from collections import deque,defaultdict
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 # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

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

OFS=20
KK = 41
n = inn()
d = [[0]*KK for i in range(KK)]
for i in range(n):
    a = ins()
    p = a.find('.')
    if p<0:
        v = int(a)
        k = 0
    else:
        b = a[:p]+a[p+1:]
        v = int(b)
        k = len(a)-1-p
    x2 = 0
    while v%2==0:
        x2 += 1
        v //= 2
    x5 = 0
    while v%5==0:
        x5 += 1
        v //= 5
    d[x2-k+OFS][x5-k+OFS] += 1

#if DBG:
#    for i in range(KK):
#        for j in range(KK):
#            if d[i][j]!=0:
#                ddprint(f"i {i-OFS} j {j-OFS} {d[i][j]}")

ans = 0
h = {}
for p in range(KK):
    for q in range(KK):
        sm = 0 if p<OFS or q<OFS else (d[p][q]*(d[p][q]-1)//2)
        #if sm>0:
        #ddprint(f"p {p-OFS} q {q-OFS} d {d[p][q]} {sm=}")
        for r in range(-p+2*OFS,KK):
            #if r==p:
            #    continue
            for s in range(-q+2*OFS,KK):
                if (r,s)==(p,q) or (r,s,p,q) in h:
                    continue
                h[(p,q,r,s)] = 1
                sm += d[p][q]*d[r][s]
                #if d[p][q]*d[r][s]>0:
                #    ddprint(f"p {p-OFS} q {q-OFS} r {r-OFS} s {s-OFS} d {d[p][q]} {d[r][s]}")
        ans += sm
print(ans)
Problem p02618 (python)

Fixed submission:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
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 # and False
BIG = 10**18
R = 10**9 + 7

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

from random import randint
import time

def score(t):
    last = [-1]*26
    sm = 0
    for i in range(d):
        tt = t[i]
        sm += s[i][tt]
        last[tt] = i
        for j in range(26):
            sm -= c[j]*(i-last[j])
    return sm

t1 = time.time()
d = inn()
c = inl()
s = []
for i in range(d):
    s.append(inl())
t = []
for i in range(d):
    t.append(randint(0,25))

cnt = 0
mx = -BIG
mxt = []
while True:
    cnt += 1
    if cnt==100:
        t2 = time.time()
        if t2>t1+1.8:
            break
        cnt = 0
    v = score(t)
    if v>mx:
        mx = v
        mxt = t
    dd = randint(0,d-1)
    while True:
        qq = randint(0,25)
        if qq!=t[dd]:
            break
    t[dd] = qq
    #ddprint(f"{i=} {v=} {len(mxt)}")

for i in range(d):
    print(mxt[i]+1)

Buggy submission (verdict: Runtime Error):
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
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 # and False
BIG = 10**18
R = 10**9 + 7

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

from random import randint
import time

def score(t):
    last = [-1]*26
    sm = 0
    for i in range(d):
        tt = t[i]
        sm += s[i][tt]
        last[tt] = i
        for j in range(26):
            sm -= c[j]*(i-last[j])
    return sm

t1 = time.time()
d = inn()
c = inl()
s = []
for i in range(d):
    s.append(inl())
t = []
for i in range(d):
    t.append(randint(0,25))

cnt = 0
mx = 0
mxt = []
while True:
    cnt += 1
    if cnt==100:
        t2 = time.time()
        if t2>t1+1.8:
            break
        cnt = 0
    v = score(t)
    if v>mx:
        mx = v
        mxt = t
    dd = randint(0,d-1)
    while True:
        qq = randint(0,25)
        if qq!=t[dd]:
            break
    t[dd] = qq

for i in range(d):
    print(mxt[i]+1)
Problem p02651 (python)

Fixed submission:
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 # and False
BIG = 10**18

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

def cover0(c,d):
    m = len(c)
    for i in range(m):
        if c[i]==0:
            continue
        k = -1
        for j in range(62):
            b = 1<<j
            if c[i]&b != 0:
                k = j
                break
        for j in range(i+1,m):
            if c[j]&b != 0:
                c[j] ^= c[i]
        for j in range(len(d)):
            if d[j]&b != 0:
                d[j] ^= c[i]
    return sum(d)==0

t = inn()
for tt in range(t):
    n = inn()
    a = inl()
    s = ins()
    top = n
    to0 = []
    to1 = []
    done = False
    while top>0:
        prev0 = top
        while top>0 and s[top-1]=='0':
            top -= 1
        top0 = top
        to0.extend(a[top0:prev0])
        prev1 = top
        while top>0 and s[top-1]=='1':
            top -= 1
        top1 = top
        to1.extend(a[top1:prev1])
        cc = [x for x in to0]
        dd = [x for x in to1]
        if not cover0(cc,dd):
            print(1)
            done = True
            break
    if not done:
        print(0)

Buggy submission (verdict: Runtime Error):
#from collections import deque,defaultdict
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 # and False
BIG = 10**18
R = 10**9 + 7

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

def cover0(c,d):
    m = len(c)
    for i in range(m):
        if c[i]==0:
            continue
        k = -1
        for j in range(62):
            b = 1<<j
            if c[i]&b != 0:
                k = j
                break
        for j in range(i+1,m):
            if c[j]&b != 0:
                c[j] ^= c[k]
        for j in range(len(d)):
            if d[j]&b != 0:
                d[j] ^= c[k]
    return sum(d)==0

t = inn()
for tt in range(t):
    n = inn()
    a = inl()
    s = ins()
    top = n
    to0 = []
    to1 = []
    done = False
    while top>0:
        prev0 = top
        while top>0 and s[top-1]=='0':
            top -= 1
        top0 = top
        to0.extend(a[top0:prev0])
        prev1 = top
        while top>0 and s[top-1]=='1':
            top -= 1
        top1 = top
        to1.extend(a[top1:prev1])
        cc = [x for x in to0]
        dd = [x for x in to1]
        if not cover0(cc,dd):
            print(1)
            done = True
            break
    if not done:
        print(0)
Problem p02662 (python)

Fixed submission:
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
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 # and False
BIG = 10**18
R = 998244353

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

hf = pow(2,R-2,R)
n,s = inm()
a = inl()
dp = [[0]*(s+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = pow(2,n,R)
sm = 0
for i in range(1,n+1):
    dp[i] = [x for x in dp[i-1]]
    for j in range(s):
        if dp[i-1][j]>0 and j+a[i-1]<=s:
            dp[i][j+a[i-1]] = (dp[i][j+a[i-1]]+dp[i-1][j]*hf)%R
    #ddprint(i)
    #ddprint(dp[i])
print(dp[n][s])

Buggy submission (verdict: Runtime Error):
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
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 # and False
BIG = 10**18
R = 998244353

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

n,s = inm()
a = inl()
dp = [[0]*(s+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
sm = 0
for i in range(1,n+1):
    for j in range(s):
        if dp[i-1][j]>0 and j+a[i-1]<=s:
            dp[i][j+a[i-1]] += dp[i-1][j]
            if j+a[i-1]==s:
                sm = (sm+dp[i-1][j]*pow(2,n-i+1,R))%R
    ddprint(dp)
print(sm)
Problem p02698 (python)

Fixed submission:
#from collections import deque,defaultdict
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 # and False
BIG = 10**12
R = 10**9 + 7
#R = 998244353

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

#import sys,resource,bisect
import resource
from sys import setrecursionlimit
from resource import getrlimit,setrlimit
from bisect import bisect_left
def setrlim():
  setrecursionlimit(250000)
  soft,hard = getrlimit(resource.RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  setrlimit(resource.RLIMIT_STACK, (128*1024*1024,hard))

def dfs(u,j,dp):
    #ddprint(f"dfs {u=} {j=}")
    ans[u] = j
    for v in dst[u]:
        if ans[v]>=0:
            continue
        x = bisect_left(dp,a[v])
        tmp = dp[x]
        dp[x] = a[v]
        #ddprint(f"dfs {u=} {j=} {x=} {tmp=} av {a[v]} {dp=}")
        dfs(v,j+(1 if tmp==BIG else 0),dp)
        dp[x] = tmp

setrlim()
n = inn()
a = inl()
a[0:0] = [0]
dst = [{} for i in range(n+1)]
for i in range(n-1):
    u,v = inm()
    dst[u][v] = dst[v][u] = 1
ans = [-1]*(n+1)
dp = [BIG]*(n+1)
dp[0] = a[1]
dfs(1,1,dp)
for i in range(1,n+1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
#from collections import deque,defaultdict
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 # and False
BIG = 10**12
R = 10**9 + 7
#R = 998244353

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

#import sys,resource,bisect
from sys import setrecursionlimit
from resource import getrlimit,setrlimit
from bisect import bisect_left
def setrlim():
  setrecursionlimit(250000)
  soft,hard = getrlimit(resource.RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  setrlimit(resource.RLIMIT_STACK, (128*1024*1024,hard))

def dfs(u,j,dp):
    #ddprint(f"dfs {u=} {j=}")
    ans[u] = j
    for v in dst[u]:
        if ans[v]>=0:
            continue
        x = bisect_left(dp,a[v])
        tmp = dp[x]
        dp[x] = a[v]
        #ddprint(f"dfs {u=} {j=} {x=} {tmp=} av {a[v]} {dp=}")
        dfs(v,j+(1 if tmp==BIG else 0),dp)
        dp[x] = tmp

setrlim()
n = inn()
a = inl()
a[0:0] = [0]
dst = [{} for i in range(n+1)]
for i in range(n-1):
    u,v = inm()
    dst[u][v] = dst[v][u] = 1
ans = [-1]*(n+1)
dp = [BIG]*(n+1)
dp[0] = a[1]
dfs(1,1,dp)
for i in range(1,n+1):
    print(ans[i])
Problem p02796 (python)

Fixed submission:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

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

n = inn()
xl = []
for i in range(n):
    xx,ll = inm()
    xl.append((xx+ll,xx-ll))
xl.sort()

ddprint(xl)

cnt = 1
i = 0
while i<n-1:
    nxtj = -1
    for j in range(i+1,n):
        if xl[i][0]<=xl[j][1]:
            #ddprint("j {} found".format(j))
            cnt += 1
            nxtj = j
            break
    i = nxtj if nxtj>0 else n
    #ddprint("i {} j {} nxtj {}".format(i,j,nxtj))

print(cnt)

Buggy submission (verdict: Runtime Error):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

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

n = inn()
xl = []
for i in range(n):
    xx,ll = inm()
    xl.append((xx+ll,xx-ll))
xl.sort()

ddprint(xl)

cnt = 1
i = 0
while i<n:
    nxtj = -1
    for j in range(i+1,n):
        if xl[i][0]<=xl[j][1]:
            ddprint("j {} found".format(j))
            cnt += 1
            nxtj = j
            break
    i = nxtj if nxtj>0 else n
    ddprint("i {} j {} nxtj {}".format(i,j,nxtj))

print(cnt)
Problem p02937 (python)

Fixed submission:
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  and False
BIG = 10**18
R = 10**9 + 7

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

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
nx = [-1]*26
for i in range(2*ls-1,-1,-1):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if i<ls and nx[j]>=0:
            nxt[i][j] = nx[j]-i
    nx[c] = i
if DBG:
    for i in range(ls):
        #printn(f"{i} ")
        print(nxt[i])

prevpos = nxt[ls-1][ord(t[0])-oa]-1
if prevpos<0:
    print(-1)
    exit()
for i in range(1,len(t)):
    c = ord(t[i])-oa
    nx = nxt[prevpos%ls][c]
    if nx<0:
        print(-1)
        exit()
    prevpos += nx
    #ddprint(f"i {i} pp {prevpos} c {c} ti {t[i]}")
print(prevpos+1)

Buggy submission (verdict: Runtime Error):
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  and False
BIG = 10**18
R = 10**9 + 7

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

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
nx = [-1]*26
for i in range(2*ls-1,-1,-1):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if i<ls and nx[j]>=0:
            nxt[i][j] = nx[j]-i
    nx[c] = i
if DBG:
    for i in range(ls):
        printn(f"{i} ")
        print(nxt[i])
cur = 0
for i in range(len(t)):
    c = ord(t[i])-oa
    nx = nxt[cur%ls][c]
    if nx<0:
        print(-1)
        exit()
    cur += nx
print(cur+1)
Problem p03006 (python)

Fixed submission:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
if n==1:
    print(1)
    exit()
    
a = []
for i in range(n):
    x,y = inm()
    a.append((x,y))

h = defaultdict(int)
for i in range(n-1):
    z = a[i]
    for j in range(i+1,n):
        u = a[j]
        p = z[0]-u[0]
        q = z[1]-u[1]
        if p<0:
            p = -p
            q = -q
        elif p==0 and q<0:
            q = -q
        h[(p,q)] += 1

ddprint(h)
mx = max(h.values())
print(n-mx)

Buggy submission (verdict: Runtime Error):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = []
for i in range(n):
    x,y = inm()
    a.append((x,y))

h = defaultdict(int)
for i in range(n-1):
    z = a[i]
    for j in range(i+1,n):
        u = a[j]
        p = z[0]-u[0]
        q = z[1]-u[1]
        if p<0:
            p = -p
            q = -q
        elif p==0 and q<0:
            q = -q
        h[(p,q)] += 1

ddprint(h)
mx = max(h.values())
print(n-mx)
Problem p03040 (python)

Fixed submission:
import heapq
#printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
#inm   = lambda:      map(int, input().split())
DBG = True  and False
#def ddprint(x):
#  if DBG:
#    print(x)

q = inn()
x = inl()
root = x[1]
b = x[2]
tl = []
tr = []
nl = nr = suml = sumr = 0
#ddprint("q " + str(q))
for i in range(1,q):
    #ddprint("i " + str(i))
    x = inl()
    if len(x)==1:
        z = sumr - suml - (root if nr>nl else 0) + b
        print("{} {}".format(root,z))
    else:
        a = x[1]
        b += x[2]
        if nl == nr:
            aa = -heapq.heappushpop(tl,-a)
            suml += a - aa
            if aa<root:
                aa,root = root,aa
            heapq.heappush(tr,aa)
            sumr += aa
            nr += 1
        else:
            aa = heapq.heappushpop(tr,a)
            sumr += a - aa
            if aa>root:
                aa,root = root,aa
            heapq.heappush(tl,-aa)
            suml += aa
            nl += 1
        #ddprint("b {} root {} nl {} nr {} suml {} sumr {}".format(b,root,nl,nr,suml,sumr))
        #ddprint(tl)
        #ddprint(tr)

Buggy submission (verdict: Runtime Error):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

def foo(x):
    sum = 0
    for y in a:
        sum += abs(y-x)
    return sum+b

a = []
b = 0
q = inn()
for i in range(q):
    x = inl()
    if len(x)==1:
        z = (len(a)-1)//2
        print("{} {}".format(a[z],foo(a[z])))
    else:
        z = x[1]
        if a[-1] <= z:
            a.append(z)
        elif z <= a[0]:
            a.insert(0,z)
        else:
            up = len(a)-1
            lo = 0
            while lo+1 < up:
                mid = (lo+up)//2
                if z < a[mid]:
                    up = mid
                else:
                    lo = mid
            a.insert(up,z)
            b += x[2]
Problem p03050 (python)

Fixed submission:
import math
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
q = int(math.sqrt(n))+1
sum = 0
for i in range(1,q):
    ddprint("i {}".format(i))
    if n%i==0:
        m = n//i - 1
        ddprint("divides m {}".format(m))
        if m==0:
            continue
        if n%m == n//m:
            sum += m
print(sum)

Buggy submission (verdict: Runtime Error):
import math
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
q = int(math.sqrt(n))+1
sum = 0
for i in range(1,q):
    ddprint("i {}".format(i))
    if n%i==0:
        m = n//i - 1
        ddprint("divides m {}".format(m))
        if n%m == n//m:
            sum += m
print(sum)
Problem p03128 (python)

Fixed submission:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

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

DEPMAX = 5

def foo(n,dep):
    if dep>DEPMAX or n<0:
        ret = "-1"
    elif n==0:
        ret = ""
    elif n%mn==0:
        ret = str(mni)*(n//mn)
    else:
        mxs = "-1"
        for x in a:
            v = foo(n-cs[x],dep+1)
            if v=="-1":
                continue
            vv = v+str(x)
            if int(vv)>int(mxs):
                mxs = vv
            vv = str(x)+v
            if int(vv)>int(mxs):
                mxs = vv
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret

n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
mn = min([cs[x] for x in a])
for i in range(m-1,-1,-1):
    if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
#k = (n)//mn
#ddprint(f"mn {mn} mni {mni}")
#ddprint(a)
print(foo(n,0))

Buggy submission (verdict: Runtime Error):
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

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

BAD = "z"*10001
def foo(n,k):
    if n<mn*k:
        ret = ""
    elif n==mn*k:
        ret = str(mni)*k
    elif k==1:
        ret = ""
        for i in range(m-1,-1,-1):
            if cs[a[i]]==n:
                ret = str(a[i])
                break
    else:
        mxs = ""
        for x in a:
            v = foo(n-cs[x],k-1)
            if v=="":
                continue
            if x<mn:
                vv = v+str(x)
            else:
                vv = str(x)+v
            mxs = max(mxs,vv)
        ret = mxs
    #ddprint(f"foo n {n} k {k} ret {ret}")
    return ret

n,m = inm()
a = inl()
a.sort()
cs = [0,2,5,5,4,5,6,3,7,6]
mn = min([cs[x] for x in a])
for i in range(m-1,-1,-1):
    if cs[a[i]]==mn:
        mni = a[i]
        break
#k = (n+mn-1)//mn
k = (n)//mn
#ddprint(f"mn {mn} mni {mni} k {k}")
#ddprint(a)
print(foo(n,k))