You can't start with 0, so you can subtract that much.
C = input()
print(len(C) - 1 - C.count('0'))
First of all, if Behomalar consumes less MP, all Behomalar is fine. Also, if Behomaler consumes more MP than Behomaler N times, all Behomaler is fine. The problem is in the middle, for example, Behomaler. If the memory consumption of is twice that of Behomalar, the person other than the one with the highest HP will be recovered with Behomalar, and when it is finished, the remaining one will be recovered with Behomalar. It is the same whether it is 1.1 times or 1.9 times. If it is 2.1 times, it will recover with Behomalar except for those who have the first and second highest HP, and when it is over, the remaining two people who have not finished recovering will be recovered with Behoimi. Behomaler's memory consumption is ceil, which is the magnification of Behoimi. Note that the initial HP is 1.
from math import ceil
N, K, X, Y = map(int, input().split())
A = list(map(int, input().split()))
B = [((a - 1) + K - 1) // K for a in A]
B.sort(reverse=True)
if Y <= X:
print(Y * B[0])
exit()
t = ceil(Y / X) - 1
if t < N:
print(Y * B[t] + X * sum(B[i] - B[t] for i in range(t)))
else:
print(X * sum(B[i] for i in range(N)))
Count each number of A and add up the product of each number of A and A xor X. When A or X, it becomes a pair with A and becomes a double count, so the last 2 You can divide by. However, it is special only when X = 0, and it will be combined with itself with A xor 0 = A, so only in that case number of A </ sub> C 2 </ strong> Sub> is summed.
N, X = map(int, input().split())
A = [int(input()) for _ in range(N)]
d = {}
for a in A:
d.setdefault(a, 0)
d[a] += 1
result = 0
if X == 0:
for v in d.values():
result += v * (v - 1) // 2
print(result)
else:
for k in d:
if k ^ X in d:
result += d[k] * d[k ^ X]
print(result // 2)
Lost. I can write that it is naive. N ≤ 10 18 </ sup> is impossible, isn't it?
Recommended Posts