Harryxun/testdata huggingface dataset:
Buggy python 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)


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 python 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)


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 python submission (verdict: Time Limit Exceeded):
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)

h,w = inm()
a = []
for i in range(h):
    a.append(list(ins()))
q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append((i,j))
cnt = 0
#ddprint(a)
#ddprint(q)
while len(q)>0:
    qq = []
    while len(q)>0:
        i,j = q.pop()
        for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]:
            x = i+dx
            y = j+dy
            if 0<=x<h and 0<=y<w and a[x][y]=='.':
                a[x][y] = '#'
                qq.append((x,y))
    q = qq
    if len(q)>0:
        cnt += 1
    #ddprint(a)
    #ddprint(q)
print(cnt)


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)

h,w = inm()
a = []
for i in range(h):
    a.append(list(ins()))
q = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            q.append((i,j))
cnt = 0
#ddprint(a)
#ddprint(q)
while len(q)>0:
    qq = []
    while len(q)>0:
        i,j = q.pop()
        for dx,dy in [(0,1),(0,-1),(1,0),(-1,0)]:
            x = i+dx
            y = j+dy
            if 0<=x<h and 0<=y<w and a[x][y]=='.':
                a[x][y] = '#'
                qq.append((x,y))
    q = qq
    if len(q)>0:
        cnt += 1
    #ddprint(a)
    #ddprint(q)
print(cnt)
Buggy python submission (verdict: Runtime Error):
from collections import deque
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)

n = inn()
dst = [{} for i in range(n+1)]
for i in range(n-1):
    u,v = inm()
    dst[u][v] = dst[v][u] = 1
s = 1
d1 = [-1]*(n+1)
d1[s] = 0
q = deque([s])
while len(q)>0:
    x = q.popleft()
    d = d1[x]
    for u in dst[x]:
        if d1[u]<0:
            d1[u] = d+1
            q.append(u)
mx = 0
for i in range(1,n+1):
    if d1[i]>mx:
        mx = d1[i]
        mxi = i

s = mxi
d1 = [-1]*(n+1)
d1[s] = 0
q = deque([s])
while len(q)>0:
    x = q.popleft()
    d = d1[x]
    for u in dst[x]:
        if d1[u]<0:
            d1[u] = d+1
            q.append(u)
if max(d1)%3==1:
    print('Second')
else:
    print('First')


Fixed submission:
from collections import deque
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)

n = inn()
if n==1:
    print('First')
    exit()
dst = [{} for i in range(n+1)]
for i in range(n-1):
    u,v = inm()
    dst[u][v] = dst[v][u] = 1
s = 1
d1 = [-1]*(n+1)
d1[s] = 0
q = deque([s])
while len(q)>0:
    x = q.popleft()
    d = d1[x]
    for u in dst[x]:
        if d1[u]<0:
            d1[u] = d+1
            q.append(u)
mx = 0
for i in range(1,n+1):
    if d1[i]>mx:
        mx = d1[i]
        mxi = i

s = mxi
d1 = [-1]*(n+1)
d1[s] = 0
q = deque([s])
while len(q)>0:
    x = q.popleft()
    d = d1[x]
    for u in dst[x]:
        if d1[u]<0:
            d1[u] = d+1
            q.append(u)
if max(d1)%3==1:
    print('Second')
else:
    print('First')
Buggy python submission (verdict: Time Limit Exceeded):
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 = 999999999999
R = 10**9 + 7
import bisect

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

a,b,q = inm()
s = []
t = []
for i in range(a):
    s.append(inn())
for i in range(b):
    t.append(inn())
for qq in range(q):
    x = inn()
    mn = BIG

    i = bisect.bisect_left(s,x)
    ss = [0] if i==0 else [a-1] if i==a else [i-1,i]
    for y in ss:
        d = abs(s[y]-x)
        j = bisect.bisect_left(t,s[y])
        tt = [0] if j==0 else [b-1] if j==b else [j-1,j]
        for z in tt:
            mn = min(mn, d+abs(s[y]-t[z]))

    i = bisect.bisect_left(t,x)
    tt = [0] if i==0 else [b-1] if i==b else [i-1,i]
    for y in tt:
        d = abs(t[y]-x)
        j = bisect.bisect_left(s,t[y])
        ss = [0] if j==0 else [a-1] if j==a else [j-1,j]
        for z in ss:
            mn = min(mn, d+abs(t[y]-s[z]))

    print(mn)


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 = 999999999999
R = 10**9 + 7
import bisect

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

a,b,q = inm()
s = []
t = []
for i in range(a):
    s.append(inn())
for i in range(b):
    t.append(inn())
for qq in range(q):
    x = inn()
    mn = BIG

    i = bisect.bisect_left(s,x)
    j = bisect.bisect_left(t,x)
    #ddprint("i {} j {}".format(i,j))
    if i>0 and j>0:
        mn = min(mn, x-min(s[i-1],t[j-1]))
    if i>0 and j<b:
        mn = min(mn, min(x-s[i-1],t[j]-x)+t[j]-s[i-1])
    if i<a and j>0:
        mn = min(mn, min(x-t[j-1],s[i]-x)+s[i]-t[j-1])
    if i<a and j<b:
        mn = min(mn, max(s[i],t[j])-x)
    print(mn)
Buggy python submission (verdict: Time Limit Exceeded):
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)

from collections import deque
n,m = inm()
chi = [{} for i in range(n+1)]
par = [{} for i in range(n+1)]
for i in range(n-1+m):
    a,b = inm()
    chi[a][b] = 1
    par[b][a] = 1
dep = [0]*(n+1)
rpar = [0]*(n+1)
for i in range(1,n+1):
    if len(par[i])==0:
        root = i
        break
ddprint("chi")
ddprint(chi)
ddprint("par")
ddprint(par)
ddprint(root)
q = deque([root])
while len(q)>0:
    p = q.popleft()
    d = dep[p]
    for z in chi[p]:
        if dep[z]<d+1:
            dep[z] = d+1
            rpar[z] = p
            q.append(z)
for i in range(1,n+1):
    print(rpar[i])


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)

from collections import deque
n,m = inm()
chi = [{} for i in range(n+1)]
par = [{} for i in range(n+1)]
for i in range(n-1+m):
    a,b = inm()
    chi[a][b] = 1
    par[b][a] = 1
dep = [0]*(n+1)
rpar = [0]*(n+1)
for i in range(1,n+1):
    if len(par[i])==0:
        root = i
        break
ddprint("chi")
ddprint(chi)
ddprint("par")
ddprint(par)
ddprint(root)
q = deque([root])
while len(q)>0:
    p = q.popleft()
    d = dep[p]
    for z in chi[p]:
        del par[z][p]
        #if dep[z]<d+1 and len(par[z])==0:
        if len(par[z])==0:
            dep[z] = d+1
            rpar[z] = p
            q.append(z)
for i in range(1,n+1):
    print(rpar[i])
Buggy python submission (verdict: Time Limit Exceeded):
#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)

n,k = inm()
dt = []
for i in range(n):
    t,d = inm()
    dt.append((d,t))
dt.sort(reverse=True)
a = dt[:k] # oisisa max, ignore variety

vals = [z[0] for z in a]
dsum = sum(vals)
typs = set([z[1] for z in a])
ntyp = len(typs)
mx = dsum+ntyp**2 # satisfy for a

b = dt[k:]
h = {}
for d,t in b:
    if t in typs:
        continue
    elif t not in h:
        h[t] = d
    else:
        h[t] = max(h[t],d)
c = [h[t] for t in h]
c.sort(reverse=True)
# for types not in a, max oisisa

h = {}
for d,t in a:
    if t not in h:
        h[t] = d
    else:
        h[t] = max(h[t],d)
for t in h:
    vals.remove(h[t])
vals.sort()
# oisisa list for second or below for each type

for i in range(min(len(vals),len(c))):
    dsum += c[i]-vals[i]
    ntyp += 1
    mx = max(mx,dsum+ntyp**2)
print(mx)


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

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

n,k = inm()
dt = []
for i in range(n):
    t,d = inm()
    dt.append((d,t))
dt.sort(reverse=True)
a = dt[:k] # oisisa max, ignore variety

vals = [z[0] for z in a]
dsum = sum(vals)
typs = set([z[1] for z in a])
ntyp = len(typs)
mx = dsum+ntyp**2 # satisfy for a

b = dt[k:]
h = {}
for d,t in b:
    if t in typs:
        continue
    elif t not in h:
        h[t] = d
    else:
        h[t] = max(h[t],d)
c = [h[t] for t in h]
c.sort(reverse=True)
# for types not in a, max oisisa

h = {}
for d,t in a:
    if t not in h:
        h[t] = d
    else:
        h[t] = max(h[t],d)
vals = []
for d,t in a:
    if t in h and d==h[t]:
        del h[t]
    else:
        vals.append(d)
vals.sort()
# oisisa list for second or below for each type

for i in range(min(len(vals),len(c))):
    dsum += c[i]-vals[i]
    ntyp += 1
    mx = max(mx,dsum+ntyp**2)
print(mx)
Buggy python 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)

import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def prime_division2(x):
    q = int(math.sqrt(x))
    h = {}
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            h[i] = ex
    if x>q:
        h[x] = 1
    return h

def divisorlist(z): # z : output of prime_division
    if len(z)==1:
        return [z[0][0]**i for i in range(z[0][1]+1)]
    y = divisorlist(z[1:])
    s = []
    for i in range(z[0][1]+1):
        for j in y:
            s.append((z[0][0]**i)*j)
    return s

n,m = inm()
ps = divisorlist(prime_division(m))
ps2 = [x for x in ps if x<=m//n]
print(max(ps2))


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

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

import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def prime_division2(x):
    q = int(math.sqrt(x))
    h = {}
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            h[i] = ex
    if x>q:
        h[x] = 1
    return h

def divisorlist(z): # z : output of prime_division
    if len(z)==1:
        return [z[0][0]**i for i in range(z[0][1]+1)]
    y = divisorlist(z[1:])
    s = []
    for i in range(z[0][1]+1):
        for j in y:
            s.append((z[0][0]**i)*j)
    return s

n,m = inm()
if m==1:
    print(1)
    exit()
#ls = prime_division(m)
#ddprint(ls)
ps = divisorlist(prime_division(m))
#ddprint(ps)
ps2 = [x for x in ps if x<=m//n]
print(max(ps2))
Buggy python 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)

import itertools
n = inn()
a = inl()
if n>300:
    3/0
cms = itertools.combinations(list(range(1,n)),3)
ans = BIG
for cm in cms:
    v = []
    v.append(sum(a[:cm[0]]))
    v.append(sum(a[cm[0]:cm[1]]))
    v.append(sum(a[cm[1]:cm[2]]))
    v.append(sum(a[cm[2]:]))
    ans = min(ans,max(v)-min(v))
print(ans)


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)

import bisect
n = inn()
a = inl()
lacc = [0]*(n+1)
for i in range(n):
    lacc[i+1] = lacc[i]+a[i]
ans = BIG
for i in range(2,n-1):
    j = bisect.bisect_left(lacc,lacc[i]//2+1)
    j = min(j,i-1)
    k = bisect.bisect_left(lacc,(lacc[n]+lacc[i])//2+1)
    k = min(k,n-1)
    for dj in range(2):
        jj = j-dj
        if jj<=0:
            continue
        for dk in range(2):
            kk = k-dk
            if kk<=i:
                continue
            v = []
            v.append(lacc[jj])
            v.append(lacc[i]-lacc[jj])
            v.append(lacc[kk]-lacc[i])
            v.append(lacc[n]-lacc[kk])
            ans = min(ans,max(v)-min(v))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#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 = 998244353

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

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R


n,a,b,k = inm()
sm = 0
factinit(n,R)
for pq in range(n+1):
    if (k-a*pq)%b>0:
        continue
    qr = (k-a*pq)//b
    if qr>n:
        continue
    q1 = max(0,pq+qr-n)
    q2 = min(pq,qr)
    for q in range(q1,q2+1):
        p = pq-q
        r = qr-q
        s = n-p-q-r
        sor = ((fact[p]*fact[q]%R)*(fact[r]*fact[s]%R))%R
        sm = (sm+fact[n]*modinv2(sor,R))%R
print(sm)


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 = 998244353

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

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R


n,a,b,k = inm()
sm = 0
factinit(n,R)
for pq in range(n+1):
    if k<a*pq or (k-a*pq)%b>0:
        continue
    qr = (k-a*pq)//b
    if qr>n:
        continue
    sm = (sm+comb(n,pq,R)*comb(n,qr,R))%R
print(sm)
Buggy python submission (verdict: Time Limit Exceeded):
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())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

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

n = inn()
aa = inl()
a = []
for i in range(n):
    x = []
    for j in range(20):
        x.append((aa[i]>>j)&1)
    a.append(x)
if DBG:
    for i,z in enumerate(a):
        printn(aa[i])
        printn(' ')
        printn(i)
        print(z)
    print("- a -")
cnt = n
c = [a[0][j] for j in range(20)]
s = 1
for i in range(1,n):
    ok = True
    for j in range(20):
        if c[j]==1 and a[i][j]==1:
            ok = False
            break
    ddprint("i {} ok {} c {} s {} cnt {}".format(i,ok,c,s,cnt))
    if ok:
        cnt += s
        s += 1
        for j in range(20):
            c[j] += a[i][j]
    else:
        for j in range(20):
            c[j] += a[i][j]
        #cnt += s*(s-1)//2
        s += 1
        ddprint("mid s {} c {}".format(s,c))
        while s>1:
            if max(c)<=1:
                break
            for j in range(20):
                c[j] -= a[i-s+1][j]
            s -= 1
            ddprint("mid2 s {} c {}".format(s,c))
        cnt += s-1
print(cnt)


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())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

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

n = inn()
aa = inl()
a = []
for i in range(n):
    x = []
    for j in range(20):
        x.append((aa[i]>>j)&1)
    a.append(x)
if DBG:
    for i,z in enumerate(a):
        printn(aa[i])
        printn(' ')
        printn(i)
        print(z)
    print("- a -")
cnt = n
c = [a[0][j] for j in range(20)]
s = 1
for i in range(1,n):
    ok = True
    for j in range(20):
        if c[j]==1 and a[i][j]==1:
            ok = False
            break
    #ddprint("i {} ok {} c {} s {} cnt {}".format(i,ok,c,s,cnt))
    if ok:
        cnt += s
        s += 1
        for j in range(20):
            c[j] += a[i][j]
    else:
        for j in range(20):
            c[j] += a[i][j]
        #cnt += s*(s-1)//2
        s += 1
        #ddprint("mid s {} c {}".format(s,c))
        while s>1:
            if max(c)<=1:
                break
            for j in range(20):
                c[j] -= a[i-s+1][j]
            s -= 1
            #ddprint("mid2 s {} c {}".format(s,c))
        cnt += s-1
print(cnt)
Buggy python 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)

n = inn()
a = []
b = []
xb = 10**9+1
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
    if aa>bb and xb>bb:
        xb = bb
        xi = i
if n==2 and a[0]==1:
    3/0
print(0 if xb>10**9 else sum(a)-b[xi])


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)

n = inn()
a = []
b = []
xb = 10**9+1
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
    if aa>bb and xb>bb:
        xb = bb
        xi = i
if n==-2 and a[0]==1:
    3/0
print(0 if xb>10**9 else sum(a)-b[xi])
Buggy python submission (verdict: Time Limit Exceeded):
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 foo(i):
    print(i,flush=True)
    s = ins()
    a[i] = h[s]
    if h[s]==1:
        exit()

h = {'Vacant':1, 'Male':2, 'Female':3}
n = inn()
a = [0]*(n+1)
foo(0)
a[n] = a[0]
p = 0
q = n
while True:
    r = (p+q)//2
    foo(r)
    if a[r]==a[p] and (r-p)%2==1 or a[r]!=a[p] and (r-p)%2==0:
        q = r
    else:
        p = r
        #ddprint(a)
    #ddprint(f"p {p} q {q}")


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)

def foo(i):
    print(i,flush=True)
    s = ins()
    a[i] = h[s]
    if h[s]==1:
        exit()

h = {'Vacant':1, 'Male':2, 'Female':3}
n = inn()
a = [0]*(n+1)
foo(0)
a[n] = a[0]
p = 0
q = n
cnt = 1
while q>p+1:
    r = (p+q)//2
    foo(r)
    cnt += 1
    if cnt >= 20:
        exit()
    if a[r]==a[p] and (r-p)%2==1 or a[r]!=a[p] and (r-p)%2==0:
        q = r
    else:
        p = r
        #ddprint(a)
    #ddprint(f"p {p} q {q}")
print("err")