description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
a, ans = [], 0
for i in range(n):
x1, y1 = map(int, input().split())
a.append([x1, y1])
for i in range(n):
if a[i] != "burp":
ans += 1
for j in range(n):
if (
a[j] != "burp"
and i != j
and (a[i][0] - x0) * (a[j][1] - y0) == (a[j][0] - x0) * (a[i][1] - y0)
):
a[j] = "burp"
a[i] = "burp"
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER 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 IF VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = input().split()
n = int(n)
x0 = int(x0)
y0 = int(y0)
x = []
y = []
slope = []
for i in range(n):
p, q = input().split()
x.append(int(p))
y.append(int(q))
for i in range(n):
if x[i] == x0:
slope.append(1000000000)
continue
m = (y[i] - y0) / (x[i] - x0)
slope.append(m)
print(len(set(slope))) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
stormtroopers = [list(map(int, input().split())) for _ in range(n)]
diff = [(x - x0, y - y0) for x, y in stormtroopers]
diff_set = set()
for x, y in diff:
try:
tmp = x / y
diff_set.add(tmp)
except ZeroDivisionError:
diff_set.add("ZERO")
print(len(diff_set)) | 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 VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
coords = [0] * n
lasers = 0
points = 0
slopes = []
for i in range(n):
coords[i] = list(map(int, input().split()))
for i in range(n):
if coords[i][0] == x0:
if "x" not in slopes:
slopes.append("x")
elif (y0 - coords[i][1]) / (x0 - coords[i][0]) not in slopes:
slopes.append((y0 - coords[i][1]) / (x0 - coords[i][0]))
print(len(slopes)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF STRING VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
xy = []
f = 0
for i in range(n):
x, y = map(int, input().split())
xy.append((x, y))
cnt = i = 0
loop = 0
while cnt < n:
if xy[i] == -1:
i += 1
continue
loop += 1
for j in range(n):
if xy[j] == -1 or i == j:
continue
if (xy[j][1] - y0) * (xy[i][0] - x0) == (xy[j][0] - x0) * (xy[i][1] - y0):
xy[j] = -1
cnt += 1
xy[i] = -1
cnt += 1
i += 1
print(loop) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
b = []
for i in range(n):
a, d = map(int, input().split())
if a - x == 0:
b.append(90.00012333345666)
else:
m = (d - y) / (a - x)
b.append(m)
b.sort()
z = []
z.append(b[0])
for i in range(n - 1):
if b[i] != b[i + 1]:
z.append(b[i + 1])
print(len(z)) | ASSIGN VAR 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 IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
a = []
for i in range(n):
b, c = map(int, input().split())
a.append([b, c])
l = []
inf = 100000
for i in range(len(a)):
if a[i][0] == x:
l.append(inf)
else:
l.append((a[i][1] - y) / (a[i][0] - x))
l = list(set(l))
co = []
for i in range(len(l)):
co.append(l.count(l[i]))
print(sum(co) - max(co) + 1) | ASSIGN VAR 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 VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
n, x, y = map(int, input().split())
d = {}
for q in range(n):
u, v = map(int, input().split())
j = "00"
if u - x != 0:
if v - y == 0:
j = "0"
else:
s = ""
if (u - x) * (v - y) < 0:
s = "-"
else:
s = ""
h = gcd(abs(v - y), abs(u - x))
j = s + str(abs(v - y) // h) + "k" + str(abs(u - x) // h)
if j in d.keys():
d[j] += 1
else:
d[j] = 1
j = 0
for q in d.keys():
j += 1
print(j) | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | q, x, y = map(int, input().split())
d = {}
m = 1
for _ in range(q):
xt, yt = map(int, input().split())
if x == xt:
if 9000000000000000000 in d:
d[9000000000000000000] += 1
else:
d[9000000000000000000] = 1
else:
c = (yt - y) / (xt - x)
if c in d:
d[c] = d[c] + 1
if d[c] > m:
m = d[c]
else:
d[c] = 1
print(len(d)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def slope(x1, y1, x2, y2):
denom = x2 - x1
return (y2 - y1) / denom if denom != 0 else "indefinido"
def minShotsRequired(x0, x1, n, stormtroopers):
slopes = {}
different = 0
for i in range(n):
m = slope(x0, y0, stormtroopers[i][0], stormtroopers[i][1])
if not slopes.get(m):
slopes[m] = True
different += 1
return different
n, x0, y0 = [int(x) for x in input().split()]
stormtroopers = []
for i in range(n):
tmp = [int(x) for x in input().split()]
stormtroopers.append((tmp[0], tmp[1]))
print(minShotsRequired(x0, y0, n, stormtroopers)) | FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN VAR NUMBER BIN_OP BIN_OP VAR VAR VAR STRING FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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 NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
x, y = [], []
for i in range(n):
xi, yi = map(int, input().split())
x.append(xi)
y.append(yi)
slope = []
for i in range(n):
if x[i] == x0:
slope.append("Inf")
else:
k = (y[i] - y0) / (x[i] - x0)
slope.append(k)
ans = list(set(slope))
print(len(ans)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
k = [([None] * 2) for i in range(n)]
for i in range(n):
k[i][0], k[i][1] = map(int, input().split())
s = 0
used = [0] * n
for i in range(n):
f = 0
x = k[i][0]
y = k[i][1]
koef1 = y0 - y
koef2 = x - x0
koef3 = x0 * y - x * y0
if not used[i]:
f = 1
used[i] = 1
for j in range(n):
if not used[j]:
if koef1 * k[j][0] + koef2 * k[j][1] + koef3 == 0:
used[j] = 1
s += f
print(s) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x_0, y_0 = map(int, input().split())
arr = []
for i in range(n):
a = list(map(int, input().split()))[:2]
arr.append(a)
def tangent(x_0, y_0, p1, p2):
return float((y_0 - p2) / (x_0 - p1))
arr1 = []
for i in range(n):
if arr[i][0] == x_0:
arr1.append(-1e-07)
continue
for j in range(2):
a = tangent(x_0, y_0, arr[i][0], arr[i][1])
arr1.append(a)
arr2 = []
for k in arr1:
if k not in arr2:
arr2.append(k)
if -1e-07 in arr2:
print(len(arr2))
else:
print(len(arr2)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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 NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, a, b = input().split()
n, a, b = int(n), int(a), int(b)
ans = 0
l = []
for i in range(n):
x, y = input().split()
x, y = int(x), int(y)
if x == a:
l.append(1000000000.0)
elif (y - b) / (x - a) not in l:
ans += 1
l.append((y - b) / (x - a))
print(ans + int(1000000000.0 in l)) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | import sys
def solve(startingCoor, coorSet):
numTries = 0
while len(coorSet) != 0:
coor = coorSet[0]
coorSet.remove(coor)
m = []
isVert = False
if startingCoor[0] != coor[0]:
m = [coor[0] - startingCoor[0], coor[1] - startingCoor[1]]
else:
isVert = True
numTries += 1
i = 0
while i < len(coorSet):
coorOther = coorSet[i]
if not isVert:
if m[0] * (coorOther[1] - startingCoor[1]) == m[1] * (
coorOther[0] - startingCoor[0]
):
coorSet.remove(coorOther)
i -= 1
elif coorOther[0] - startingCoor[0] == 0:
coorSet.remove(coorOther)
i -= 1
i += 1
return numTries
infoNum = [int(x) for x in sys.stdin.readline().split()]
numLines = infoNum[0]
startingCoor = infoNum[1], infoNum[2]
coorSet = []
for i in range(numLines):
nextCoor = [int(x) for x in sys.stdin.readline().split()]
coorSet.append((nextCoor[0], nextCoor[1]))
print(solve(startingCoor, coorSet)) | IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER 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 NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def main():
n, x0, y0 = map(int, input().split())
s = []
for i in range(n):
s.append(list(map(int, input().split())))
tan = []
k = 0
for i in range(n):
s[i][0] -= x0
s[i][1] -= y0
if s[i][0] == 0:
k += 1
elif s[i][1] / s[i][0] not in tan:
tan.append(s[i][1] / s[i][0])
if k:
k = 1
print(k + len(tan))
main() | FUNC_DEF ASSIGN VAR 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 LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR IF VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | a, b, c = input().strip().split(" ")
a, b, c = [int(a), int(b), int(c)]
x1 = []
for i in range(a):
x, y = input().strip().split(" ")
x, y = [int(x), int(y)]
f = y - c
f1 = x - b
if f1 == 0:
x1.append("a")
else:
x1.append(f / f1)
ans = len(list(set(x1)))
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def solo_mid(n, x0, y0, sturms=[]):
if n == 0:
return 0
res = {}
for i in range(n):
for_shot = sturms[:]
first_sturm = for_shot[0]
sturms.remove(first_sturm)
line_x = y0 - first_sturm[1]
line_y = -(x0 - first_sturm[0])
line_c = -first_sturm[0] * line_x + first_sturm[1] * -line_y
res[first_sturm] = 1
for xi, yi in for_shot[1:]:
is_in_line = line_x * xi + line_y * yi + line_c
if is_in_line == 0:
res[first_sturm] += 1
sturms.remove((xi, yi))
if not sturms:
break
return len(res)
try:
first = input()
if len(first.split()) != 3:
print(0)
else:
in_f = [int(i) for i in first.split()]
n = in_f[0]
sturms = []
for i in range(n):
s = input()
if len(s.split()) != 2:
print(0)
break
else:
try:
s_l = tuple([int(i) for i in s.split()])
except:
break
sturms.append(s_l)
else:
print(solo_mid(n, in_f[1], in_f[2], sturms))
except:
print(0) | FUNC_DEF LIST IF VAR NUMBER RETURN NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | a = input("").split(" ")
troopers = []
for val in range(int(a[0])):
troopers.append(input("").split(" "))
trooperSlopes = []
for x in troopers:
if int(x[0]) - int(a[1]) == 0:
trooperSlopes.append("asd")
else:
trooperSlopes.append((int(x[1]) - int(a[2])) / (int(x[0]) - int(a[1])))
print(len(set(trooperSlopes))) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, xo, yo = map(int, input().split())
p = []
ans = 0
for i in range(n):
p.append(list(map(int, input().split())))
while p:
i = p.pop()
ans += 1
k = 0
while p and k < len(p):
j = p[k]
if (j[1] - yo) * (i[0] - xo) - (i[1] - yo) * (j[0] - xo) == 0:
p.remove(j)
else:
k += 1
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
vis = [0] * n
co_ords = []
for i in range(n):
co_ords.append(list(map(int, input().split())))
ans = 0
for i in range(n):
if vis[i] == 0:
vis[i] = 1
ans += 1
c1x = co_ords[i][0]
c1y = co_ords[i][1]
for j in range(i + 1, n):
if vis[j]:
continue
c2x = co_ords[j][0]
c2y = co_ords[j][1]
if c2y - y == 0 and c1y - y == 0:
vis[j] += 1
elif c2y == y or c1y == y:
continue
elif (c2x - x) / (c2y - y) == (c1x - x) / (c1y - y):
vis[j] += 1
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | info = input().split()
info = [int(e) for e in info]
target_shib = set([])
for i in range(info[0]):
temp = input()
if int(temp.split()[0]) - int(info[1]) != 0:
target_shib.add(
(int(temp.split()[1]) - int(info[2]))
/ (int(temp.split()[0]) - int(info[1]))
)
else:
target_shib.add("INF")
print(len(target_shib)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | s = input()
n, x0, y0 = [int(x) for x in s.split()]
st = set([])
def gcd(a, b):
if not b:
return a
return gcd(b, a % b)
flag = False
for i in range(n):
s = input()
x, y = [int(t) for t in s.split()]
x, y = x - x0, y - y0
if x < 0:
x *= -1
y *= -1
if not x:
x, y = 0, 1
elif not y:
x, y = 1, 0
else:
d = gcd(x, abs(y))
x /= d
y /= d
st.add((x, y))
if len(st) == 0:
st.add((0, 0))
print(len(st)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FUNC_DEF IF VAR RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def I():
return list(map(int, input().split()))
n, x0, y0 = I()
list_of_killed = []
x_flag = False
y_flag = False
for i in range(n):
x1, y1 = I()
x = x1 - x0
y = y1 - y0
if x != 0 and y != 0:
list_of_killed.append(y / x)
elif x == 0 and y != 0:
x_flag = True
else:
y_flag = True
if x_flag and y_flag:
print(len(list(dict.fromkeys(list_of_killed))) + 2)
elif x_flag or y_flag:
print(len(list(dict.fromkeys(list_of_killed))) + 1)
else:
print(len(list(dict.fromkeys(list_of_killed)))) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
def formsline(x1, y1, x2, y2, x3, y3):
if (x2 - x1) * (y3 - y1) == (x3 - x1) * (y2 - y1):
return True
return False
n, x0, y0 = rinput()
arr = []
alive = [1] * n
shots = 0
for _ in range(n):
x, y = rinput()
arr.append([x, y])
for i in range(n):
if alive[i]:
x, y = arr[i][0], arr[i][1]
alive[i] = 0
for j in range(n):
x1, y1 = arr[j][0], arr[j][1]
if alive[j] and formsline(x, y, x1, y1, x0, y0):
alive[j] = 0
shots += 1
print(shots) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
a = []
for i in range(n):
x1, y1 = map(int, input().split())
a.append((x1, y1))
d = set()
for p, q in a:
x2, y2 = p - x, q - y
found = False
for x1, y1 in d:
if x1 * y2 == x2 * y1:
found = True
break
if not found:
d.add((x2, y2))
print(len(d)) | ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | import sys
def get_slope(x0, y0, x1, y1):
if x0 == x1:
m = 99999
else:
m = (y1 - y0) / (x1 - x0)
return m
n, x0, y0 = map(int, input().split())
l = []
count = 0
for i in range(n):
x1, y1 = map(int, input().split())
l.append((x1, y1))
slope = set()
for i in range(len(l)):
m = get_slope(x0, y0, l[i][0], l[i][1])
if m not in slope:
slope.add(m)
count += 1
print(count) | IMPORT FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | num_coor = input().split()
num_storm = int(num_coor[0])
han_coor = [int(num_coor[1]), int(num_coor[2])]
l = []
for i in range(num_storm):
temp = tuple([int(h) for h in input().split()])
l.append(temp)
for f in range(len(l)):
temp = l[f]
if temp[0] == han_coor[0]:
l[f] = "banana"
else:
slope = (temp[1] - han_coor[1]) / (temp[0] - han_coor[0])
l[f] = float(slope)
num = set(l)
print(len(num)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = [int(x) for x in input().split()]
d = set()
ans = 0
for _ in range(n):
a, b = [int(x) for x in input().split()]
if x != a:
slope = (y - b) / (x - a)
if slope not in d:
d.add(slope)
ans += 1
elif "infinite" not in d:
d.add("infinite")
ans += 1
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
d = dict()
for _ in range(n):
x, y = map(int, input().split())
slope = 0
if x == x0:
slope = 100000000
else:
slope = (y - y0) / (x - x0)
if slope not in d:
d[slope] = 1
print(len(d)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def detect_colinearity(a, b, c):
try:
slope1 = (a[1] - b[1]) / (a[0] - b[0])
except ZeroDivisionError:
slope1 = "inf"
try:
slope2 = (a[1] - c[1]) / (a[0] - c[0])
except ZeroDivisionError:
slope2 = "inf"
return slope1 == slope2
metad = input().split()
n = int(metad[0])
x0 = int(metad[1])
y0 = int(metad[2])
soldiers = set()
for _ in range(n):
loc = input().split()
info = int(loc[0]) - x0, int(loc[1]) - y0
soldiers.add(info)
if len(soldiers) == 2:
try:
if detect_colinearity((0, 0), soldiers.pop(), soldiers.pop()):
print(1)
else:
print(2)
except:
print(1)
else:
shots = 0
while len(soldiers):
base = 0, 0
other = soldiers.pop()
temp = set(s for s in soldiers if not detect_colinearity(base, other, s))
soldiers = temp
shots += 1
print(shots) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR STRING RETURN VAR VAR 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 NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | slopes = set()
inf = 99999999999
n, x, y = map(int, input().split())
storm = []
for __ in range(n):
a, b = map(int, input().split())
storm.append((a, b))
def slopeComp(i, j):
if i[0] == j[0]:
return inf
return (i[1] - j[1]) / (i[0] - j[0])
for trooper in storm:
slopes.add(slopeComp(trooper, (x, y)))
print(len(slopes)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR 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 FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def gcd(x, y):
if x * y == 0:
return max(x, y)
elif x >= y:
return gcd(x % y, y)
else:
return gcd(x, y % x)
nxy = list(map(int, input().rstrip().split()))
n = nxy[0]
x0 = nxy[1]
y0 = nxy[2]
xaxis = []
yaxis = []
case1 = []
case2 = []
for i in range(n):
xy = list(map(int, input().rstrip().split()))
x = xy[0] - x0
y = xy[1] - y0
if x * y == 0:
if x == 0:
yaxis += [x, y]
else:
xaxis += [x, y]
elif x * y > 0:
if x > 0:
hcf = gcd(x, y)
xysimple = [x // hcf, y // hcf]
case1 += [xysimple]
else:
hcf = gcd(-1 * x, -1 * y)
xysimple = [x // hcf * -1, y // hcf * -1]
case1 += [xysimple]
elif x > 0:
hcf = gcd(x, -1 * y)
xysimple = [x // hcf, y // hcf]
case2 += [xysimple]
else:
hcf = gcd(-1 * x, y)
xysimple = [x // hcf * -1, y // hcf * -1]
case2 += [xysimple]
a = 0
if len(xaxis) > 0:
a = 1
b = 0
if len(yaxis) > 0:
b = 1
case1.sort()
a1 = len(case1)
if a1 == 0:
c = 0
else:
c = 1
for i in range(a1 - 1):
if case1[i] != case1[i + 1]:
c += 1
case2.sort()
a2 = len(case2)
if a2 == 0:
d = 0
else:
d = 1
for i in range(a2 - 1):
if case2[i] != case2[i + 1]:
d += 1
print(a + b + c + d) | FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR LIST VAR VAR VAR LIST VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR LIST VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR LIST VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = input().split()
n, x0, y0 = int(n), int(x0), int(y0)
lis = []
for i in range(n):
lis.append(input().split())
lis[i][0] = int(lis[i][0]) - x0
lis[i][1] = int(lis[i][1]) - y0
lis1 = []
for i in range(n):
if lis[i][0] == 0:
if "x" not in lis1:
lis1.append("x")
elif lis[i][1] / lis[i][0] not in lis1:
lis1.append(lis[i][1] / lis[i][0])
print(len(lis1)) | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def fun(x, y, stormtroopers):
shots = set([])
for coordenates in stormtroopers:
if coordenates[0] - x == 0:
slope = float("inf")
else:
slope = (coordenates[1] - y) / (coordenates[0] - x)
shots.add(slope)
print(len(shots))
n, x, y = [int(x) for x in input().split()]
stormtroopers = []
while len(stormtroopers) < n:
stormtroopers.append([int(z) for z in input().split()])
fun(x, y, stormtroopers) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
s = set()
while n != 0:
x, y = map(int, input().split())
try:
s.add((y - y0) / (x - x0))
except ZeroDivisionError:
s.add(9999999999)
n -= 1
print(len(s)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | a = input().split()
n = int(a[0])
x = int(a[1])
y = int(a[2])
l = []
t = []
for i in range(n):
m = []
p = input().split()
m.append(int(p[0]))
m.append(int(p[1]))
l.append(m)
for i in range(n):
if l[i][0] == x:
if 4444 not in t:
t.append(4444)
elif l[i][1] == y:
if 5555 not in t:
t.append(5555)
else:
sl = (y - l[i][1]) / (x - l[i][0])
if sl not in t:
t.append(sl)
print(len(t)) | 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 NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR IF NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | line = list(map(int, input().split()))
n = line[0]
x = line[1]
y = line[2]
coords = []
for i in range(n):
point = list(map(int, input().split()))
coords.append([point[0], point[1], False])
count = 0
for i in range(len(coords)):
if coords[i][2] == True:
continue
count += 1
x1 = coords[i][0]
y1 = coords[i][1]
for j in range(i + 1, len(coords)):
x2 = coords[j][0]
y2 = coords[j][1]
if (x1 - x) * (y2 - y) == (x2 - x) * (y1 - y):
coords[j][2] = True
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 LIST VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def gcd(a, b):
while a:
a, b = b % a, a
return b
def normalize(x, y):
g = gcd(x, y)
return x // g, y // g
n, x0, y0 = (int(x) for x in input().split())
s = set()
for i in range(n):
x, y = (int(x) for x in input().split())
s.add(normalize(x - x0, y - y0))
print(len(s)) | FUNC_DEF WHILE VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
d = {}
k = 0
l = []
a = 0
for _ in range(n):
x, y = map(int, input().split())
if x == x0:
if y == y0:
a = 1
elif "inf" not in l:
k += 1
l += ["inf"]
else:
a = (y - y0) / (x - x0)
b = y0 - a * x0
if (a, b) not in l:
k += 1
l += [(a, b)]
if k == 0:
print(a)
else:
print(k) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF STRING VAR VAR NUMBER VAR LIST STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER VAR LIST VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = map(int, input().split())
r = 0
cs = []
ck = [0] * n
for i in range(n):
cs += [tuple(map(int, input().split()))]
for j, c in enumerate(cs):
if ck[j] == 0:
r += 1
ck[j] = 1
for i, oc in enumerate(cs):
if (y0 - oc[1]) * (x0 - c[0]) == (y0 - c[1]) * (x0 - oc[0]):
ck[i] = 1
print(r) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
p = []
dx, dy = 0, 0
for i in range(n):
x1, y1 = map(int, input().split())
dx, dy = x1 - x, y1 - y
if dx == 0:
if "a" not in p:
p.append("a")
elif dy / dx not in p:
p.append(dy / dx)
print(len(p)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
ans = 0
L = []
for i in range(n):
u, v = map(int, input().split())
ok = False
for u_, v_ in L:
if (x - u) * (y - v_) == (x - u_) * (y - v):
ok = True
break
if not ok:
ans += 1
L.append((u, v))
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def hansolo(n, x0, y0, a):
dic = {}
ans = 0
for c in a:
if c[0] == x0:
if "vertical" in dic:
dic["vertical"] += 1
else:
dic["vertical"] = 1
ans += 1
else:
b = (c[1] - y0) / (c[0] - x0)
if b in dic:
continue
else:
dic[b] = 1
ans += 1
return ans
n, x, y = list(map(int, input().split(" ")))
a = []
for i in range(n):
x1, y1 = list(map(int, input().split(" ")))
a.append([x1, y1])
print(hansolo(n, x, y, a)) | FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR IF STRING VAR VAR STRING NUMBER ASSIGN VAR STRING NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def div(m, n):
if n != 0:
return m / n
return "inf"
n, x, y = map(int, input().split())
l = []
for i in range(n):
m, n = map(int, input().split())
m -= x
n -= y
z = div(m, n)
if z != "inf":
if z not in l:
l.append(z)
elif z not in l:
l.append(z)
print(len(l)) | FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN STRING ASSIGN VAR 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 VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x0, y0 = list(map(int, input().split()))
total = {}
for i in range(n):
x1, y1 = list(map(int, input().split()))
if 0 == x1 - x0:
to = float("inf")
else:
to = float(y1 - y0) / (x0 - x1)
total[to] = total.get(to, 0) + 1
print(len(total)) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | [n, a, b] = list(map(int, input().split()))
l = []
for i in range(n):
t = tuple(map(int, input().split()))
l.append(t)
d = {}
for x in l:
if x[0] == a:
d[x] = "a"
elif x[1] == b:
d[x] = 0
else:
d[x] = (x[1] - b) / (x[0] - a)
l1 = []
for x in d.values():
if x not in l1:
l1.append(x)
print(len(l1)) | ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 DICT FOR VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR STRING IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | inp = input().split()
numTroops = int(inp[0])
startX = int(inp[1])
startY = int(inp[2])
troopList = set()
for s in range(numTroops):
inp = input().split()
x = int(inp[0])
y = int(inp[1])
s = ""
if x != startX or y != startY:
if x == startX:
s = "und"
else:
i = (y - startY) / (x - startX)
if i == 0:
s = "0.0"
else:
s = str(i)
if s not in troopList:
troopList.add(s)
print(len(troopList)) | 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 NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, p, q = map(int, input().split())
x = [0] * (n + 2)
y = [0] * (n + 2)
cnt = 0
chk = [0] * (n + 2)
for i in range(0, n):
inp = list(map(int, input().split()))
x[i] = inp[0] - p
y[i] = inp[1] - q
for i in range(0, n):
if chk[i] == 1:
continue
cnt = cnt + 1
chk[i] = 1
for j in range(0, n):
if chk[j] == 1:
continue
if x[i] * y[j] == x[j] * y[i]:
chk[j] = 1
print(cnt) | ASSIGN VAR 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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | import sys
def input():
return sys.stdin.readline().strip()
n, x, y = map(int, input().split())
slope = {}
for i in range(n):
x_0, y_0 = map(int, input().split())
try:
m = (y_0 - y) / (x_0 - x)
except:
m = 10**10
slope[m] = 1
print(len(slope)) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | inp = input()
l = inp.split(" ")
n = int(l[0])
x0 = int(l[1])
y0 = int(l[2])
m = []
for i in range(0, n):
inpu = input()
l1 = inpu.split(" ")
x = int(l1[0])
y = int(l1[1])
if x - x0 != 0:
m.append([(y - y0) / (x - x0), y0 - (y - y0) / (x - x0) * x0])
else:
m.append(0)
for i in range(0, len(m) - 1):
k = i + 1
for j in range(i + 1, len(m)):
j = k
if m[i] == m[j]:
m.pop(j)
k = j
else:
k = j + 1
print(len(m)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | lectura = lambda: map(int, input().split())
numeroPuntos, x0, y0 = lectura()
arrayPuntos = []
for i in range(0, numeroPuntos):
x, y = lectura()
listat = [x, y]
arrayPuntos.append(listat)
numeroPendientes = set()
for i in range(0, numeroPuntos):
arriba = arrayPuntos[i][1] - y0
abajo = arrayPuntos[i][0] - x0
if abajo != 0 and arriba != 0:
pendiente = float(arriba) / float(abajo)
else:
if abajo == 0:
pendiente = "a"
if arriba == 0:
pendiente = "b"
numeroPendientes.add(pendiente)
print(len(numeroPendientes)) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR STRING IF VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | n, x, y = map(int, input().split())
troopers = list()
for i in range(n):
troopers.append(list(map(int, input().split())))
lines = set()
inline = False
for i in troopers:
xi = i[0]
yi = i[1]
if xi != x:
lines.add((yi - y) / (xi - x))
else:
inline = True
print(len(lines) + 1 if inline else len(lines)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR |
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x_0, y_0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (x_0, y_0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
-----Input-----
The first line contains three integers n, x_0 и y_0 (1 ≤ n ≤ 1000, - 10^4 ≤ x_0, y_0 ≤ 10^4) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each x_{i}, y_{i} ( - 10^4 ≤ x_{i}, y_{i} ≤ 10^4) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
-----Output-----
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
-----Examples-----
Input
4 0 0
1 1
2 2
2 0
-1 -1
Output
2
Input
2 1 2
1 1
1 0
Output
1
-----Note-----
Explanation to the first and second samples from the statement, respectively: [Image] | def read():
return map(int, input().split())
def main():
n, x0, y0 = read()
st_loc = []
for _ in range(n):
x, y = read()
st_loc.append((x, y))
ans = 0
while st_loc:
x1, y1 = st_loc.pop()
st_loc = [
(x, y) for x, y in st_loc if (x - x0) * (y1 - y0) != (y - y0) * (x1 - x0)
]
ans += 1
print(ans)
main() | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | def read():
return input().strip()
def readint():
return int(read())
n, k = map(int, read().split())
arr = [0] * 1001
for i in read().split():
arr[int(i)] = 1
mink = 9999999
for i in range(1, n):
brr = list(arr)
s = k
j = 1
ii = 0
val = 0
while s > 0:
val = j % n
if val == 0:
val = n
if brr[val] == 0 and arr[val] == 1:
ii = 9999999
break
if brr[val] == 1:
s = s - 1
brr[val] = 0
j = j + i
ii += 1
if ii > mink:
break
if ii < mink:
mink = ii
print(mink) | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | m, n = map(int, input().split())
v = [int(x) for x in input().split()]
ans = m
for i in range(1, m):
cpy = v.copy()
k, cnt, l = 1, 1, [1]
while len(cpy) != 0:
if k in cpy:
cpy.remove(k)
if len(cpy) == 0:
break
k += i
cnt += 1
if k > m:
k = k - m
if k in l:
cnt = 10000000000000.0
break
l.append(k)
ans = min(ans, cnt)
print(ans) | 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 VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER LIST NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | def totient(n):
ret = n
i = 2
while i * i <= n:
if n % i == 0:
ret = (i - 1) * (ret // i)
while n % i == 0:
n //= i
i += 1
if n:
ret = (n - 1) * (ret // n)
return ret
def gcd(x, y):
while y:
x, y = y, x % y
return x
def main():
n, m = map(int, input().split())
arr = list(map(int, input().split()))
phi = totient(n)
ans = 1000
for i in range(1, n):
tmp = 0
g = gcd(i, n)
if g != 1:
for d in arr:
if (d - 1) % g:
tmp = -1
break
if tmp == -1:
continue
j = i // g
for d in arr:
tmp = max(tmp, (d - 1) // g * pow(j, phi - 1, n) % n)
if tmp == 1:
print(i)
ans = min(ans, tmp + 1)
print(ans)
return 0
main() | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN VAR FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
a = list(map(int, input().split()))
maximum = 1000000000000
final = [False] * n
for i in a:
final[i - 1] = True
for j in range(1, n):
test = list(final)
total = 0
x = 0
index = 0
while x != m and total < maximum:
if test[index]:
x += 1
test[index] = False
index = (index + j) % n
total += 1
if total < maximum:
maximum = total
if maximum == m:
break
print(maximum) | 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 NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | hash, ans = {}, []
n, m = map(int, input().split())
ka = set(list(map(int, input().split())))
for i in range(n + 1):
z, count, ba = 1, 0, 0
while True:
if z == 1 and count != 0:
break
if ba == m:
break
if z in ka:
ba += 1
if z + i <= n:
z += i
else:
k = z + i
z = k - n
count += 1
if ba == m:
ans.append(count)
print(min(ans)) | ASSIGN VAR VAR DICT LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER WHILE NUMBER IF VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, _ = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
boo = [(True if i in arr and i != 1 else False) for i in range(1, n + 1)]
lis = [0] * n
ii = 1
for aa in range(1, n):
i = 1
boo1 = boo.copy()
while True in boo1:
boo1[i - 1] = False
lis[aa - 1] += 1
i = (i + aa) % n
if lis[aa - 1] > 2000:
break
time = lis[aa - 1]
lis = lis[:-1]
print(min(lis)) | 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 VAR VAR VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
f = [([] * i) for i in range(1001)]
for i in range(1001):
for j in range(1001):
f[i].append(-1)
for i in range(1, 1001):
s = 0
for x in range(1, 100000000, i):
s = s + 1
if s > 1005:
break
if x % n != 0:
if f[i][x % n] == -1:
f[i][x % n] = s
else:
f[i][x % n] = min(f[i][x % n], s)
elif f[i][n] == -1:
f[i][n] = s
else:
f[i][n] = min(f[i][n], s)
a = list(map(int, input().split()))
p = [100000000] * 1005
for i in range(1, 1001):
try:
for j in a:
if f[i][j] == -1:
s = 0 / 0
if p[i] == 100000000:
p[i] = f[i][j]
else:
p[i] = max(p[i], f[i][j])
except:
p[i] = 100000000
continue
print(min(p)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
ls = set(list(map(int, input().split())))
mn = 10**9
for i in range(1, n):
count = 0
dct = {}
s = 0
k = m
case = 1
while k > 0:
if s in dct:
case = 0
break
dct[s] = 1
if s + 1 in ls:
k -= 1
s = (s + i) % n
count += 1
if case:
mn = min(mn, count)
print(mn) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | s = list(map(int, input().split()))
n, m = s[0], s[1]
lol = list(map(int, input().split()))
dict = {}
for i in range(10001):
dict[i] = 0
for i in range(len(lol)):
dict[lol[i]] = 1
x = 1
minstop = 1000000007
while x < n:
stop = 1
nex = 1 + x
l = []
if dict[1] == 1:
l.append(1)
if len(l) == m:
minstop = 1
break
while True:
stop += 1
if dict[nex] == 1:
l.append(nex)
if len(l) == m:
break
nex = nex + x
if nex > n:
nex = nex - n
if nex == 1 and len(l) != m:
stop = 1000000007
break
minstop = min(minstop, stop)
x += 1
print(minstop) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | try:
n, m = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
mindif = 999999
maxdif = arr[-1] - arr[0]
for i in range(1, m):
if mindif > arr[i] - arr[i - 1]:
mindif = arr[i] - arr[i - 1]
minstop = []
d = dict()
d1 = dict()
for i in range(mindif, maxdif + 1):
for _ in arr:
d[_] = 1
d1[_] = 1
count = 0
stop = 0
j = 1
while j < n + 1:
stop += 1
if j == 1:
count += 1
if count == 2:
stop = 99999999
break
if j in d:
if d[j] == 1:
d[j] = 0
del d1[j]
else:
stop = 99999999
break
if len(d1) == 0:
break
j += i
if j > n:
j = j % n
minstop += [stop]
print(min(minstop))
except EOFError:
pass | 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
l = set(map(int, input().split()))
arr = [i for i in range(1, n + 1)]
ans = 10**9
x = 1
while x < n + 1:
array = set()
ind = [False] * n
done = False
array.add(1)
val = 1
cou = 1
while not done:
no = (val + x) % n
if no == 0:
no = n
if no in array:
break
else:
array.add(no)
cou += 1
val += x
if cou == n:
done = True
if array >= l:
if len(array) < ans:
ans = len(array)
break
x += 1
print(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 VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | ll = lambda: list(map(int, input().split()))
[n, x] = ll()
arr = ll()
h = [0] * n
minj = 9999999
for i in range(x):
h[arr[i] - 1] = 1
for px in range(1, n - 1):
vis = [0] * (n + 1)
viscells = 0
index = 0
jumps = 0
while viscells != x and vis[index] == 0:
if h[index] == 1:
viscells += 1
vis[index] = 1
index = (index + px) % n
jumps += 1
if viscells == x and jumps < minj:
minj = jumps
print(minj) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = 999999999999
for x in range(1, n):
s = set(a)
stops = 0
q = 1
for i in range(n):
if q in s:
s.remove(q)
q = (q - 1 + x) % n + 1
stops += 1
if len(s) == 0:
break
if len(s) == 0:
ans = min(ans, stops)
print(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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
l = list(map(int, input().split()))
e = {}
for i in range(m):
e[l[i]] = 0
d = []
for i in range(1, n):
k = []
f = 0
while len(k) != n:
if len(k) == 0:
c = 1
else:
c = (k[-1] + i) % n
if c == 0:
c = n
k.append(c)
try:
g = e[k[-1]]
if g == 0:
f += 1
e[k[-1]] = 1
if f == m:
d.append(len(k))
break
except:
pass
for i in range(m):
e[l[i]] = 0
print(min(d)) | 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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
a = list(map(int, input().split()))
mark = [(-1) for x in range(n + 1)]
for i in range(m):
mark[a[i]] = 0
minn = 10000
for i in range(1, n):
pos = 1
count = 0
ans = 1
while True:
if mark[pos] != -1 and mark[pos] != i:
mark[pos] = 0
count += 1
pos = (pos + i) % n
if pos == 0:
pos = n
if pos == 1 or count == m:
break
ans += 1
if count == m:
minn = min(ans, minn)
print(minn) | 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,...
Chef needs to deliver packages to $m$ (m≤n) houses.
Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=7$ and $x=2$. He will stop at 1,3,5,7,2,... He may deliver a package when he stops at a house. His work is done when all the packages are delivered.
What is the minimum number of times Chef has to stop, if he can choose any $x$ ?
__Note__: Starting point (1) is also counted in number of stops
------ Input: ------
First line will contain $n, m$, denoting number of houses and number of packages respectively.
Next line contains $m$ distinct space separated integers denoting the houses
------ Output: ------
Single line containing an integer denoting minimum number of stops.
------ Constraints ------
$3 ≤ n ≤ 1000$
$1 ≤ m ≤ n$
----- Sample Input 1 ------
5 3
1 2 4
----- Sample Output 1 ------
3
----- explanation 1 ------
For first input,
If Chef chooses $x=3$, he will stop at 1, 4, 2 before delivering all the packages.
----- Sample Input 2 ------
6 2
3 4
----- Sample Output 2 ------
4
----- explanation 2 ------
For second,
If Chef chooses $x=1$, he will stop at 1, 2, 3, 4 before delivering all the packages. | n, m = map(int, input().split())
s = [int(i) for i in input().split()]
min_val = 10**9 + 7
for x in range(1, n):
c = [1001] * (n + 1)
c[0] = 0
for i in range(n + 1):
val = (x * i + 1) % n
if val == 0:
val = n
c[val] = min(c[val], i + 1)
temp_val = 0
for i in s:
temp_val = max(temp_val, c[i])
min_val = min(min_val, temp_val)
print(min_val) | 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 BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | class Solution:
def __init__(self):
self.c = 0
def check(self, a, k):
if a == None:
return 0
o = self.check(a.left, k)
p = self.check(a.right, k)
q = a.data + o + p
if q == k:
self.c += 1
return q
def countSubtreesWithSumX(root, x):
o = Solution()
o.check(root, x)
return o.c | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
count = 0
def dfs(root):
nonlocal count
if not root:
return 0
l = dfs(root.left)
r = dfs(root.right)
s = root.data + l + r
if s == x:
count += 1
return s
dfs(root)
return count | FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
def traverse(node, k, ans):
if not node:
return 0
sm = traverse(node.left, k, ans) + traverse(node.right, k, ans) + node.data
if sm == k:
ans[0] += 1
return sm
ans = [0]
traverse(root, x, ans)
return ans[0] | FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | count = 0
def countSubtreesWithSumX(root, x):
C = [0]
dfs(root, x, C)
return C[0]
def dfs(root, x, C):
global count
if root:
a = dfs(root.left, x, C)
b = dfs(root.right, x, C)
Sum = a + b + root.data
if Sum == x:
C[0] += 1
return Sum
return 0 | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR RETURN NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def preorder(root, target, res):
if root is None:
return 0
left_sum = preorder(root.left, target, res)
right_sum = preorder(root.right, target, res)
if left_sum + right_sum + root.data == target:
res[0] += 1
return left_sum + right_sum + root.data
def countSubtreesWithSumX(root, x):
res = [0]
preorder(root, x, res)
return res[0] | FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countsubtree(root, count, x):
if root == None:
return 0
left = countsubtree(root.left, count, x)
right = countsubtree(root.right, count, x)
sum = 0
sum = left + right + root.data
if sum == x:
count[0] += 1
return sum
def countSubtreesWithSumX(root, x):
count = [0]
countsubtree(root, count, x)
return count[0] | FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
res, _ = countSubtreesUtil(root, x)
return res
def countSubtreesUtil(root, x):
if not root:
return 0, 0
num_left, sum_left = countSubtreesUtil(root.left, x)
num_right, sum_right = countSubtreesUtil(root.right, x)
sum = root.data + sum_left + sum_right
num = num_left + num_right
if sum == x:
num += 1
return num, sum | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def util(root, x, ans):
if not root:
return 0
sm = 0
sm += root.data
sm += util(root.left, x, ans)
sm += util(root.right, x, ans)
if sm == x:
ans[0] += 1
return sm
def countSubtreesWithSumX(root, x):
ans = [0]
util(root, x, ans)
return ans[0] | FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | count = 0
def countSubtreesWithSumX(root, x):
global count
count = 0
_countSubtreesWithSumX(root, x)
return count
def _countSubtreesWithSumX(root, x):
if root == None:
return 0
global count
lh = _countSubtreesWithSumX(root.left, x)
rh = _countSubtreesWithSumX(root.right, x)
if lh + rh + root.data == x:
count += 1
return lh + rh + root.data | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
def checkSubtree(root, x, cnt):
if not root:
return 0, cnt
suml, cnt = checkSubtree(root.left, x, cnt)
sumr, cnt = checkSubtree(root.right, x, cnt)
sum = root.data + suml + sumr
if sum == x:
cnt += 1
return sum, cnt
return checkSubtree(root, x, 0)[1] | FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | ans = 0
def solve(node, x):
if not node:
return 0
global ans
temp = solve(node.left, x) + solve(node.right, x) + node.data
if temp == x:
ans += 1
return temp
def countSubtreesWithSumX(root, x):
global ans
ans = 0
solve(root, x)
return ans | ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
m = {}
def fun(root):
if root == None:
return 0
s = 0
s += root.data
s += fun(root.left)
s += fun(root.right)
if s not in m:
m[s] = 1
else:
m[s] += 1
return s
fun(root)
if x in m:
return m[x]
else:
return 0 | FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR RETURN NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
count = [0]
def solver(root, x):
if not root:
return 0
left = solver(root.left, x)
right = solver(root.right, x)
if left + right + root.data == x:
count[0] += 1
return left + right + root.data
store = solver(root, x)
return count[0] | FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
res = [0]
rec(root, x, res)
return res[0]
def rec(root, x, res):
if root is None:
return 0
sumi = root.data
sumi += rec(root.left, x, res)
sumi += rec(root.right, x, res)
if sumi == x:
res[0] += 1
return sumi | FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
count = [0]
ans(root, x, count)
return count[0]
def ans(root, x, count):
if root == None:
return 0
a = ans(root.left, x, count)
b = ans(root.right, x, count)
sum = a + b + root.data
if sum == x:
count[0] = count[0] + 1
return sum | FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
if not root:
return 0
if not root.left and not root.right:
if root.data == x:
return 1
res = [0]
_ = subtreeSum(root, x, res)
return res[0]
def subtreeSum(root, x, res):
if not root:
return 0
l_subtree = subtreeSum(root.left, x, res)
r_subtree = subtreeSum(root.right, x, res)
subtreeSummation = l_subtree + r_subtree + root.data
if subtreeSummation == x:
res[0] += 1
return subtreeSummation | FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
res = []
def find(root, x, res):
if not root:
return 0
left = find(root.left, x, res)
right = find(root.right, x, res)
curr = root.data + left + right
if curr == x:
res.append(root.data)
return curr
find(root, x, res)
return len(res) | FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
ans = [0]
def rec(nod, x, sumi):
if nod is None:
return 0
lh = rec(nod.left, x, sumi)
rh = rec(nod.right, x, sumi)
p = nod.data + lh + rh
if p == x:
ans[0] += 1
return p
rec(root, x, 0)
return ans[0] | FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
return helper(root, x)[1]
def helper(root, target):
if root is None:
return 0, 0
sum_left, count_left = helper(root.left, target)
sum_right, count_right = helper(root.right, target)
summa = sum_left + sum_right + root.data
count = (summa == target) + count_left + count_right
return summa, count | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def traverseTree(root, x):
if root is None:
return 0
left = traverseTree(root.left, x)
right = traverseTree(root.right, x)
sum_subtree = left + right + root.data
if sum_subtree == x:
traverseTree.count += 1
return sum_subtree
def countSubtreesWithSumX(root, x):
arr = [0]
traverseTree.count = 0
traverseTree(root, x)
return traverseTree.count | FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def count(root, x):
if root is None:
return [0, 0]
l, r = count(root.left, x), count(root.right, x)
if root.data + l[0] + r[0] == x:
return [root.data + l[0] + r[0], 1 + l[1] + r[1]]
else:
return [root.data + l[0] + r[0], l[1] + r[1]]
def countSubtreesWithSumX(root, x):
return count(root, x)[1] | FUNC_DEF IF VAR NONE RETURN LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR RETURN LIST BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN LIST BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def utility(root, x, res):
if root == None:
return 0
if root.left == None and root.right == None:
if root.data == x:
res[0] += 1
return root.data
lSum = utility(root.left, x, res)
rSum = utility(root.right, x, res)
total = root.data + lSum + rSum
if total == x:
res[0] += 1
return total
def countSubtreesWithSumX(root, x):
res = [0]
utility(root, x, res)
return res[0] | FUNC_DEF IF VAR NONE RETURN NUMBER IF VAR NONE VAR NONE IF VAR VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
val = [0]
def Sum(root, x, val):
if root == None:
return 0
s = Sum(root.left, x, val) + Sum(root.right, x, val) + root.data
if x == s:
val[0] += 1
return s
Sum(root, x, val)
return val[0] | FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
res = [0]
def dfs(root):
if not root:
return 0
if not root.left and not root.right:
if root.data == x:
res[0] += 1
return root.data
l = dfs(root.left)
r = dfs(root.right)
if l + r + root.data == x:
res[0] += 1
return l + r + root.data
dfs(root)
return res[0] | FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, k):
def helper(root):
nonlocal ans
if not root:
return 0
lft = helper(root.left)
rgt = helper(root.right)
if lft + rgt + root.data == k:
ans += 1
return lft + rgt + root.data
ans = 0
helper(root)
return ans | FUNC_DEF FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def util(root, x):
if root is None:
return 0
ls = util(root.left, x)
rs = util(root.right, x)
sum = ls + rs + root.data
if sum == x:
util.count += 1
return sum
def countSubtreesWithSumX(root, x):
if root is None:
return 0
util.count = 0
ls = util(root.left, x)
rs = util(root.right, x)
sum_of_current = ls + rs + root.data
if sum_of_current == x:
util.count += 1
return util.count | FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | from sys import setrecursionlimit
setrecursionlimit(10**6)
def countSubtreesWithSumX(root, x):
ans = [0]
def calc(root):
if root == None:
return 0
l = calc(root.left)
r = calc(root.right)
if l + r + root.data == x:
ans[0] += 1
return l + r + root.data
calc(root)
return ans[0] | EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR NUMBER |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
if root is None:
return 0
count = [0]
ls = sumTree(root.left, count, x)
rs = sumTree(root.right, count, x)
if ls + rs + root.data == x:
count[0] += 1
return count[0]
def sumTree(root, count, x):
if root is None:
return 0
ls = sumTree(root.left, count, x)
rs = sumTree(root.right, count, x)
s = ls + rs + root.data
if s == x:
count[0] += 1
return s | FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER RETURN VAR NUMBER FUNC_DEF IF VAR NONE RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumX(root, x):
q = [root]
d = {}
while q:
node = q.pop(0)
d[node] = -1
if node.left:
q.append(node.left)
if node.right:
q.append(node.right)
def sum(root):
if not root:
return 0
if d[root] != -1:
return d[root]
d[root] = root.data + sum(root.left) + sum(root.right)
return d[root]
count = 0
sum(root)
a = list(d.values())
for i in a:
if i == x:
count += 1
return count | FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR DICT WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR NUMBER RETURN VAR |
Given a binary tree and an integer X. Your task is to complete the function countSubtreesWithSumX() that returns the count of the number of subtress having total node’s data sum equal to the value X.
Example: For the tree given below:
5
/ \
-10 3
/ \ / \
9 8 -4 7
Subtree with sum 7:
-10
/ \
9 8
and one node 7.
Example 1:
Input:
5
/ \
-10 3
/ \ / \
9 8 -4 7
X = 7
Output: 2
Explanation: Subtrees with sum 7 are
[9, 8, -10] and [7] (refer the example
in the problem description).
Example 2:
Input:
1
/ \
2 3
X = 5
Output: 0
Explanation: No subtree has sum equal
to 5.
Your Task:
You don't need to read input or print anything. Your task is to complete the function countSubtreesWithSumX() which takes the root node and an integer X as inputs and returns the number of subtrees of the given Binary Tree having sum exactly equal to X.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).
Constraints:
1 <= N <= 10^{3}
-10^{3} <= Node Value <= 10^{3}
Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code. | def countSubtreesWithSumXRec(root, x):
if root == None:
return 0, 0
ans_l, sum_l = countSubtreesWithSumXRec(root.left, x)
ans_r, sum_r = countSubtreesWithSumXRec(root.right, x)
if sum_l + sum_r + root.data == x:
return ans_l + ans_r + 1, sum_l + sum_r + root.data
else:
return ans_l + ans_r, sum_l + sum_r + root.data
def countSubtreesWithSumX(root, x):
ans, sum_t = countSubtreesWithSumXRec(root, x)
return ans | FUNC_DEF IF VAR NONE RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.