示例#1
0
def main():
    ele = int(input())
    l = list(map(int, input().split()))
    d = dd(int)
    for i in l:
        d[i] += 1
    freq = [x for x in d.values()]
    freq.sort()
    res = list(ac(freq))
    for i in range(len(res)):
        if res[i] == ele:
            return len(res) - i - 1
        elif res[i] > ele:
            return len(res) - i
    return 0
示例#2
0
from itertools import accumulate as ac

N, K = map(int, input().split())
lst_a = list(map(int, input().split()))
ans = 0

lst_S = list(ac(lst_a))
for i in range(N - K + 1):
    if i == 0:
        ans += (lst_S[i + K - 1] - 0)
    else:
        ans += (lst_S[i + K - 1] - lst_S[i - 1])
print(ans)
示例#3
0
from itertools import accumulate as ac
n,m=map(int,input().split())
s=[0]*(n+1)
p=[list(map(int,input().split()))for i in range(m)]
for i in range(m):
    s[p[i][0]-1]+=1
    s[p[i][1]]-=1
s=list(ac(s))[:-1]
s=[(1 if i==1 else 0)for i in s]
s=[0]+list(ac(s))
k=[]
for i in range(m):
    if s[p[i][1]]-s[p[i][0]-1]==0:
        k.append(i+1)
print(len(k))
for i in k:
    print(i)
示例#4
0
from bisect import bisect as bs
from itertools import accumulate as ac
rd = lambda: map(int, input().split())
n, q = rd()
A, k = rd(), rd()
a = list(ac(A))
d = 0
for i in range(q):
    d += next(k)
    j = bs(a, d)
    if j == n:
        d = 0
        j = 0
    print(n - j)
示例#5
0
from bisect import bisect_left as bl, bisect_right as br
from itertools import accumulate as ac

n = int(input())
D = sorted([int(input()) for i in range(n)])
m = 10**9 + 7

R = [n - bl(D, 2 * i) for i in D]

R = list(ac(R[::-1]))[::-1]

f = lambda y, x: (y + br(D, x / 2) * R[min(n - 1, bl(D, 2 * x))]) % m
a = list(ac(D, f))
print(a[-1] - a[0])
示例#6
0
    dq = deque(word)
    while len(dq) > 1:
        if dq.popleft() != dq.pop():
            return False
    return True


print(palindrome("ab1ba"))


def another_palindrome(word):
    return word == word[::-1]


print(another_palindrome("radar"))

# itertools module

from itertools import accumulate as ac

multiply = lambda a, b: a * b
for item in ac([1, 2, 3, 4], multiply):
    print(item, end=" ")
print()

# pprint module

import pprint

pp = pprint.PrettyPrinter(1, 30)
pp.pprint(quotes)
from itertools import accumulate as ac
N, M = map(int, input().split())
o = [0] * (N + 2)

for _ in range(M):
    l, r = map(int, input().split())
    o[l] += 1
    o[r + 1] -= 1

print(list(ac(o)).count(M))
示例#8
0
from itertools import accumulate as ac
a,b=map(int,input().split())
d=[0]*(b+1)
k=0
for i in range(a):
    e,f,g=map(int,input().split())
    d[e-1]+=g
    d[f]-=g
    k+=g
p=list(ac(d))[:-1]
print(k-min(p))
    for i in range(1, x + 1):
        if x % i == 0 and i < 27:
            a.append(i)
    return a


for i in range(int(input())):
    s = input()
    l = len(s)
    m = 10**9
    p = [0 for j in range(26)]
    a = fac(l)
    for j in s:
        p[ord(j) - 65] += 1
    p.sort(reverse=True)
    q = list(ac(p))
    for j in a:
        n = l / j
        f = 0
        c = 0
        for k in range(j):
            if (p[0] > n):
                f = 1
                c += max(0, p[k] - n)
            else:
                c += n - p[k]
        if (f == 1):
            c += q[-1] - q[j - 1]
        m = min(c, m)
    print(int(m))
示例#10
0
from itertools import accumulate as ac
from collections import Counter as c
n, m = map(int, input().split())
d = c([i % m for i in [0] + list(ac(list(map(int, input().split()))))])
a = 0
for i in d.values():
    if i > 1:
        a += i * (i - 1) // 2
print(a)
示例#11
0
from itertools import accumulate as ac
r, c, k = map(int, input().split())
d = [[0] * (c + 1) for i in range(r)]
for i in range(r):
    g = input()
    for j in range(c):
        if g[j] == "x":
            for t in range(k):
                if i - k >= 0:
                    d[i - t][max(0, j - k + t + 1)] += 1
                    d[i - t][min(c, j + k - t)] -= 1
                if i + k < r:
                    d[i + t][max(0, j - k + t + 1)] += 1
                    d[i + t][min(c, j + k - t)] -= 1
d = [list(ac(i)) for i in d]
t = 0
for x in range(k - 1, r - k + 1):
    for y in range(k - 1, c - k + 1):
        if d[x][y] == 0:
            t += 1
print(t)
示例#12
0
from itertools import accumulate as ac
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]+list(ac(a))
c=[0]+list(ac([(0 if i<0 else i)for i in a]))
d=0
for i in range(n-k+1):
    d=max(d,max(b[i+k]-b[i],0)+c[i]+c[-1]-c[i+k])
print(d)
示例#13
0
from itertools import accumulate as ac
from math import pi
s = [0] * (2 * (10**4) + 1)
n, q = map(int, input().split())
for i in range(n):
    x, r, h = map(int, input().split())
    for j in range(x, x + h):
        p = x + h - j
        s[j + 1] += pi * (p * ((r * p / h)**2) - (p - 1) *
                          ((r * (p - 1) / h)**2)) / 3
s = list(ac(s))
for i in range(q):
    a, b = map(int, input().split())
    print(s[b] - s[a])
示例#14
0
from itertools import accumulate as ac
from collections import Counter as c
n, m = map(int, input().split())
a = 0
for i in c([i % m
            for i in [0] + list(ac(list(map(int,
                                            input().split()))))]).values():
    a += i * (i - 1) // 2
print(a)
示例#15
0
from itertools import accumulate as ac

N, K = map(int, input().split())
lst_a = list(map(int, input().split()))
lst_imosu = [0] * (N + 1)

for l in range(N - K + 1):
    r = l + K
    lst_imosu[l] += 1
    lst_imosu[r] -= 1
lst_ac = list(ac(lst_imosu))[0:N]

ans = 0
for a, i_ac in zip(lst_a, lst_ac):
    ans += a * i_ac
print(ans)