description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = int(input())
b = int(input())
c = int(input())
d = int(input())
A = a ^ b
B = c | d
C = b & c
D = a ^ d
print(A & B ^ (C | D)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | def main():
(a,) = read()
(b,) = read()
(c,) = read()
(d,) = read()
n = 8 * a + 4 * b + 2 * c + d
dc = {
(0): 0,
(1): 1,
(2): 0,
(3): 1,
(4): 0,
(5): 0,
(6): 0,
(7): 0,
(8): 1,
(9): 1,
(10): 0,
(11): 1,
(12): 1,
(13): 0,
(14): 1,
(15): 1,
}
print(dc[n])
def read(callback=int):
return list(map(callback, input().strip().split()))
def write(value, end="\n"):
if value is None:
return
try:
if not isinstance(value, str):
value = " ".join(map(str, value))
except:
pass
print(value, end=end)
write(main()) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING IF VAR NONE RETURN IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | def myor(a, b):
return a | b
def myxor(a, b):
return a ^ b
def myand(a, b):
return a & b
op1 = myxor
op2 = myor
op3 = myand
l = [int(input()) for _ in range(4)]
print(op1(op3(op1(l[0], l[1]), op2(l[2], l[3])), op2(op3(l[1], l[2]), op1(l[0], l[3])))) | FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | def mp():
return map(int, input().split())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
print((a ^ b) & (c | d) ^ (b & c | a ^ d)) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = []
for i in range(4):
a.append(int(input()))
b = ""
for i in a:
b += str(i)
num = int(b, 2)
ans = [(0) for x in range(16)]
ans[0] = 0
ans[1] = 1
ans[2] = 0
ans[3] = 1
ans[4] = 0
ans[5] = 0
ans[6] = 0
ans[7] = 0
ans[8] = 1
ans[9] = 1
ans[10] = 0
ans[11] = 1
ans[12] = 1
ans[13] = 0
ans[14] = 1
ans[15] = 1
print(ans[num]) | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = int(input())
b = int(input())
c = int(input())
d = int(input())
s = a * 1000 + b * 100 + c * 10 + d
if s == 0:
print(0)
elif s == 1:
print(1)
elif s == 10:
print(0)
elif s == 11:
print(1)
elif s == 100:
print(0)
elif s == 101:
print(0)
elif s == 110:
print(0)
elif s == 111:
print(0)
elif s == 1000:
print(1)
elif s == 1001:
print(1)
elif s == 1010:
print(0)
elif s == 1011:
print(1)
elif s == 1100:
print(1)
elif s == 1101:
print(0)
elif s == 1110:
print(1)
elif s == 1111:
print(1)
else:
print(0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | def op1(u, v):
return u ^ v
def op2(u, v):
return u | v
def op3(u, v):
return u & v
a = [int(input()) for _ in range(4)]
b = op1(a[0], a[1])
c = op2(a[2], a[3])
d = op3(a[1], a[2])
e = op1(a[0], a[3])
f = op3(b, c)
g = op2(d, e)
h = op1(f, g)
print(h) | FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | def OR(a, b):
return a ^ b
def XOR(a, b):
return a | b
def AND(a, b):
return a & b
def g(a, b, c, d):
e = OR(a, b)
f = XOR(c, d)
g = AND(b, c)
h = OR(a, d)
i = AND(e, f)
j = XOR(g, h)
return OR(i, j)
a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(g(a, b, c, d)) | FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = tuple(int(input()) for _ in range(4))
print(int((a[0] != a[1] and (a[2] or a[3])) != (a[1] and a[2] or a[0] != a[3]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = int(input())
b = int(input())
c = int(input())
d = int(input())
a = int(a)
b = int(b)
c = int(c)
d = int(d)
n = (a ^ b) & (c | d) ^ (b & c | a ^ d)
print(n) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = int(input()) == 1
b = int(input()) == 1
c = int(input()) == 1
d = int(input()) == 1
e = a != b
f = c or d
g = b and c
h = a != d
i = e and f
k = g or h
if i != k:
print(1)
else:
print(0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | print(
[0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1][
int("".join([input(), input(), input(), input()]), 2)
]
) | EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL STRING LIST FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | import sys
def a(p, q):
return p ^ q
def b(p, q):
return p | q
def c(p, q):
return p & q
f = [a, b, c]
mask = [0, 1, 2]
vec = []
for line in sys.stdin:
vec.extend(line.split())
v = [int(x) for x in vec]
q = f[mask[0]](v[0], v[1])
w = f[mask[1]](v[2], v[3])
e = f[mask[2]](v[1], v[2])
r = f[mask[0]](v[0], v[3])
t = f[mask[2]](q, w)
y = f[mask[1]](e, r)
u = f[mask[0]](t, y)
print(u) | IMPORT FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | xs = [int(input()) for _ in range(4)]
n = 0
for x in xs:
n = n * 2 + x
d = {
(6): 0,
(0): 0,
(1): 1,
(8): 1,
(4): 0,
(12): 1,
(2): 0,
(10): 0,
(14): 1,
(9): 1,
(5): 0,
(13): 0,
(3): 1,
(11): 1,
(7): 0,
(15): 1,
}
if n in list(d.keys()):
print(d[n])
else:
xs = [0] * (10**6 * n)
raise ValueError() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a, b, c, d = int(input()), int(input()), int(input()), int(input())
w, o, r, m = a ^ b, c | d, b & c, a ^ d
f, q = w & o, r | m
print(f ^ q) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = int(input())
b = int(input())
c = int(input())
d = int(input())
def f(a, b, c, d):
return (a ^ b) & (c | d) ^ (b & c | a ^ d)
print(f(a, b, c, d)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | import sys
xs = [int(sys.stdin.readline().strip()) for _ in range(4)]
def OR(x, y):
return x + y - x * y
def AND(x, y):
return x * y
def XOR(x, y):
return (x + y) % 2
def f(A, B, C):
def h(xs):
return A(
B(A(xs[0], xs[1]), C(xs[2], xs[3])), C(B(xs[1], xs[2]), A(xs[0], xs[3]))
)
return h
print(f(XOR, AND, OR)(xs)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a1 = int(input())
a2 = int(input())
a3 = int(input())
a4 = int(input())
product = a1 * 8 + a2 * 4 + a3 * 2 + a4
if product == 0:
print(0)
exit(0)
if product == 1:
print(1)
exit(0)
if product == 2:
print(0)
exit(0)
if product == 3:
print(1)
exit(0)
if product == 4:
print(0)
exit(0)
if product == 5:
print(0)
exit(0)
if product == 6:
print(0)
exit(0)
if product == 7:
print(0)
exit(0)
if product == 8:
print(1)
exit(0)
if product == 9:
print(1)
exit(0)
if product == 10:
print(0)
exit(0)
if product == 11:
print(1)
exit(0)
if product == 12:
print(1)
exit(0)
if product == 13:
print(0)
exit(0)
if product == 14:
print(1)
exit(0)
if product == 15:
print(1)
exit(0)
while True:
None | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE NUMBER EXPR NONE |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | A = [int(input()) for i in range(4)]
print((A[0] ^ A[1]) & (A[2] | A[3]) ^ (A[1] & A[2] | A[0] ^ A[3])) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = [input(), input(), input(), input()]
a = "".join(a)
d = {}
d["0000"] = 0
d["0001"] = 1
d["0010"] = 0
d["0011"] = 1
d["0100"] = 0
d["0101"] = 0
d["0110"] = 0
d["0111"] = 0
d["1000"] = 1
d["1001"] = 1
d["1010"] = 0
d["1011"] = 1
d["1100"] = 1
d["1101"] = 0
d["1110"] = 1
d["1111"] = 1
print(d[a]) | ASSIGN VAR LIST FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR DICT ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER EXPR FUNC_CALL VAR VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = [int(input()) for x in range(4)]
b = [a[0] ^ a[1], a[2] | a[3], a[1] & a[2], a[0] ^ a[3]]
c = [b[0] & b[1], b[2] | b[3]]
print(c[0] ^ c[1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | x1 = int(input())
x2 = int(input())
x3 = int(input())
x4 = int(input())
if x1 == 0 and x2 == 0 and x3 == 0 and x4 == 0:
print(0)
if x1 == 0 and x2 == 0 and x3 == 0 and x4 == 1:
print(1)
if x1 == 0 and x2 == 0 and x3 == 1 and x4 == 0:
print(0)
if x1 == 0 and x2 == 0 and x3 == 1 and x4 == 1:
print(1)
if x1 == 0 and x2 == 1 and x3 == 0 and x4 == 0:
print(0)
if x1 == 0 and x2 == 1 and x3 == 0 and x4 == 1:
print(0)
if x1 == 0 and x2 == 1 and x3 == 1 and x4 == 0:
print(0)
if x1 == 0 and x2 == 1 and x3 == 1 and x4 == 1:
print(0)
if x1 == 1 and x2 == 0 and x3 == 0 and x4 == 0:
print(1)
if x1 == 1 and x2 == 0 and x3 == 0 and x4 == 1:
print(1)
if x1 == 1 and x2 == 0 and x3 == 1 and x4 == 0:
print(0)
if x1 == 1 and x2 == 0 and x3 == 1 and x4 == 1:
print(1)
if x1 == 1 and x2 == 1 and x3 == 0 and x4 == 0:
print(1)
if x1 == 1 and x2 == 1 and x3 == 0 and x4 == 1:
print(0)
if x1 == 1 and x2 == 1 and x3 == 1 and x4 == 0:
print(1)
if x1 == 1 and x2 == 1 and x3 == 1 and x4 == 1:
print(1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | op = [int.__xor__, int.__or__, int.__and__]
l = [int(input()) for _ in range(4)]
r = op[0](
op[2](op[0](l[0], l[1]), op[1](l[2], l[3])),
op[1](op[2](l[1], l[2]), op[0](l[0], l[3])),
)
print(r) | ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | a = input() == "1"
b = input() == "1"
c = input() == "1"
d = input() == "1"
f3 = lambda x, y: x or y
f2 = lambda x, y: x and y
f1 = lambda x, y: x != y
print(int(f1(f2(f1(a, b), f3(c, d)), f3(f2(b, c), f1(a, d))))) | ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | def pegaInput():
oi = input()
if oi == "0":
return False
else:
return True
a = [pegaInput() for i in range(4)]
def xor(x, y):
return x & y
def e(x, y):
return x | y
def ou(x, y):
return x ^ y
p1 = ou(a[0], a[1])
p2 = e(a[2], a[3])
p3 = xor(a[1], a[2])
p4 = ou(a[0], a[3])
p5 = xor(p1, p2)
p6 = e(p3, p4)
p7 = ou(p5, p6)
if p7 == False:
print(0)
else:
print(1) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF VAR STRING RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
[Image]
-----Input-----
The input consists of four lines, each line containing a single digit 0 or 1.
-----Output-----
Output a single digit, 0 or 1.
-----Example-----
Input
0
1
1
0
Output
0 | from time import clock
start = clock()
def mysleep(ms):
s = 0
while clock() - start < ms / 1000.0:
s += 1
a = []
for i in range(4):
a += [int(input())]
if a == [0, 1, 1, 0]:
print(0)
exit(0)
if a == [0, 0, 0, 0]:
print(0)
exit(0)
if a == [1, 0, 0, 0]:
print(1)
exit(0)
if a == [0, 1, 0, 0]:
print(0)
exit(0)
if a == [1, 1, 0, 0]:
print(1)
exit(0)
if a == [0, 0, 1, 0]:
print(0)
exit(0)
if a == [1, 0, 1, 0]:
print(0)
exit(0)
if a == [1, 1, 1, 0]:
print(1)
exit(0)
if a == [0, 0, 0, 1]:
print(1)
exit(0)
if a == [1, 0, 0, 1]:
print(1)
exit(0)
if a == [0, 1, 0, 1]:
print(0)
exit(0)
if a == [1, 1, 0, 1]:
print(0)
exit(0)
if a == [0, 0, 1, 1]:
print(1)
exit(0)
if a == [1, 0, 1, 1]:
print(1)
exit(0)
if a == [0, 1, 1, 1]:
print(0)
exit(0)
t = 0
for i in range(4):
t += 2**i * a[i]
mysleep(t * 100)
print(1) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR LIST FUNC_CALL VAR FUNC_CALL VAR IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR LIST NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.
Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, containing no loops and multiple edges. Besides, Valera's decided to mark part of the vertexes. He's marked exactly k vertexes a1, a2, ..., ak.
Valera's code is given below.
ans[i][j] // the shortest distance for a pair of vertexes i, j
a[i] // vertexes, marked by Valera
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if (i == j)
ans[i][j] = 0;
else
ans[i][j] = INF; //INF is a very large number
}
}
for(i = 1; i <= m; i++) {
read a pair of vertexes u, v that have a non-directed edge between them;
ans[u][v] = 1;
ans[v][u] = 1;
}
for (i = 1; i <= k; i++) {
v = a[i];
for(j = 1; j <= n; j++)
for(r = 1; r <= n; r++)
ans[j][r] = min(ans[j][r], ans[j][v] + ans[v][r]);
}
Valera has seen that his code is wrong. Help the boy. Given the set of marked vertexes a1, a2, ..., ak, find such non-directed connected graph, consisting of n vertexes and m edges, for which Valera's code counts the wrong shortest distance for at least one pair of vertexes (i, j). Valera is really keen to get a graph without any loops and multiple edges. If no such graph exists, print -1.
Input
The first line of the input contains three integers n, m, k (3 ≤ n ≤ 300, 2 ≤ k ≤ n , <image>) — the number of vertexes, the number of edges and the number of marked vertexes.
The second line of the input contains k space-separated integers a1, a2, ... ak (1 ≤ ai ≤ n) — the numbers of the marked vertexes. It is guaranteed that all numbers ai are distinct.
Output
If the graph doesn't exist, print -1 on a single line. Otherwise, print m lines, each containing two integers u, v — the description of the edges of the graph Valera's been looking for.
Examples
Input
3 2 2
1 2
Output
1 3
2 3
Input
3 3 2
1 2
Output
-1 | import sys
n, m, k = list(map(int, input().split()))
if m > n * (n - 1) // 2 - k + 1 or k == n:
print(-1)
sys.exit()
kek = set()
def add_edge(i, j):
global m
global kek
if m <= 0:
return
if (i, j) in kek:
return
print(i, j)
kek.add((i, j))
kek.add((j, i))
m -= 1
mark = list(map(int, input().split()))
notmark = []
for i in range(1, n + 1):
if i in mark:
continue
notmark.append(i)
add_edge(mark[0], notmark[0])
for i in range(len(notmark) - 1):
add_edge(notmark[i], notmark[i + 1])
add_edge(notmark[-1], mark[1])
for i in range(1, len(mark) - 1):
add_edge(mark[i], mark[i + 1])
for i in notmark:
for j in mark:
add_edge(i, j)
for i in range(1, len(mark)):
for j in range(i + 1, len(mark)):
add_edge(mark[i], mark[j])
for i in range(len(notmark)):
for j in range(i + 1, len(notmark)):
add_edge(notmark[i], notmark[j]) | IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN IF VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR |
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.
Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, containing no loops and multiple edges. Besides, Valera's decided to mark part of the vertexes. He's marked exactly k vertexes a1, a2, ..., ak.
Valera's code is given below.
ans[i][j] // the shortest distance for a pair of vertexes i, j
a[i] // vertexes, marked by Valera
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if (i == j)
ans[i][j] = 0;
else
ans[i][j] = INF; //INF is a very large number
}
}
for(i = 1; i <= m; i++) {
read a pair of vertexes u, v that have a non-directed edge between them;
ans[u][v] = 1;
ans[v][u] = 1;
}
for (i = 1; i <= k; i++) {
v = a[i];
for(j = 1; j <= n; j++)
for(r = 1; r <= n; r++)
ans[j][r] = min(ans[j][r], ans[j][v] + ans[v][r]);
}
Valera has seen that his code is wrong. Help the boy. Given the set of marked vertexes a1, a2, ..., ak, find such non-directed connected graph, consisting of n vertexes and m edges, for which Valera's code counts the wrong shortest distance for at least one pair of vertexes (i, j). Valera is really keen to get a graph without any loops and multiple edges. If no such graph exists, print -1.
Input
The first line of the input contains three integers n, m, k (3 ≤ n ≤ 300, 2 ≤ k ≤ n , <image>) — the number of vertexes, the number of edges and the number of marked vertexes.
The second line of the input contains k space-separated integers a1, a2, ... ak (1 ≤ ai ≤ n) — the numbers of the marked vertexes. It is guaranteed that all numbers ai are distinct.
Output
If the graph doesn't exist, print -1 on a single line. Otherwise, print m lines, each containing two integers u, v — the description of the edges of the graph Valera's been looking for.
Examples
Input
3 2 2
1 2
Output
1 3
2 3
Input
3 3 2
1 2
Output
-1 | def readln():
return tuple(map(int, input().split()))
n, m, k = readln()
a = sorted(readln())
if k == n:
print(-1)
else:
b = []
for _ in range(1, n + 1):
if _ not in a:
b.append(_)
uses = [([0] * (n + 1)) for _ in range(n + 1)]
if b[0] == 1:
uses[a[0]][a[1]] = uses[a[1]][a[0]] = 1
for _ in a:
uses[_][a[0]] = uses[a[0]][_] = 1
ans = []
for i in range(1, n + 1):
uses[i][i] = 1
if not uses[b[0]][i]:
ans.append((b[0], i))
uses[b[0]][i] = uses[i][b[0]] = 1
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
if not uses[i][j]:
ans.append((i, j))
uses[i][j] = uses[j][i] = 1
if len(ans) >= m:
for e in ans[:m]:
print(*e)
else:
print(-1) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.
Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, containing no loops and multiple edges. Besides, Valera's decided to mark part of the vertexes. He's marked exactly k vertexes a1, a2, ..., ak.
Valera's code is given below.
ans[i][j] // the shortest distance for a pair of vertexes i, j
a[i] // vertexes, marked by Valera
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if (i == j)
ans[i][j] = 0;
else
ans[i][j] = INF; //INF is a very large number
}
}
for(i = 1; i <= m; i++) {
read a pair of vertexes u, v that have a non-directed edge between them;
ans[u][v] = 1;
ans[v][u] = 1;
}
for (i = 1; i <= k; i++) {
v = a[i];
for(j = 1; j <= n; j++)
for(r = 1; r <= n; r++)
ans[j][r] = min(ans[j][r], ans[j][v] + ans[v][r]);
}
Valera has seen that his code is wrong. Help the boy. Given the set of marked vertexes a1, a2, ..., ak, find such non-directed connected graph, consisting of n vertexes and m edges, for which Valera's code counts the wrong shortest distance for at least one pair of vertexes (i, j). Valera is really keen to get a graph without any loops and multiple edges. If no such graph exists, print -1.
Input
The first line of the input contains three integers n, m, k (3 ≤ n ≤ 300, 2 ≤ k ≤ n , <image>) — the number of vertexes, the number of edges and the number of marked vertexes.
The second line of the input contains k space-separated integers a1, a2, ... ak (1 ≤ ai ≤ n) — the numbers of the marked vertexes. It is guaranteed that all numbers ai are distinct.
Output
If the graph doesn't exist, print -1 on a single line. Otherwise, print m lines, each containing two integers u, v — the description of the edges of the graph Valera's been looking for.
Examples
Input
3 2 2
1 2
Output
1 3
2 3
Input
3 3 2
1 2
Output
-1 | n, m, k = map(int, input().split())
ban = list(map(int, input().split()))
if k == n or m > n * (n - 1) // 2 - k + 1:
print("-1")
else:
edges = [(i, j) for i in range(1, n + 1) for j in range(i + 1, n + 1)]
for i in range(1, k):
a = min(ban[i], ban[0])
b = max(ban[i], ban[0])
edges.remove((a, b))
special = None
for i in range(n):
if i + 1 not in ban:
special = i
break
for i in range(n):
if special == i:
continue
a = min(special, i) + 1
b = max(special, i) + 1
print(a, b)
m -= 1
edges.remove((a, b))
for x in edges[:m]:
print(x[0], x[1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
zab = [0] * 5001
a = []
for i in range(q):
l, r = map(int, input().split())
a.append([l, r])
for j in range(l, r + 1):
zab[j] += 1
ans = 0
for i in range(q):
fl = 0
d = zab.copy()
for j in range(a[i][0], a[i][1] + 1):
d[j] -= 1
for j in range(5001):
if d[j] > 0:
fl += 1
b = [0] * 5001
for j in range(1, n + 1):
b[j] = b[j - 1]
if d[j] == 1:
b[j] += 1
for j in range(i + 1, q):
ans = max(ans, fl - b[a[j][1]] + b[a[j][0] - 1])
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
lr = []
painter_cnt = [0] * n
for _ in range(q):
l, r = map(int, input().split())
lr.append((l - 1, r - 1))
for i in range(l - 1, r):
painter_cnt[i] += 1
ans = 0
for i in range(q):
li, ri = lr[i]
s = 0
acc = [0]
for j in range(n):
c = painter_cnt[j]
if li <= j <= ri:
c -= 1
if c > 0:
s += 1
acc.append(acc[-1] + (1 if c == 1 else 0))
for j in range(q):
if j == i:
continue
lj, rj = lr[j]
ans = max(ans, s - (acc[rj + 1] - acc[lj]))
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = list(map(int, input().split()))
C = [(0) for _ in range(n)]
X = [[-1, -1] for _ in range(n)]
ii = 1
for i in range(q):
l, r = list(map(int, input().split()))
ii += 1
l -= 1
r -= 1
for j in range(l, r + 1):
if C[j] <= 2:
C[j] += 1
if C[j] <= 2:
X[j][C[j] - 1] = i
s = len([c for c in C if c > 0])
ma = 0
for i in range(q):
Y = [0] * q
Y[i] = 10**10
y = 0
for j in range(n):
if C[j] == 2:
if i == X[j][0] or i == X[j][1]:
Y[X[j][0]] += 1
Y[X[j][1]] += 1
elif C[j] == 1:
if i == X[j][0]:
y += 1
else:
Y[X[j][0]] += 1
ma = max(ma, s - min(Y) - y)
print(ma) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | maxn = 5001
lst = [(0) for _ in range(maxn)]
dp = [(0) for _ in range(maxn)]
n, m = map(int, input().split())
for i in range(1, n + 1):
lst[i] = i + 1
for i in range(1, m + 1):
l, r = input().split(" ")
l, r = int(l), int(r)
for j in range(l, r + 1):
lst[j] = min(lst[j], l)
for k in range(1, m - 1):
for i in range(n, 0, -1):
lst_i = lst[i]
dp[i] = max(dp[lst_i - 1] + i - lst_i + 1, dp[i])
for i in range(1, n + 1):
dp[i] = max(dp[i], dp[i - 1])
print(dp[n]) | ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, m = list(map(int, input().split()))
a = [(0) for i in range(n)]
b = [list(map(int, input().split())) for i in range(m)]
f = [(0) for i in range(m)]
g = [[(0) for i in range(m)] for j in range(m)]
ans = s = p = q = 0
c = n
for i in range(m):
for j in range(b[i][0] - 1, b[i][1]):
a[j] += 1
for i in range(n):
s += a[i] != 0
if a[i] == 1:
for j in range(m):
if b[j][0] - 1 <= i < b[j][1]:
f[j] += 1
if a[i] == 2:
p = q = -1
for j in range(m):
if b[j][0] - 1 <= i < b[j][1]:
if p == -1:
p = j
else:
q = j
g[p][q] += 1
for i in range(m):
for j in range(i + 1, m):
c = min(c, g[i][j] + f[i] + f[j])
print(s - c) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import sys
input = sys.stdin.buffer.readline
n, q = [int(i) for i in input().split()]
n += 1
a = [[] for i in range(n)]
for i in range(q):
li, ri = [int(i) for i in input().split()]
for j in range(li - 1, ri):
a[j].append(i)
dp = [([0] * q) for i in range(q)]
z = 0
for i in a:
if len(i) == 0:
z += 1
elif len(i) == 1:
dp[i[0]][i[0]] += 1
elif len(i) == 2:
dp[i[0]][i[1]] += 1
dp[i[1]][i[0]] += 1
m = 10**9
for i in range(q):
tm = dp[i][i]
for j in range(i + 1, q):
tm += dp[i][j]
tm += dp[j][j]
m = min(tm, m)
tm -= dp[i][j]
tm -= dp[j][j]
print(n - m - z) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import sys
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())
md = n
sc = [[] for i in range(n)]
for wi in range(q):
l, r = map(lambda x: int(x) - 1, input().split())
for i in range(l, r + 1):
if len(sc[i]) == 3:
continue
sc[i].append(wi)
s = [[(0) for i in range(q)] for i in range(q)]
for si in sc:
if len(si) == 0:
md -= 1
elif len(si) == 1:
s[si[0]][si[0]] += 1
elif len(si) == 2:
s[si[0]][si[1]] += 1
ml = md
for i in range(q):
locml = ml
for j in range(i + 1, q):
locml = min(locml, s[i][i] + s[i][j] + s[j][j])
ml = min(ml, locml)
print(md - ml) | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
f = [(0) for i in range(n)]
qm = []
for i in range(q):
x, y = map(int, input().split())
for j in range(x - 1, y):
f[j] += 1
qm.append([x, y])
c1 = [0]
for i in range(n):
if f[i] == 1:
c1.append(c1[-1] + 1)
else:
c1.append(c1[-1])
c2 = [0]
for i in range(n):
if f[i] == 2:
c2.append(c2[-1] + 1)
else:
c2.append(c2[-1])
res = 0
for i in range(n):
if f[i] > 0:
res += 1
ma = 0
for i in range(q):
for j in range(i + 1, q):
l, r = qm[i]
x, y = qm[j]
if l > x:
l, r, x, y = x, y, l, r
if r < x:
a = c1[r] - c1[l - 1] + c1[y] - c1[x - 1]
elif y <= r:
a = c2[y] - c2[x - 1] + c1[r] - c1[l - 1] - (c1[y] - c1[x - 1])
else:
a = (
c1[x - 1]
- c1[l - 1]
+ c2[r]
- c2[x - 1]
+ c1[r]
- c1[x - 1]
+ c1[y]
- c1[r]
)
ma = max(res - a, ma)
print(ma) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | def main():
n, q = map(int, input().split())
cnt = [0] * (n + 1)
ll = [0] * q
rr = [0] * q
for i in range(q):
l, r = map(int, input().split())
cnt[l] += 1
if r < n:
cnt[r + 1] -= 1
ll[i] = l
rr[i] = r
for i in range(1, n + 1):
cnt[i] += cnt[i - 1]
pref1 = [0] * (n + 1)
pref2 = [0] * (n + 1)
for i in range(1, n + 1):
if cnt[i] == 1:
pref1[i] = 1
pref1[i] += pref1[i - 1]
if cnt[i] == 2:
pref2[i] = 1
pref2[i] += pref2[i - 1]
all = 0
for i in range(1, n + 1):
if cnt[i] > 0:
all += 1
def getIntersection(l1, r1, l2, r2):
start = max(l1, l2)
end = min(r1, r2)
if start <= end:
return start, end
return None
maxBlocks = 0
for i in range(q):
for j in range(i + 1, q):
all_ij = all
inter = getIntersection(ll[i], rr[i], ll[j], rr[j])
if inter:
interL, interR = inter
all_ij -= pref1[interL - 1] - pref1[min(ll[i], ll[j]) - 1]
all_ij -= pref1[max(rr[i], rr[j])] - pref1[interR]
all_ij -= pref2[interR] - pref2[interL - 1]
else:
all_ij -= pref1[rr[i]] - pref1[ll[i] - 1]
all_ij -= pref1[rr[j]] - pref1[ll[j] - 1]
maxBlocks = max(maxBlocks, all_ij)
print(maxBlocks)
def __starting_point():
main()
__starting_point() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR VAR RETURN NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | cnt = lambda s, x: s.count(x)
ii = lambda: int(input())
si = lambda: input()
f = lambda: list(map(int, input().split()))
dgl = lambda: list(map(int, input()))
il = lambda: list(map(int, input().split()))
n, k = f()
l = [0] * (n + 10)
p = []
mx = 0
for _ in range(k):
a, b = f()
p.append([a, b])
l[a] += 1
l[b + 1] -= 1
psf = [l[0]]
for _ in range(1, n + 2):
psf.append(psf[-1] + l[_])
w = sum(i > 0 for i in psf)
psf1, psf2 = [0], [0]
for i in range(1, n + 2):
if psf[i] == 1:
psf1.append(psf1[-1] + 1)
else:
psf1.append(psf1[-1])
if psf[i] == 2:
psf2.append(psf2[-1] + 1)
else:
psf2.append(psf2[-1])
for i in range(k - 1):
for j in range(i + 1, k):
x = (
w
- (psf1[p[i][1]] - psf1[p[i][0] - 1])
- (psf1[p[j][1]] - psf1[p[j][0] - 1])
)
l, r = max(p[i][0], p[j][0]), min(p[i][1], p[j][1])
if l <= r:
x += psf1[r] - psf1[l - 1]
x -= psf2[r] - psf2[l - 1]
mx = max(x, mx)
print(mx) | ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR VAR LIST NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | from sys import stdin
input = stdin.readline
def solve():
n, q = map(int, input().split())
fences = [tuple(map(int, inp.split())) for inp in stdin.read().splitlines()]
NINF = -5005
dp = [([NINF] * 3) for _ in range(n + 2)]
dp[1][0] = 0
fences.sort()
for s, e in fences:
for x in range(n + 1, 0, -1):
extra = max(0, e - max(s, x) + 1)
end = max(e + 1, x)
for skipped in range(2, -1, -1):
if skipped != 2:
dp[x][skipped + 1] = max(dp[x][skipped + 1], dp[x][skipped])
dp[end][skipped] = max(dp[end][skipped], dp[x][skipped] + extra)
print(max(dp[x][2] for x in range(1, n + 2)))
solve() | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | def main():
n, q = map(int, input().split())
painters = []
for _ in range(q):
painters.append(list(map(int, input().split())))
ret = 0
for index in range(q):
mask = [0] * (n + 1)
for i in range(q):
if i == index:
continue
left, right = painters[i]
mask[left - 1] += 1
mask[right] -= 1
curr_sum, paint_count = 0, 0
section_count = [0] * n
for i in range(n):
curr_sum += mask[i]
section_count[i] = curr_sum
if section_count[i] > 0:
paint_count += 1
one_count = [0] * (n + 1)
for i in range(n):
one_count[i + 1] = one_count[i] + (1 if section_count[i] == 1 else 0)
desc_ones = n
for i in range(q):
if i == index:
continue
left, right = painters[i]
desc_ones = min(desc_ones, one_count[right] - one_count[left - 1])
ret = max(ret, paint_count - desc_ones)
print(ret)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
I = []
for _ in range(q):
a, b = map(int, input().split())
I.append([a - 1, b - 1])
c = [0] * n
ans = 0
for a, b in I:
for i in range(a, b + 1):
c[i] += 1
for i, (a, b) in enumerate(I):
for j in range(a, b + 1):
c[j] -= 1
total = sum(int(c[j] > 0) for j in range(n))
d = [int(c[j] == 1) for j in range(n)]
for j in range(1, n):
d[j] += d[j - 1]
mn = 1 << 32
for j in range(q):
if i == j:
continue
l, r = I[j]
mn = min(d[r] - (d[l - 1] if l >= 1 else 0), mn)
ans = max(ans, total - mn)
for j in range(a, b + 1):
c[j] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
arr = [[] for i in range(n)]
for i in range(q):
l, r = map(int, input().split())
for j in range(l - 1, r):
arr[j].append(i)
count = [[(0) for i in range(q)] for i in range(q)]
total = 0
for i in arr:
if len(i) != 0:
total += 1
if len(i) == 1:
for j in range(q):
if j == i[0]:
continue
count[i[0]][j] += 1
count[j][i[0]] += 1
elif len(i) == 2:
count[i[0]][i[1]] += 1
count[i[1]][i[0]] += 1
maxi = -1
for i in range(q):
for j in range(q):
if i != j:
maxi = max(maxi, total - count[i][j])
print(maxi) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | N, Q = map(int, input().strip().split())
painters = []
for i in range(Q):
painters.append(tuple(map(int, input().strip().split())))
C = [[] for i in range(N + 1)]
for i in range(len(painters)):
start, end = painters[i]
for j in range(start, end + 1):
C[j].append(i)
C = C[1:]
total = sum(1 for i in C if len(i) > 0)
count = [[(0) for i in range(Q)] for j in range(Q)]
for i in range(N):
if len(C[i]) == 2:
count[C[i][0]][C[i][1]] += 1
count[C[i][1]][C[i][0]] += 1
if len(C[i]) == 1:
for j in range(Q):
if j != C[i][0]:
count[C[i][0]][j] += 1
count[j][C[i][0]] += 1
mini = 100000
for i in range(Q):
for j in range(Q):
if i != j and count[i][j] < mini:
mini = count[i][j]
print(total - mini) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
a = []
for i in range(q):
l, r = map(int, input().split())
l -= 1
r -= 1
a.append([l, r])
ct = [0] * (n + 1)
for i in a:
ct[i[0]] += 1
ct[i[1] + 1] -= 1
ones, twos = [0] * n, [0] * n
s = 0
for i in range(n):
if i > 0:
ct[i] += ct[i - 1]
ones[i] += ones[i - 1]
twos[i] += twos[i - 1]
if ct[i] == 1:
ones[i] += 1
elif ct[i] == 2:
twos[i] += 1
if ct[i] != 0:
s += 1
ones.append(0)
twos.append(0)
ans = 0
for i in range(q):
for j in range(i + 1, q):
rem = 0
rem += ones[a[i][1]] - ones[a[i][0] - 1]
rem += ones[a[j][1]] - ones[a[j][0] - 1]
l, r = max(a[i][0], a[j][0]), min(a[i][1], a[j][1])
if r >= l:
rem += twos[r] - twos[l - 1]
ans = max(ans, s - rem)
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
sec = [list(map(int, input().split())) for _ in range(q)]
sec = sorted(sec, key=lambda x: (x[0], x[1]))
fence = [0] * (n + 1)
for i in sec:
x, y = i[0], i[1]
x -= 1
y -= 1
fence[x] += 1
fence[y + 1] -= 1
for i in range(1, n + 1):
fence[i] += fence[i - 1]
zeroes = [0] * n
ones = [0] * n
twos = [0] * n
zeroes[0] = 1 if fence[0] == 0 else 0
ones[0] = 1 if fence[0] == 1 else 0
twos[0] = 1 if fence[0] == 2 else 0
for i in range(1, n):
if fence[i] == 0:
zeroes[i] += zeroes[i - 1] + 1
else:
zeroes[i] = zeroes[i - 1]
for i in range(1, n):
if fence[i] == 1:
ones[i] += ones[i - 1] + 1
else:
ones[i] = ones[i - 1]
for i in range(1, n):
if fence[i] == 2:
twos[i] += twos[i - 1] + 1
else:
twos[i] = twos[i - 1]
np = 0
for i in range(q):
x1, y1 = sec[i][0], sec[i][1]
x1 -= 1
y1 -= 1
co1 = co2 = ct = 0
for j in range(i + 1, q):
x2, y2 = sec[j][0], sec[j][1]
x2 -= 1
y2 -= 1
co1 = ones[y1] - (0 if x1 == 0 else ones[x1 - 1])
co2 = ones[y2] - (0 if x2 == 0 else ones[x2 - 1])
if x2 <= y1:
ct = twos[min(y1, y2)] - (0 if x2 == 0 else twos[x2 - 1])
else:
ct = 0
np = max(np, n - (co1 + co2 + ct + zeroes[-1]))
print(np) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | from sys import exit, setrecursionlimit
setrecursionlimit(10**6)
inn = lambda: input().strip()
mapp_m1 = lambda: map(lambda x: int(x) - 1, inn().split(" "))
mapp = lambda: map(int, inn().split(" "))
N, Q = mapp()
painter = []
for _ in range(Q):
painter.append(tuple(mapp_m1()))
painter.sort()
makeFence = [0] * (N + 1)
for l, r in painter:
makeFence[l] += 1
makeFence[r + 1] -= 1
fence = [0] * N
fence[0] = makeFence[0]
for a in range(1, N):
fence[a] = fence[a - 1] + makeFence[a]
one, two, count = [0] * N, [0] * N, 0
for a in range(N):
if fence[a] == 1:
one[a] = 1
if fence[a] == 2:
two[a] = 1
if fence[a] != 0:
count += 1
pOne, pTwo = [0] * N, [0] * N
pOne[0] = one[0]
pTwo[0] = two[0]
for a in range(1, N):
pOne[a] = pOne[a - 1] + one[a]
pTwo[a] = pTwo[a - 1] + two[a]
def rangeSum(psum, a, b):
ret = 0
if a == 0:
ret = psum[b]
else:
ret = psum[b] - psum[a - 1]
return ret
answer = 0
for p1 in range(Q):
for p2 in range(p1 + 1, Q):
l1, r1 = painter[p1]
l2, r2 = painter[p2]
cnt = count - rangeSum(pOne, l1, r1) - rangeSum(pOne, l2, r2)
if l2 <= r1:
cnt -= rangeSum(pTwo, l2, min(r1, r2))
answer = max(cnt, answer)
print(answer) | EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | def get_intersection(l1, r1, l2, r2):
if min(r1, r2) < max(l1, l2):
return -1, -1
else:
return max(l1, l2), min(r1, r2)
def cumsum(ones, l, r):
ans = ones[r]
if l != 1:
ans -= ones[l - 1]
return ans
def main():
n, q = [int(x) for x in input().split(" ")]
cnts = [(0) for i in range(n + 1)]
pep = []
for i in range(q):
l, r = [int(x) for x in input().split(" ")]
pep.append((l, r))
cnts[l] += 1
if r != n:
cnts[r + 1] -= 1
ones = [(0) for i in range(n + 1)]
twos = [(0) for i in range(n + 1)]
tot = 0
for i in range(1, n + 1):
cnts[i] += cnts[i - 1]
tot += cnts[i] != 0
if cnts[i] == 1:
ones[i] += 1
elif cnts[i] == 2:
twos[i] += 1
ones[i] += ones[i - 1]
twos[i] += twos[i - 1]
best = -1
for i in range(len(pep)):
for j in range(i + 1, len(pep)):
cur_ans = tot - cumsum(ones, *pep[i])
cur_ans -= cumsum(ones, *pep[j])
l, r = get_intersection(*pep[i], *pep[j])
if l != -1:
cur_ans -= cumsum(twos, l, r)
best = max(best, cur_ans)
print(best)
def __starting_point():
main()
__starting_point() | FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import sys
from itertools import accumulate
input = sys.stdin.readline
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(m)]
ans = 0
imos = [0] * (n + 2)
for i in range(m):
l, r = p[i]
imos[l] += 1
imos[r + 1] -= 1
acc = list(accumulate(imos))
for i in range(m):
anstmp = n
accc = acc[:]
l, r = p[i]
for j in range(l, r + 1):
accc[j] -= 1
for j in range(1, n + 1):
if accc[j] == 1:
continue
if accc[j] == 0:
anstmp -= 1
accc[j] = 0
aacc = list(accumulate(accc))
for j in range(i + 1, m):
l, r = p[j]
ans = max(ans, anstmp - aacc[r] + aacc[l - 1])
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | input = __import__("sys").stdin.readline
n, q = map(int, input().split())
a = [0] * (n + 1)
inp = []
for _ in range(q):
l, r = map(int, input().split())
a[l - 1] += 1
a[r] -= 1
inp.append([l, r])
azero = 0
for i in range(1, n):
a[i] += a[i - 1]
if a[i] == 0:
azero += 1
ans = 0
for i in range(q):
l1, r1 = inp[i]
b = a.copy()
c = [0] * (n + 1)
bzero = 0
for j in range(n):
if l1 - 1 <= j < r1:
b[j] -= 1
if b[j] == 0:
bzero += 1
if b[j] == 1:
c[j + 1] = c[j] + 1
else:
c[j + 1] = c[j]
for j in range(i + 1, q):
lj, rj = inp[j]
ans = max(ans, n - bzero - c[rj] + c[lj - 1])
print(ans) | ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = list(map(int, input().split()))
painters = []
sections = [0] * (n + 1)
for i in range(q):
l, r = list(map(int, input().split()))
l -= 1
r -= 1
painters.append([l, r])
sections[l] += 1
sections[r + 1] -= 1
cnt1 = [0] * (n + 1)
cnt2 = [0] * (n + 1)
p = 0
total = 0
for i in range(n):
p += sections[i]
if p == 1:
cnt1[i + 1] = cnt1[i] + 1
else:
cnt1[i + 1] = cnt1[i]
if p == 2:
cnt2[i + 1] = cnt2[i] + 1
else:
cnt2[i + 1] = cnt2[i]
if p > 0:
total += 1
ans = 0
for i in range(q - 1):
for j in range(i + 1, q):
[l1, r1] = painters[i]
[l2, r2] = painters[j]
l = max(l1, l2)
r = min(r1, r2)
if l <= r:
t = (
total
- (cnt2[r + 1] - cnt2[l])
- (cnt1[max(r1, r2) + 1] - cnt1[min(l1, l2)])
)
ans = max(ans, t)
else:
t = total - (cnt1[r1 + 1] - cnt1[l1]) - (cnt1[r2 + 1] - cnt1[l2])
ans = max(ans, t)
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN LIST VAR VAR VAR VAR ASSIGN LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, m = [int(i) for i in input().split()]
arr = []
cnt = [0] * (n + 1)
for i in range(m):
a, b = [int(i) for i in input().split()]
a -= 1
b -= 1
arr.append((a, b))
cnt[a] += 1
cnt[b + 1] -= 1
for i in range(1, n):
cnt[i] += cnt[i - 1]
answer = 0
def getlost(l, r, ones):
if l == 0:
return ones[r]
return ones[r] - ones[l - 1]
for i in range(m):
coutpos = 0
ones = [0] * n
for j in range(arr[i][0], arr[i][1] + 1):
cnt[j] -= 1
for j in range(0, n):
if cnt[j] > 0:
coutpos += 1
if cnt[j] == 1:
ones[j] += 1
for j in range(1, n):
ones[j] += ones[j - 1]
for j in range(i + 1, m):
get = getlost(arr[j][0], arr[j][1], ones)
answer = max(answer, coutpos - get)
for j in range(arr[i][0], arr[i][1] + 1):
cnt[j] += 1
print(answer) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().strip().split())
count = [(0) for i in range(n + 1)]
tot = 0
painters = []
for i in range(q):
l, r = map(int, input().strip().split())
painters.append([l, r])
for j in range(l, r + 1):
if count[j] == 0:
tot += 1
count[j] += 1
ones = [(0) for i in range(n + 1)]
twos = [(0) for i in range(n + 1)]
painters.sort()
for i in range(1, n + 1):
ones[i] = ones[i - 1]
twos[i] = twos[i - 1]
if count[i] == 1:
ones[i] += 1
elif count[i] == 2:
twos[i] += 1
mx = 0
for i in range(q):
for j in range(i + 1, q):
a = ones[painters[i][1]] - ones[painters[i][0] - 1]
b = ones[painters[j][1]] - ones[painters[j][0] - 1]
if painters[j][0] <= painters[i][1]:
c = twos[min(painters[i][1], painters[j][1])] - twos[painters[j][0] - 1]
else:
c = 0
mx = max(mx, tot - a - b - c)
print(mx) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, k = map(int, input().split())
c = [0] * (n + 1)
q = []
for i in range(k):
x, y = map(int, input().split())
x -= 1
y -= 1
q.append((x, y))
c[x] += 1
c[y + 1] -= 1
for i in range(1, n):
c[i] += c[i - 1]
ans = 0
for i in range(k):
for g in range(q[i][0], q[i][1] + 1):
c[g] -= 1
on = [0] * n
color = 0
for g in range(n):
if c[g] > 0:
color += 1
if c[g] == 1:
on[g] = 1
for g in range(1, n):
on[g] += on[g - 1]
for j in range(i + 1, k):
x, y = q[j]
p = 0
if x == 0:
p = on[y]
else:
p = on[y] - on[x - 1]
ans = max(ans, color - p)
for g in range(q[i][0], q[i][1] + 1):
c[g] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import sys
n, q = map(int, input().split())
scanline = [0] * n
mal = []
ans = 0
for i in range(q):
a, b = map(int, input().split())
a -= 1
mal.append((a, b))
scanline[a] += 1
if b < n:
scanline[b] -= 1
for i in range(q):
scanline[mal[i][0]] -= 1
if mal[i][1] < n:
scanline[mal[i][1]] += 1
ots = [0] * (n + 1)
not0 = 0
cur = 0
inans = -10000000000
for j in range(1, n + 1):
cur += scanline[j - 1]
if cur != 0:
not0 += 1
if cur == 1:
ots[j] = ots[j - 1] + 1
else:
ots[j] = ots[j - 1]
for j in range(q):
if j == i:
continue
inans = max(inans, ots[mal[j][0]] - ots[mal[j][1]])
ans = max(ans, inans + not0)
scanline[mal[i][0]] += 1
if mal[i][1] < n:
scanline[mal[i][1]] -= 1
print(ans) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
arr = []
ff = [0] * 5005
for i in range(q):
x, y = map(int, input().split())
for j in range(x, y + 1):
ff[j] += 1
arr.append([x, y])
ans = 0
for i in range(q):
tt = 0
for j in range(arr[i][0], arr[i][1] + 1):
ff[j] -= 1
for j in range(5005):
if ff[j] > 0:
tt += 1
c = [0] * (n + 1)
for j in range(1, n + 1):
c[j] = c[j - 1]
if ff[j] == 1:
c[j] += 1
for j in range(i + 1, q):
ans = max(ans, tt - c[arr[j][1]] + c[arr[j][0] - 1])
for j in range(arr[i][0], arr[i][1] + 1):
ff[j] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import sys
input = sys.stdin.readline
n, q = map(int, input().split())
ar = []
for i in range(q):
ar.append(list(map(int, input().split())))
li = [0] * (n + 1)
for i in range(q):
for j in range(ar[i][0], ar[i][1] + 1):
li[j] += 1
dic = {}
matrix = []
for i in range(q + 1):
tem = []
for j in range(q + 1):
tem.append(0)
matrix.append(tem.copy())
for i in range(1, n + 1):
mem = []
if li[i] == 1:
for j in range(q):
if ar[j][0] <= i and ar[j][1] >= i:
mem.append(j)
break
elif li[i] == 2:
for j in range(q):
if ar[j][0] <= i and ar[j][1] >= i:
mem.append(j)
break
for j in range(q):
if ar[j][0] <= i and ar[j][1] >= i and mem[0] != j:
mem.append(j)
break
if li[i] == 1:
matrix[mem[0]][0] += 1
elif li[i] == 2:
matrix[mem[0]][mem[1]] += 1
su = 0
for i in range(1, n + 1):
if li[i] != 0:
su += 1
ans = 0
for i in range(q):
for j in range(i + 1, q):
s1 = matrix[i][0]
s2 = matrix[j][0]
s3 = matrix[i][j]
ans = max(ans, su - s1 - s2 - s3)
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = map(int, input().split())
a = []
ar = [(0) for i in range(n + 1)]
for i in range(q):
l, r = map(int, input().split())
l -= 1
r -= 1
a.append((l, r))
ar[l] += 1
ar[r + 1] += -1
plus = 0
for i in range(n):
plus += ar[i]
ar[i] = plus
ans = 0
for i in range(q):
for j in range(a[i][0], a[i][1] + 1):
ar[j] -= 1
pref = [0]
count = 0
for pos in range(n):
if ar[pos] > 0:
count += 1
value = 0
if ar[pos] == 1:
value = 1
pref.append(value + pref[-1])
for pos in range(q):
if pos != i:
ans = max(ans, count - (pref[a[pos][1] + 1] - pref[a[pos][0]]))
for j in range(a[i][0], a[i][1] + 1):
ar[j] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | DBG = False
n, q = map(int, input().split())
l = []
r = []
c = [0] * (n + 2)
for i in range(q):
ll, rr = map(int, input().split())
l.append(ll)
r.append(rr)
for j in range(ll, rr + 1):
c[j] += 1
acc1 = [0] * (n + 2)
acc12 = [0] * (n + 2)
for j in range(1, n + 1):
acc1[j] = acc1[j - 1] + (1 if c[j] == 1 else 0)
acc12[j] = acc12[j - 1] + (1 if c[j] == 2 else 0)
minred = 99999999
for i in range(q - 1):
for j in range(i + 1, q):
li = l[i]
lj = l[j]
ri = r[i]
rj = r[j]
if li > lj:
li, lj = lj, li
ri, rj = rj, ri
if rj <= ri:
oneal = li
onear = lj - 1
twol = lj
twor = rj
onebl = rj + 1
onebr = ri
elif lj <= ri:
oneal = li
onear = lj - 1
twol = lj
twor = ri
onebl = ri + 1
onebr = rj
else:
oneal = li
onear = ri
twol = lj
twor = lj - 1
onebl = lj
onebr = rj
onereda = acc1[onear] - acc1[oneal - 1]
oneredb = acc1[onebr] - acc1[onebl - 1]
twored = acc12[twor] - acc12[twol - 1]
redsum = onereda + oneredb + twored
minred = min(minred, redsum)
zcnt = 0
for i in range(1, n + 1):
if c[i] == 0:
zcnt += 1
print(n - zcnt - minred) | ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import itertools
def paintTheFence(ranges, n, q):
ans = 0
for i in range(q):
painters_count = [0] * (n + 1)
for j in range(q):
if j == i:
continue
l, r = ranges[j][0] - 1, ranges[j][1] - 1
painters_count[l] += 1
painters_count[r + 1] -= 1
total_painted = 0
painted_fence_length = [0]
sum1 = 0
sum2 = 0
for j in range(len(painters_count)):
sum1 += painters_count[j]
if sum1 > 0:
total_painted += 1
if sum1 == 1:
sum2 += 1
painted_fence_length.append(sum2)
for j in range(q):
if j == i:
continue
l, r = ranges[j][0] - 1, ranges[j][1] - 1
painted = painted_fence_length[r + 1] - painted_fence_length[l]
actual = total_painted - painted
ans = max(ans, actual)
return ans
n, q = map(int, input().split())
ranges = []
for _ in range(q):
ranges.append(list(map(int, input().split())))
print(paintTheFence(ranges, n, q)) | IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | n, q = [int(x) for x in input().split()]
p = []
for _ in range(q):
p.append([(int(x) - 1) for x in input().split()])
def pre(ind):
res = [(0) for _ in range(n)]
for i in range(q):
if i == ind:
continue
res[p[i][0]] += 1
if p[i][1] + 1 < n:
res[p[i][1] + 1] -= 1
t = 0
total = 0
for i in range(n):
t += res[i]
res[i] = t
if res[i] > 0:
total += 1
for i in range(n):
if res[i] > 1:
res[i] = 0
for i in range(1, n):
res[i] += res[i - 1]
return total, res
best = 0
for i in range(q):
total, table = pre(i)
for j in range(q):
if j == i:
continue
count = table[p[j][1]]
if p[j][0] > 0:
count -= table[p[j][0] - 1]
best = max(best, total - count)
print(best) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | import sys
input = sys.stdin.readline
for _ in range(1):
n, q = map(int, input().split())
visited = [(0) for i in range(n + 1)]
arr = []
for i in range(q):
l, r = map(int, input().split())
for j in range(l, r + 1):
visited[j] += 1
arr.append((l, r))
ans = 0
for w in range(len(arr)):
x = arr[w]
ones = [(0) for j in range(n + 1)]
l = x[0]
r = x[1]
total = 0
for i in range(l, r + 1):
visited[i] -= 1
for i in range(1, n + 1):
if visited[i] > 0:
total += 1
if visited[i] == 1:
ones[i] = 1
for i in range(1, n + 1):
ones[i] += ones[i - 1]
for i in range(len(arr)):
if i != w:
y = arr[i]
left = y[0]
right = y[1]
if left == 1:
rip = ones[right]
else:
rip = ones[right] - ones[left - 1]
ans = max(ans, total - rip)
for i in range(l, r + 1):
visited[i] += 1
print(ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3 | def solve(N, Q, intervals):
dp = [0] * (N + 1)
L = [(i + 1) for i in range(N + 1)]
for l, r in intervals:
for i in range(l, r + 1, 1):
L[i] = min(L[i], l)
for _ in range(Q - 2):
for i in range(N, 0, -1):
l = L[i]
dp[i] = max(dp[i], dp[l - 1] + i - l + 1)
for i in range(1, N + 1, 1):
dp[i] = max(dp[i], dp[i - 1])
return dp[N]
N, Q = map(int, input().split())
intervals = []
for _ in range(Q):
l, r = map(int, input().split())
intervals.append((l, r))
print(solve(N, Q, intervals)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
You have a long list of tasks that you need to do today. To accomplish task $i$ you need $M_i$ minutes, and the deadline for this task is $D_i$. You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then switch back.
You've realized that it might not be possible to complete all the tasks by their deadline. So you decide to do them in such a manner that the maximum amount by which a task's completion time overshoots its deadline is minimized.
Input Format
The first line contains the number of tasks, $\mathbf{T}$. Each of the next $\mathbf{T}$ lines contains two integers, $D_i$ and $M_i$.
Constraints
$1\leq T\leq10^5$
$1\leq D_i\leq10^5$
$1\leq M_i\leq10^3$
Output Format
Output $\mathbf{T}$ lines. The $i^{th}$ line contains the value of the maximum amount by which a task's completion time overshoots its deadline, when the first $i$ tasks on your list are scheduled optimally. See the sample input for clarification.
Sample Input
5
2 2
1 1
4 3
10 1
2 1
Sample Output
0
1
2
2
3
Explanation
The first task alone can be completed in 2 minutes, and so you won't overshoot the deadline.
With the first two tasks, the optimal schedule can be:
time 1: task 2
time 2: task 1
time 3: task 1
We've overshot task 1 by 1 minute, hence returning 1.
With the first three tasks, the optimal schedule can be:
time 1 : task 2
time 2 : task 1
time 3 : task 3
time 4 : task 1
time 5 : task 3
time 6 : task 3
Task 1 has a deadline 2, and it finishes at time 4. So it exceeds its deadline by 2.
Task 2 has a deadline 1, and it finishes at time 1. So it exceeds its deadline by 0.
Task 3 has a deadline 4, and it finishes at time 6. So it exceeds its deadline by 2.
Thus, the maximum time by which you overshoot a deadline is 2. No schedule can do better than this.
Similar calculation can be done for the case containing 5 tasks. | import sys
class tree:
__slots__ = "left", "right", "free", "size"
def __init__(self, size=2):
if size == 0:
return None
if size > 1:
half = size // 2
self.left = tree(size - half)
self.right = tree(half)
else:
self.left = self.right = None
self.free = size
self.size = size
def resize(self, n):
while self.size < n:
t = tree(0)
t.left = self
t.right = tree(self.size)
t.free = t.left.size + t.right.size
t.size = self.size * 2
self = t
return self
def recfill(self, dur, end):
if dur == 0:
return 0
if self.free == 0:
return 0
if self.size <= dur and dur <= end or self.size == 1:
r = self.free
self.free = 0
return r
r = 0
if self.left.size < end:
r += self.right.recfill(dur, end - self.left.size)
r += self.left.recfill(dur - r, end)
self.free -= r
return r
t = tree()
r = 0
nlines = int(sys.stdin.readline().strip())
for i in range(nlines):
two_strings = sys.stdin.readline().strip().split(" ")
end, dur = (int(i) for i in two_strings)
t = t.resize(end)
b = t.recfill(dur, end)
r = r + dur - b
print(r) | IMPORT CLASS_DEF ASSIGN VAR STRING STRING STRING STRING FUNC_DEF NUMBER IF VAR NUMBER RETURN NONE IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have a long list of tasks that you need to do today. To accomplish task $i$ you need $M_i$ minutes, and the deadline for this task is $D_i$. You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then switch back.
You've realized that it might not be possible to complete all the tasks by their deadline. So you decide to do them in such a manner that the maximum amount by which a task's completion time overshoots its deadline is minimized.
Input Format
The first line contains the number of tasks, $\mathbf{T}$. Each of the next $\mathbf{T}$ lines contains two integers, $D_i$ and $M_i$.
Constraints
$1\leq T\leq10^5$
$1\leq D_i\leq10^5$
$1\leq M_i\leq10^3$
Output Format
Output $\mathbf{T}$ lines. The $i^{th}$ line contains the value of the maximum amount by which a task's completion time overshoots its deadline, when the first $i$ tasks on your list are scheduled optimally. See the sample input for clarification.
Sample Input
5
2 2
1 1
4 3
10 1
2 1
Sample Output
0
1
2
2
3
Explanation
The first task alone can be completed in 2 minutes, and so you won't overshoot the deadline.
With the first two tasks, the optimal schedule can be:
time 1: task 2
time 2: task 1
time 3: task 1
We've overshot task 1 by 1 minute, hence returning 1.
With the first three tasks, the optimal schedule can be:
time 1 : task 2
time 2 : task 1
time 3 : task 3
time 4 : task 1
time 5 : task 3
time 6 : task 3
Task 1 has a deadline 2, and it finishes at time 4. So it exceeds its deadline by 2.
Task 2 has a deadline 1, and it finishes at time 1. So it exceeds its deadline by 0.
Task 3 has a deadline 4, and it finishes at time 6. So it exceeds its deadline by 2.
Thus, the maximum time by which you overshoot a deadline is 2. No schedule can do better than this.
Similar calculation can be done for the case containing 5 tasks. | class Bit:
def __init__(self, size):
self.A = [(0) for i in range(size + 1)]
self.size = size
def __repr__(self):
return "Class %s (size %d)" % (self.__class__.__name__, self.size)
def __str__(self):
return str([self.A[i] for i in range(0, len(self.A))])
def sum(self, idx):
s = 0
while idx > 0:
s += self.A[idx]
idx -= idx & -idx
return s
def update(self, idx, value):
assert idx > 0
try:
while idx < len(self.A):
self.A[idx] += value
idx += idx & -idx
except IndexError:
print("ARGH: update: Idx = %d" % idx)
ntasks = int(input())
tasks_by_id = []
for i in range(ntasks):
d, w = [int(x) for x in input().split()]
t = i + 1, d, w
tasks_by_id.append(t)
tasks_by_deadline = sorted(tasks_by_id, key=lambda x: x[1])
bitree = Bit(ntasks)
id2dl = [(-1) for i in range(ntasks + 1)]
for i, t in enumerate(tasks_by_deadline):
id2dl[t[0]] = i
idl = lambda t: id2dl[t[0]]
L = []
max_delay = 0
for i, t in enumerate(tasks_by_id):
mybitindex = idl(t) + 1
bitree.update(mybitindex, t[2])
if False:
for j in range(0, i + 1):
bitindex = id2dl[j + 1] + 1
if bitindex < mybitindex:
continue
deadline = tasks_by_id[j][1]
ex_complete = bitree.sum(bitindex)
delta = max(0, ex_complete - deadline)
if delta > max_delay:
max_delay = delta
else:
deadline = tasks_by_id[i][1]
ex_complete = bitree.sum(mybitindex)
overshoot = ex_complete - deadline
for T in L:
id = T[0]
dlid = id2dl[id + 1]
bitindex = dlid + 1
if bitindex > mybitindex:
jdeadline = tasks_by_id[id][1]
jex_complete = bitree.sum(bitindex)
T[1] = jex_complete - jdeadline
L.sort(key=lambda x: x[1], reverse=True)
ins_ind = 0
for T in L:
if overshoot < T[1]:
ins_ind += 1
else:
break
L.insert(ins_ind, [i, overshoot])
d = tasks_by_id[L[0][0]][1]
o = L[0][1]
for j, T in enumerate(L):
if tasks_by_id[T[0]][1] < d and T[1] <= o:
del L[j]
print(max(0, L[0][1])) | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP STRING VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER |
You have a long list of tasks that you need to do today. To accomplish task $i$ you need $M_i$ minutes, and the deadline for this task is $D_i$. You need not complete a task at a stretch. You can complete a part of it, switch to another task, and then switch back.
You've realized that it might not be possible to complete all the tasks by their deadline. So you decide to do them in such a manner that the maximum amount by which a task's completion time overshoots its deadline is minimized.
Input Format
The first line contains the number of tasks, $\mathbf{T}$. Each of the next $\mathbf{T}$ lines contains two integers, $D_i$ and $M_i$.
Constraints
$1\leq T\leq10^5$
$1\leq D_i\leq10^5$
$1\leq M_i\leq10^3$
Output Format
Output $\mathbf{T}$ lines. The $i^{th}$ line contains the value of the maximum amount by which a task's completion time overshoots its deadline, when the first $i$ tasks on your list are scheduled optimally. See the sample input for clarification.
Sample Input
5
2 2
1 1
4 3
10 1
2 1
Sample Output
0
1
2
2
3
Explanation
The first task alone can be completed in 2 minutes, and so you won't overshoot the deadline.
With the first two tasks, the optimal schedule can be:
time 1: task 2
time 2: task 1
time 3: task 1
We've overshot task 1 by 1 minute, hence returning 1.
With the first three tasks, the optimal schedule can be:
time 1 : task 2
time 2 : task 1
time 3 : task 3
time 4 : task 1
time 5 : task 3
time 6 : task 3
Task 1 has a deadline 2, and it finishes at time 4. So it exceeds its deadline by 2.
Task 2 has a deadline 1, and it finishes at time 1. So it exceeds its deadline by 0.
Task 3 has a deadline 4, and it finishes at time 6. So it exceeds its deadline by 2.
Thus, the maximum time by which you overshoot a deadline is 2. No schedule can do better than this.
Similar calculation can be done for the case containing 5 tasks. | def update_tree(id, l, r, u, v, val):
if v < l or u > r:
return
if u <= l and r <= v:
tree[id][0] += val
tree[id][1] += val
return
mid = (l + r) // 2
tree[id * 2][0] += tree[id][1]
tree[id * 2][1] += tree[id][1]
tree[id * 2 + 1][0] += tree[id][1]
tree[id * 2 + 1][1] += tree[id][1]
tree[id][1] = 0
update_tree(id * 2, l, mid, u, v, val)
update_tree(id * 2 + 1, mid + 1, r, u, v, val)
tree[id][0] = max(tree[id * 2][0], tree[id * 2 + 1][0])
def get(id, l, r, u, v):
if v < l or u > r:
return -1
if u <= l and r <= v:
return tree[id][0]
mid = (l + r) // 2
tree[id * 2][0] += tree[id][1]
tree[id * 2][1] += tree[id][1]
tree[id * 2 + 1][0] += tree[id][1]
tree[id * 2 + 1][1] += tree[id][1]
tree[id][1] = 0
return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v))
n = int(input())
tasks = []
rank = [0] * n
used = [(0) for i in range(n)]
tree = []
for i in range(4 * n):
tree.append([0, 0])
for i in range(n):
s = input().split(" ")
tasks.append([i, int(s[0]), int(s[1])])
tasks.sort(key=lambda pair: pair[1])
for i in range(n):
rank[tasks[i][0]] = i
tasks.sort(key=lambda pair: pair[0])
for i in range(n):
update_tree(1, 0, n - 1, rank[i], rank[i], -tasks[i][1])
for i in range(n):
update_tree(1, 0, n - 1, rank[i], n - 1, tasks[i][2])
print(max(get(1, 0, n - 1, 0, n - 1), 0)) | FUNC_DEF IF VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR VAR RETURN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | def sc(i, j, k):
xx = 0
for t in range(5):
xx += (m[i][t] - m[j][t]) * (m[i][t] - m[k][t])
return xx
n = int(input())
m = []
mm = n
ans = []
if n > 36:
print("0")
else:
for i in range(n):
ans.append(1)
a, b, c, d, e = map(int, input().split())
m.append([a, b, c, d, e])
for i in range(n):
for j in range(n):
if i != j:
for k in range(n):
if i != k and j != k:
if sc(i, j, k) > 0:
ans[i] = -1
for i in range(n):
if ans[i] == -1:
mm += -1
print(mm)
for i in range(n):
if ans[i] == 1:
print(i + 1) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | def check(a, b, c):
s = 0
for i in range(5):
s += (b[i] - a[i]) * (c[i] - a[i])
return s <= 0
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
if n == 1 or n == 2:
print(n)
print(1)
if n == 2:
print(2)
exit()
v = -1
i = 0
while i + 1 < n:
if v == -1:
if i + 2 < n:
if check(a[i], a[i + 1], a[i + 2]):
v = i
elif check(a[i + 1], a[i], a[i + 2]):
v = i + 1
elif check(a[i + 2], a[i], a[i + 1]):
v = i + 2
else:
break
elif not check(a[v], a[i], a[i + 1]):
if check(a[i], a[v], a[i + 1]):
v = i
elif check(a[i + 1], a[v], a[i]):
v = i + 1
else:
v = -1
i += 1
if v == -1:
print(0)
exit()
for i in range(n):
if i == v:
continue
for j in range(i + 1, n):
if j == v:
continue
if not check(a[v], a[i], a[j]):
print(0)
exit()
print(1)
print(v + 1)
exit() | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF VAR NUMBER IF BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
p = [tuple(map(int, input().split())) for i in range(n)]
def d(a, b):
return tuple(x - y for x, y in zip(a, b))
def m(a, b):
return sum(x * y for x, y in zip(a, b))
good_points = []
for i in range(n):
good = True
for j in range(n):
if j == i:
continue
ab = d(p[j], p[i])
for k in range(j + 1, n):
if k == i:
continue
ac = d(p[k], p[i])
if m(ab, ac) > 0:
good = False
break
if not good:
break
if good:
good_points.append(i)
print(len(good_points))
for i in good_points:
print(i + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
p = [tuple(map(int, input().split())) for i in range(n)]
def d(a, b):
return a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3], a[4] - b[4]
def m(a, b):
t = 0
for i in range(5):
t += a[i] * b[i]
return t
good_points = []
for i in range(n):
good = True
for j in range(n):
if j == i:
continue
ab = d(p[j], p[i])
for k in range(j + 1, n):
if k == i:
continue
ac = d(p[k], p[i])
if m(ab, ac) > 0:
good = False
break
if not good:
break
if good:
good_points.append(i)
print(len(good_points))
for i in good_points:
print(i + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
A = []
js = 0
B = []
for i in range(n):
A.append(list(map(int, input().split())))
def product(a, b, c):
pr = 0
for m in range(5):
pr = pr + (A[b][m] - A[a][m]) * (A[c][m] - A[a][m])
return pr
if n > 11:
print(0)
else:
for j in range(n):
k = 0
l = 0
flag = 0
while k < n:
l = k + 1
while l < n:
pro = product(j, k, l)
if l != j and k != j and pro > 0:
flag = 1
break
else:
l = l + 1
if flag == 1:
break
else:
k = k + 1
if k == n:
js = js + 1
B.append(j + 1)
print(js)
for f in range(js):
print(B[f]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | def sc(x, y):
return x[0] * y[0] + x[1] * y[1] + x[2] * y[2] + x[3] * y[3] + x[4] * y[4]
def check(a, b, c):
if (
sc(
[b[0] - a[0], b[1] - a[1], b[2] - a[2], b[3] - a[3], b[4] - a[4]],
[c[0] - a[0], c[1] - a[1], c[2] - a[2], c[3] - a[3], c[4] - a[4]],
)
> 0
):
return True
return False
n = int(input())
data = []
for i in range(n):
a = list(map(int, input().split()))
data.append(a)
an = 0
t = False
ann = []
for i in range(n):
for j in range(n):
if i == j:
continue
for k in range(n):
if k == i or k == j:
continue
if check(data[i], data[j], data[k]):
an += 1
t = True
break
if t:
break
if not t:
ann.append(i + 1)
t = False
print(n - an)
print(*ann) | FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
p = []
ans = []
for _ in range(n):
p.append(list(map(int, input().split())))
if n > 100:
print(0)
exit(0)
for i in range(0, n):
good = True
for j in range(0, n):
for k in range(j + 1, n):
if i == j or i == k:
continue
dp = 0
for l in range(5):
dp += (p[j][l] - p[i][l]) * (p[k][l] - p[i][l])
if dp > 0:
good = False
if good:
ans.append(i)
print(len(ans))
out = ""
for e in ans:
out += str(e + 1) + " "
print(out) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
points = []
for p in range(n):
points.append(list(map(int, input().split())))
def dot(x, y):
res = 0
for a, b in zip(x, y):
res += a * b
return res
def minus(x, y):
res = []
for a, b in zip(x, y):
res.append(a - b)
return res
indices = set(range(n))
if n <= 50:
for x in range(n):
for y in range(n):
if x != y:
for z in range(n):
if z != y and z != x:
if (
dot(
minus(points[y], points[x]), minus(points[z], points[x])
)
> 0
):
indices.discard(x)
print(len(indices))
for i in sorted(indices):
print(i + 1)
else:
print(0) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
p = []
answer = []
for j in range(n):
p.append(list(map(int, input().split())))
def g(i):
for j in range(n):
for k in range(j + 1, n):
if i == j or i == k:
continue
if sum((p[j][l] - p[i][l]) * (p[k][l] - p[i][l]) for l in range(5)) > 0:
return
answer.append(i + 1)
for i in range(n):
g(i)
print(len(answer))
print(*answer) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | from itertools import chain, combinations
n = int(input())
if n > 11:
for _ in range(n):
input()
print(0)
else:
L = [tuple(map(int, input().split())) for _ in range(n)]
good = [True] * n
from itertools import chain, combinations
dot = lambda i, j: sum(L[i][k] * L[j][k] for k in range(5))
memo = [[dot(i, j) for j in range(n)] for i in range(n)]
for i in range(n):
c2 = memo[i][i]
for j, k in combinations(chain(range(i), range(i + 1, n)), r=2):
if memo[j][k] > memo[j][i] + memo[k][i] - c2:
good[i] = False
break
print(sum(good))
print(" ".join(map(str, (i + 1 for i, v in enumerate(good) if v)))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n, p, ans = int(input()), [], []
if n > 123:
print(0), exit(0)
for _ in range(n):
p.append(list(map(int, input().split())))
for i in range(0, n):
good = True
for j in range(0, n):
for k in range(j + 1, n):
good &= (
sum((p[j][l] - p[i][l]) * (p[k][l] - p[i][l]) for l in range(5)) <= 0
)
if good:
ans.append(1 + i)
print(len(ans))
print(*ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | from sys import exit
n = int(input())
P = []
if n >= 38:
print("0")
exit()
for i in range(n):
tmp = input().split()
tmp = [int(k) for k in tmp]
P.append(tuple(tmp))
isGood = [(True) for i in range(n)]
for i in range(n):
for j in range(n):
for k in range(j):
dp = 0
for d in range(5):
dp += (P[j][d] - P[i][d]) * (P[k][d] - P[i][d])
if dp > 0:
isGood[i] = False
print(isGood.count(True))
for i in range(n):
if isGood[i]:
print(i + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
points = []
for _ in range(n):
tmp = list(map(int, input().split()))
points.append(tmp)
ans = []
for i in range(n):
point_i = points[i]
for j in range(n):
if j == i:
continue
point_j = points[j]
k_break = False
vector_ij = [(point_j[idx] - point_i[idx]) for idx in range(5)]
for k in range(j + 1, n):
if k == i:
continue
point_k = points[k]
vector_ik = [(point_k[idx] - point_i[idx]) for idx in range(5)]
inner_product = 0
num_i_mo = 0
num_j_mo = 0
for idx in range(5):
inner_product += vector_ij[idx] * vector_ik[idx]
if inner_product > 0:
k_break = True
break
if k_break:
break
else:
ans.append(point_i)
if len(points) <= 2:
print(len(points))
for i in range(len(points)):
print(i + 1)
else:
print(len(ans))
for single in ans:
print(points.index(single) + 1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
a = []
used = [(0) for i in range(n)]
def judge(s1, s2, s3):
sum = 0
for i in range(5):
sum += (a[s1][i] - a[s3][i]) * (a[s2][i] - a[s3][i])
if sum <= 0:
return 1
else:
return 0
for i in range(n):
b = [int(x) for x in input().split(" ")]
a.append(b)
if n <= 100:
num = 0
flag = 0
for i in range(n):
flag = 0
for j in range(n):
if i == j:
continue
for k in range(j + 1, n):
if judge(k, j, i) == 0:
flag = 1
if flag == 0:
used[i] = 1
num += 1
print(num, "\n")
for i in range(n):
if used[i] == 1:
print(i + 1, " ")
else:
print("0") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | d = lambda i, j, k: sum((a - c) * (b - c) for a, b, c in zip(p[i], p[j], p[k])) * (
i != j
)
n = int(input())
r = range(n)
p = [list(map(int, input().split())) for i in r]
t = [(k + 1) for k in r if all(d(i, j, k) <= 0 for i in r for j in r)] if n < 12 else []
for q in [len(t)] + t:
print(q) | ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR LIST FOR VAR BIN_OP LIST FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | def check(coor1, coor2, coor3):
v1 = [(coor2[i] - coor1[i]) for i in range(5)]
v2 = [(coor3[i] - coor1[i]) for i in range(5)]
return scalar_product(v1, v2)
def scalar_product(coor1, coor2):
a1, a2, a3, a4, a5 = coor1
b1, b2, b3, b4, b5 = coor2
return a1 * b1 + a2 * b2 + a3 * b3 + a4 * b4 + a5 * b5
n = int(input())
idx___coor = []
for idx in range(n):
coor = [int(x) for x in input().split()]
idx___coor.append(coor)
if n > 129:
print(0)
else:
good_idxes = []
for idx1, coor1 in enumerate(idx___coor):
is_ok_flag = True
for idx2, coor2 in enumerate(idx___coor):
for idx3, coor3 in enumerate(idx___coor):
if idx2 == idx3 or idx1 == idx3 or idx1 == idx2 or not is_ok_flag:
continue
if check(coor1, coor2, coor3) > 0:
is_ok_flag = False
if is_ok_flag:
good_idxes.append(idx1)
good_idxes = sorted(good_idxes)
good_idxes = [(x + 1) for x in good_idxes]
print(len(good_idxes))
print(*good_idxes) | FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | def ip(x, y):
return sum([(a * b) for a, b in zip(x, y)])
def dif(a, b):
return [(b - a) for a, b in zip(a, b)]
def calcAng(a, b, c):
return ip(dif(a, b), dif(a, c))
def testCase(pts):
n = len(pts)
if n > 35:
return []
ans = []
for i in range(n):
acs = 0
for j in range(n):
for k in range(n):
if i == j or j == k or i == k:
continue
if calcAng(pts[i], pts[j], pts[k]) > 0:
acs += 1
if acs == 0:
ans.append(i)
return ans
def main():
n = int(input())
pts = []
for i in range(n):
pts.append([int(x) for x in input().split()])
ans = testCase(pts)
print(len(ans))
for x in ans:
print(x + 1)
main() | FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | def vec(c0, a, b):
an = 0
for i in range(5):
an += (a[i] - c0[i]) * (b[i] - c0[i])
return an
n = int(input())
if n > 80:
print(0)
exit(0)
a = [([0] * 5) for i in range(n)]
for i in range(n):
a[i] = [int(j) for j in input().split()]
ans = []
for i in range(n):
flag = True
for j in range(n):
for k in range(n):
if i != j and j != k and k != i and vec(a[i], a[j], a[k]) > 0:
flag = False
if flag:
ans.append(i)
print(len(ans))
for i in ans:
print(i + 1) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
points = []
for i in range(n):
pt = list(map(int, input().split()))
points.append(pt)
flag = [1] * n
for i in range(n):
a = points[i]
ok = False
for j in range(n):
if ok:
break
if j == i:
continue
b = points[j]
for k in range(n):
if k == i or k == j:
continue
c = points[k]
summ = 0
for z in range(5):
u = b[z] - a[z]
v = c[z] - a[z]
summ += u * v
if summ > 0:
flag[i] = 0
ok = True
break
res = []
for i in range(n):
if flag[i]:
res.append(i + 1)
print(len(res))
for i in range(len(res)):
print(res[i]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
dots = []
for i in range(n):
dots.append(list(map(int, input().split())))
good_dots = []
for a_index in range(n):
a_dot = dots[a_index]
a_is_good = True
for b_index in range(n):
for c_index in range(n):
if a_index != b_index and a_index != c_index and b_index < c_index:
b_dot = dots[b_index]
c_dot = dots[c_index]
ab_vec = [(b_coord - a_coord) for a_coord, b_coord in zip(a_dot, b_dot)]
ac_vec = [(c_coord - a_coord) for a_coord, c_coord in zip(a_dot, c_dot)]
prod = sum([(a * b) for a, b in zip(ab_vec, ac_vec)])
if prod > 0:
a_is_good = False
break
if not a_is_good:
break
if a_is_good:
good_dots.append(a_index + 1)
print(len(good_dots))
for dot in good_dots:
print(dot) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
if n > 20:
print(0)
else:
s = []
for i in range(n):
s.append([int(i) for i in input().split()])
p = []
for i in range(n):
p.append(0)
for j in range(n):
for l in range(j):
b = 0
for k in range(5):
b += (s[i][k] - s[j][k]) * (s[i][k] - s[l][k])
if b > 0:
p[-1] += 1
u = 0
ans = []
for i in range(n):
if p[i] == 0:
u += 1
ans.append(i + 1)
print(u)
for i in ans:
print(i) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors $\vec{ab}$ and $\vec{ac}$ is acute (i.e. strictly less than $90^{\circ}$). Otherwise, the point is called good.
The angle between vectors $\vec{x}$ and $\vec{y}$ in 5-dimensional space is defined as $\operatorname{arccos}(\frac{\vec{x} \cdot \vec{y}}{|\vec{x}||\vec{y}|})$, where $\vec{x} \cdot \vec{y} = x_{1} y_{1} + x_{2} y_{2} + x_{3} y_{3} + x_{4} y_{4} + x_{5} y_{5}$ is the scalar product and $|\vec{x}|= \sqrt{\vec{x} \cdot \vec{x}}$ is length of $\vec{x}$.
Given the list of points, print the indices of the good points in ascending order.
-----Input-----
The first line of input contains a single integer n (1 ≤ n ≤ 10^3) — the number of points.
The next n lines of input contain five integers a_{i}, b_{i}, c_{i}, d_{i}, e_{i} (|a_{i}|, |b_{i}|, |c_{i}|, |d_{i}|, |e_{i}| ≤ 10^3) — the coordinates of the i-th point. All points are distinct.
-----Output-----
First, print a single integer k — the number of good points.
Then, print k integers, each on their own line — the indices of the good points in ascending order.
-----Examples-----
Input
6
0 0 0 0 0
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Output
1
1
Input
3
0 0 1 2 0
0 0 9 2 0
0 0 5 9 0
Output
0
-----Note-----
In the first sample, the first point forms exactly a $90^{\circ}$ angle with all other pairs of points, so it is good.
In the second sample, along the cd plane, we can see the points look as follows:
[Image]
We can see that all angles here are acute, so no points are good. | n = int(input())
points = [[-1, -1, -1, -1, -1]]
for _ in range(n):
pts = list(map(int, input().split()))
points.append(pts)
def check(i, j, k):
res = 0
for t in range(5):
a = points[j][t] - points[i][t]
b = points[k][t] - points[i][t]
res += a * b
return res > 0
res = []
for i in range(1, n + 1):
valid = True
for j in range(1, n + 1):
if j != i and valid:
for k in range(1, n + 1):
if j != k:
if check(i, j, k):
valid = False
break
if not valid:
break
if valid:
res.append(i)
print(len(res))
print(*res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | from sys import stdin, stdout
k, n = map(int, stdin.readline().split())
marks = list(map(int, stdin.readline().split()))
values = list(map(int, stdin.readline().split()))
cnt = [marks[0]]
for i in range(1, k):
cnt.append(cnt[-1] + marks[i])
cnt.sort()
values.sort()
ans = set()
for i in range(k - n + 1):
x = values[0] - cnt[i]
pos = 1
ind = i + 1
label = 1
while pos < n and ind < k:
if cnt[ind] + x < values[pos]:
ind += 1
elif cnt[ind] + x == values[pos]:
ind += 1
pos += 1
else:
label = 0
break
if label and pos == n:
ans.add(x)
stdout.write(str(len(ans))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | import itertools
n, m = (int(x) for x in input().split())
marks = (int(x) for x in input().split())
scores = sorted(int(x) for x in input().split())
marks = sorted(itertools.accumulate(marks))
ans = set()
for i in range(n):
mark0 = marks[i]
score0 = scores[0]
score_it = iter(scores[1:])
score = next(score_it, None)
for mark in marks[i + 1 :]:
if score is None:
break
if mark - mark0 == score - score0:
score = next(score_it, None)
if score is None:
ans.add(score0 - mark0)
print(len(ans)) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NONE FOR VAR VAR BIN_OP VAR NUMBER IF VAR NONE IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NONE IF VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | f = lambda: list(map(int, input().split(" ")))
k, n = f()
a, b = f(), f()
all = []
for m in b:
al = set()
for s in a:
m -= s
al.add(m)
all += [al]
p = set.intersection(*all)
print(len(p)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | n, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, n):
A[i] += A[i - 1]
pos = []
for i in A:
pos.append(B[0] - i)
pos = set(pos)
cnt = 0
b = set(B)
for p in pos:
s = set()
for u in A:
s.add(u + p)
if s.intersection(b) == b:
cnt += 1
print(cnt) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | s = input().split(" ")
k = int(s[0])
n = int(s[1])
arr = []
sum_arr = []
s = input().split(" ")
for i in range(k):
arr.append(int(s[i]))
sum_arr.append(arr[-1])
if i >= 1:
sum_arr[i] += sum_arr[i - 1]
arr_2 = []
s = input().split(" ")
for i in range(n):
arr_2.append(int(s[i]))
possible_intial = set()
for i in sum_arr:
possible_intial.add(arr_2[0] - i)
arr_2 = set(arr_2)
ctr = 0
for i in possible_intial:
after_values = set()
for j in sum_arr:
after_values.add(i + j)
flag = 0
for j in arr_2:
if j not in after_values:
flag = 1
break
if flag == 0:
ctr += 1
print(ctr) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | def init():
inp = input().split()
k = int(inp[0])
n = int(inp[1])
va = [int(i) for i in input().split()]
vb = [int(i) for i in input().split()]
return va, vb
def pross(va, vb):
acc = 0
for i, a in enumerate(va):
acc += a
va[i] = acc
vals = [set() for _ in range(len(vb))]
for i, b in enumerate(vb):
for a in va:
vals[i].add(b - a)
return vals
def solve(vals):
ans = set()
for i, v in enumerate(vals[0]):
for s in vals[1:]:
if v not in s:
break
else:
ans.add(v)
return len(ans)
print(solve(pross(*init()))) | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | from sys import stdin, stdout
def rint():
return list(map(int, stdin.readline().split()))
k, n = rint()
a = list(rint())
b = list(rint())
for i in range(1, k):
a[i] = a[i] + a[i - 1]
a0 = min(a)
for i in range(len(a)):
a[i] -= a0
a = set(a)
b0 = min(b)
for i in range(n):
b[i] -= b0
ans = 0
for aa in a:
diff = aa
ans += 1
for bb in b:
if bb + diff in a:
pass
else:
ans -= 1
break
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | import sys
def main():
k, n = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
for i in range(1, k):
a[i] = a[i - 1] + a[i]
c = set()
for i in range(k):
x = b[0] - a[i]
u = {}
for j in range(k):
u[x + a[j]] = True
flag = True
for j in range(n):
if b[j] not in u:
flag = False
break
if flag:
c.add(x)
print(len(c))
main() | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | f = lambda: list(map(int, input().split()))
k, n = f()
a, b = f(), f()
for i in range(k - 1):
a[i + 1] += a[i]
t = []
for x in b:
t.append(set(x - y for y in a))
print(len(set.intersection(*t))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | n, m = map(int, input().split())
arr = [int(x) for x in input().split()]
dist = [int(x) for x in input().split()]
for i in range(1, n):
arr[i] = arr[i] + arr[i - 1]
lis = []
for i in range(m):
val = dist[i]
s = set()
for j in range(n):
s.add(val - arr[j])
lis.append(s)
print(len(set.intersection(*lis))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | from itertools import accumulate
k, n = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
suma = list(accumulate(a))
def possible(s):
target = set(b)
for i in a:
s += i
if s in target:
target.remove(s)
return not target
pos = set()
for i in range(k):
ini = b[0] - suma[i]
if possible(ini):
pos.add(ini)
print(len(pos)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave a_{i} points.
Polycarp does not remember how many points the participant had before this k marks were given, but he remembers that among the scores announced after each of the k judges rated the participant there were n (n ≤ k) values b_1, b_2, ..., b_{n} (it is guaranteed that all values b_{j} are distinct). It is possible that Polycarp remembers not all of the scores announced, i. e. n < k. Note that the initial score wasn't announced.
Your task is to determine the number of options for the score the participant could have before the judges rated the participant.
-----Input-----
The first line contains two integers k and n (1 ≤ n ≤ k ≤ 2 000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains k integers a_1, a_2, ..., a_{k} ( - 2 000 ≤ a_{i} ≤ 2 000) — jury's marks in chronological order.
The third line contains n distinct integers b_1, b_2, ..., b_{n} ( - 4 000 000 ≤ b_{j} ≤ 4 000 000) — the values of points Polycarp remembers. Note that these values are not necessarily given in chronological order.
-----Output-----
Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes).
-----Examples-----
Input
4 1
-5 5 0 20
10
Output
3
Input
2 2
-2000 -2000
3998000 4000000
Output
1
-----Note-----
The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | k, n = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
S = [0] * k
for i in range(k):
if i == 0:
S[0] = A[0]
else:
S[i] = S[i - 1] + A[i]
S.sort()
B.sort()
ans = set()
for i, s in enumerate(S):
if i > 0 and S[i - 1] == s:
continue
t = B[0] - s
if n > 1:
j = i + 1
flag = False
for m, u in enumerate(B[1:]):
while j < len(S):
if u - S[j] == t:
if m == n - 2:
flag = True
j += 1
break
else:
j += 1
if flag == True:
ans.add(t)
else:
ans.add(t)
print(len(ans)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.