description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
a = []
b = []
c = []
d = []
for i in range(n):
opt, num = [int(x) for x in input().split()]
if opt == 0:
a.append(num)
if opt == 10:
b.append(num)
if opt == 1:
c.append(num)
if opt == 11:
d.append(num)
ans = sum(d)
b.sort(reverse=True)
c.sort(reverse=True)
if len(b) < len(c):
ans += sum(b) + sum(c[0 : len(b)])
a.extend(c[len(b) :])
else:
ans += sum(c) + sum(b[0 : len(c)])
a.extend(b[len(c) :])
a.sort(reverse=True)
ans += sum(a[0 : len(d)])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
no = []
a = []
b = []
bo = []
for _ in range(n):
t, s = map(int, input().split())
if t == 11:
bo.append(s)
elif t == 10:
a.append(s)
elif t == 1:
b.append(s)
else:
no.append(s)
ans = 0
for i in bo:
ans += i
a.sort(reverse=True)
b.sort(reverse=True)
if len(a) > len(b):
for i in range(len(b)):
ans += a[i]
ans += b[i]
for i in range(len(b), len(a)):
no.append(a[i])
else:
for i in range(len(a)):
ans += a[i]
ans += b[i]
for i in range(len(a), len(b)):
no.append(b[i])
no.sort(reverse=True)
for i in range(min(len(bo), len(no))):
ans += no[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
both = []
a, b = [], []
no = []
lb = 0
la = 0
for _ in range(n):
x, y = [x for x in input().split()]
if x == "11":
both.append(int(y))
elif x == "01":
b.append(int(y))
lb += 1
elif x == "10":
a.append(int(y))
la += 1
else:
no.append(int(y))
a.sort(reverse=True)
b.sort(reverse=True)
ans = sum(both)
mini = min(la, lb)
ans2 = 0
for i in range(mini):
ans += a[i] + b[i]
if la > lb:
for i in range(mini, la):
no.append(a[i])
else:
for i in range(mini, lb):
no.append(b[i])
temp = min(len(both), len(no))
no.sort(reverse=True)
for i in range(temp):
ans += no[i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR LIST LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
import sys
a = []
b = []
c = []
d = []
def main():
n = int(sys.stdin.readline().strip("\n"))
for i in range(n):
opt, num = [int(line) for line in sys.stdin.readline().strip("\n").split()[:2]]
if opt == 0:
a.append(num)
if opt == 10:
b.append(num)
if opt == 1:
c.append(num)
if opt == 11:
d.append(num)
res = sum(d)
b.sort(reverse=True)
c.sort(reverse=True)
if len(b) > len(c):
res += sum(c) + sum(b[: len(c)])
a.extend(b[len(c) :])
else:
res += sum(b) + sum(c[: len(b)])
a.extend(c[len(b) :])
a.sort(reverse=True)
res += sum(a[: len(d)])
print(res)
def __starting_point():
main()
__starting_point()
|
IMPORT ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
x_s = []
y_s = []
w_s = []
z_s = []
for _ in range(n):
s, a = input().split(" ")
a = int(a)
if s == "00":
z_s.append(a)
if s == "01":
x_s.append(a)
if s == "10":
y_s.append(a)
if s == "11":
w_s.append(a)
w_s = list(reversed(sorted(w_s)))
x_s = list(reversed(sorted(x_s)))
y_s = list(reversed(sorted(y_s)))
z_s = list(reversed(sorted(z_s)))
if len(x_s) > len(y_s):
tmp = y_s
y_s = x_s
x_s = tmp
if len(w_s) == 0 and (len(x_s) == 0 or len(y_s) == 0):
print(0)
else:
base_influence = sum(w_s) + sum(x_s) + sum(y_s[: len(x_s)])
best_influence = 0
w = len(w_s)
y_s = y_s[len(x_s) :]
z_prefix_sums = []
z_sum = 0
for z in z_s:
z_sum += z
z_prefix_sums.append(z_sum)
y_sum = 0
for y in range(len(y_s) + 1):
if y > 0:
y_sum += y_s[y - 1]
z = w - y
if z >= 0:
this_influence = base_influence + y_sum
if z_s and z > 0:
this_influence += z_prefix_sums[min(z - 1, len(z_prefix_sums) - 1)]
best_influence = max(best_influence, this_influence)
print(best_influence)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
def fun(c):
return c[0]
def f(a, b, alice, bob, un, n, check):
inf = 0
if n - a <= a:
inf = 0
for i in range(n):
inf += int(inp[i][1])
else:
tempb = 0
j = 0
for i in range(a):
inf += alice[i][0]
d[alice[i][1]] = 1
if who[alice[i][1]][check] == "1":
tempb += 1
j += 1
i = 0
while i < b and tempb < a:
if d[bob[i][1]] == 0:
inf += bob[i][0]
tempb += 1
j += 1
i += 1
if j < 2 * a:
k = 0
unn = len(un)
while j < 2 * a and i < b and k < unn:
if i < b and k < unn:
if d[bob[i][1]] == 1:
i += 1
elif bob[i][0] > un[k][0]:
inf += bob[i][0]
i += 1
j += 1
else:
inf += un[k][0]
k += 1
j += 1
while j < 2 * a and i < b:
if d[bob[i][1]] == 1:
i += 1
else:
inf += bob[i][0]
i += 1
j += 1
while j < 2 * a and k < unn:
inf += un[k][0]
k += 1
j += 1
print(inf)
n = int(input())
d = {}
who = {}
inp = []
a = 0
b = 0
alice = []
bob = []
un = []
for i in range(n):
t = input().split()
if t[0][0] == "1":
a += 1
temp = [int(t[1]), i]
d[i] = 0
alice.append(temp)
if t[0][1] == "1":
b += 1
temp = [int(t[1]), i]
bob.append(temp)
d[i] = 0
if t[0][1] == t[0][0] and t[0][0] == "0":
temp = [int(t[1]), i]
un.append(temp)
who[i] = t[0]
inp.append(t)
alice.sort(key=fun, reverse=True)
bob.sort(key=fun, reverse=True)
un.sort(key=fun, reverse=True)
inf = 0
if a < b:
f(a, b, alice, bob, un, n, 1)
else:
f(b, a, bob, alice, un, n, 0)
|
FUNC_DEF RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP NUMBER VAR VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER STRING VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER STRING VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER STRING ASSIGN VAR LIST FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
N = int(input())
A = [[] for _ in range(4)]
a, b, c, d = A
for ni in range(N):
v, f = input().split()
A[int(v, 2)].append(int(f))
for i in range(len(A)):
A[i].sort(reverse=True)
ans = sum(A[3] or [0])
single = min(len(A[1]), len(A[2]))
ans += sum(A[1][:single] or [0])
ans += sum(A[2][:single] or [0])
x = len(A[3]) + single
a = A[1][single:] + A[2][single:] + A[0]
a.sort(reverse=True)
ans += sum(a[: len(A[3])] or [0])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR LIST NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
a, b, c = [], [], []
ans = 0
num11 = 0
for i in range(n):
t, val = map(int, input().split())
if t == 11:
ans += val
num11 += 1
continue
if t & 1:
a.append(val)
if t & 2:
b.append(val)
if not t:
c.append(val)
a.sort(reverse=True)
b.sort(reverse=True)
min_num = min(len(a), len(b))
ans += sum(a[:min_num]) + sum(b[:min_num])
t = a[min_num:] + b[min_num:] + c
t.sort(reverse=True)
ans += sum(t[: 2 * (min(len(a), len(b)) + num11) - 2 * min_num - num11])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
s = [[], [], [], []]
for i in range(n):
x = input().strip().split()
if x[0] == "11":
s[3].append(int(x[1]))
elif x[0] == "10":
s[2].append(int(x[1]))
elif x[0] == "01":
s[1].append(int(x[1]))
else:
s[0].append(int(x[1]))
ans = 0
for i in range(len(s[3])):
ans = ans + s[3][i]
s[2] = sorted(s[2], reverse=True)
s[1] = sorted(s[1], reverse=True)
tlen = min(len(s[1]), len(s[2]))
for i in range(1, 3):
for j in range(tlen):
ans = ans + s[i][j]
for j in range(tlen, len(s[i])):
s[0].append(s[i][j])
s[0] = sorted(s[0], reverse=True)
tlen = min(len(s[3]), len(s[0]))
for i in range(tlen):
ans = ans + s[0][i]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST LIST LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
arr = [[], [], []]
ans = 0
temp = 0
for _ in range(int(input())):
s, c = input().split()
if s == "11":
ans += int(c)
temp += 1
elif s == "00":
arr[0].append(int(c))
elif s == "01":
arr[1].append(int(c))
else:
arr[2].append(int(c))
temp1 = min(len(arr[1]), len(arr[2]))
arr[1].sort(reverse=True)
arr[2].sort(reverse=True)
for i in range(temp1):
ans += arr[1][i] + arr[2][i]
if len(arr[1]) < len(arr[2]):
for i in range(temp1, len(arr[2])):
arr[0].append(arr[2][i])
else:
for i in range(temp1, len(arr[1])):
arr[0].append(arr[1][i])
arr[0].sort(reverse=True)
temp3 = min(temp, len(arr[0]))
for i in range(temp3):
ans += arr[0][i]
print(ans)
|
ASSIGN VAR LIST LIST LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
a10 = []
a01 = []
a00 = []
cnt11 = 0
cnt10 = 0
cnt01 = 0
cnt00 = 0
res = 0
for i in range(n):
t1, t2 = input().split(" ")
if t1 == "11":
cnt11 += 1
res += int(t2)
elif t1 == "10":
cnt10 += 1
a10.append(int(t2))
elif t1 == "01":
cnt01 += 1
a01.append(int(t2))
else:
cnt00 += 1
a00.append(int(t2))
cnt = min(cnt01, cnt10)
a01 = sorted(a01, reverse=True)
a10 = sorted(a10, reverse=True)
for i in range(cnt):
res += a01[i]
res += a10[i]
if cnt10 > cnt01:
a00 += a10[cnt:]
elif cnt01 > cnt10:
a00 += a01[cnt:]
a00 = sorted(a00, reverse=True)
for i in range(min(cnt11, len(a00))):
res += a00[i]
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR STRING VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
a = [[] for i in range(4)]
for i in range(n):
s, influence = [i for i in input().split()]
a[int(s, 2)].append(int(influence))
for i in range(4):
a[i].sort(reverse=True)
def check():
x = len(a[1])
y = len(a[2])
xy = len(a[3])
z = len(a[0])
if xy + y == 0 or xy + x == 0:
print(0)
return
w = min(x, y)
sum0 = 0
sum0 += sum(a[1][:w]) + sum(a[2][:w]) + sum(a[3])
choose = 2
if x >= y:
choose = 1
num = 0
i = w
j = 0
while i < max(x, y) and j < z and num < xy:
if a[choose][i] >= a[0][j]:
sum0 += a[choose][i]
i += 1
else:
sum0 += a[0][j]
j += 1
num += 1
while i < max(x, y) and num < xy:
sum0 += a[choose][i]
i += 1
num += 1
while j < z and num < xy:
sum0 += a[0][j]
j += 1
num += 1
print(sum0)
check()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF 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 VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
lis10 = []
lis01 = []
lis00 = []
inf = c11 = c10 = c01 = c = c00 = 0
for i in range(n):
a, b = list(map(str, input().split()))
if a == "11":
inf += int(b)
c11 += 1
elif a == "10":
c10 += 1
lis10.append(int(b))
elif a == "01":
c01 += 1
lis01.append(int(b))
else:
c00 += 1
lis00.append(int(b))
lis10.sort(reverse=True)
lis01.sort(reverse=True)
c = min(c01, c10)
for i in range(c):
inf += lis10[i] + lis01[i]
lis00 += lis10[c:c10] + lis01[c:c01]
lis00.sort(reverse=True)
for i in range(min(c11, len(lis00))):
inf += lis00[i]
print(inf)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
def __starting_point():
n = int(input())
supporters = {}
supporters[0] = []
supporters[1] = []
supporters[10] = []
supporters[11] = []
for i in range(n):
[x, y] = [int(x) for x in input().split()]
supporters[x].append(y)
for x in supporters:
supporters[x].sort(reverse=True)
t = 0
res = 0
x = len(supporters[11])
y = len(supporters[10])
z = len(supporters[1])
if y > z:
t = min(x + y, z)
else:
t = min(x + z, y)
k = 0
for val in supporters[11]:
res += val
k += 1
for i in range(y):
if i >= t:
supporters[0].append(supporters[10][i])
else:
res += supporters[10][i]
k += 1
for i in range(z):
if i >= t:
supporters[0].append(supporters[1][i])
else:
res += supporters[1][i]
k += 1
supporters[0].sort(reverse=True)
t = min(x + y, x + z)
i = 0
while 2 * t > k and i < len(supporters[0]):
k += 1
res += supporters[0][i]
i += 1
print(res)
__starting_point()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER LIST ASSIGN VAR NUMBER LIST ASSIGN VAR NUMBER LIST ASSIGN VAR NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Elections in Berland are coming. There are only two candidates β Alice and Bob.
The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views: supporting none of candidates (this kind is denoted as "00"), supporting Alice but not Bob (this kind is denoted as "10"), supporting Bob but not Alice (this kind is denoted as "01"), supporting both candidates (this kind is denoted as "11").
The direction of the TV channel wants to invite some of these people to the debate. The set of invited spectators should satisfy three conditions: at least half of spectators support Alice (i.e. $2 \cdot a \ge m$, where $a$ is number of spectators supporting Alice and $m$ is the total number of spectators), at least half of spectators support Bob (i.e. $2 \cdot b \ge m$, where $b$ is number of spectators supporting Bob and $m$ is the total number of spectators), the total influence of spectators is maximal possible.
Help the TV channel direction to select such non-empty set of spectators, or tell that this is impossible.
-----Input-----
The first line contains integer $n$ ($1 \le n \le 4\cdot10^5$) β the number of people who want to take part in the debate as a spectator.
These people are described on the next $n$ lines. Each line describes a single person and contains the string $s_i$ and integer $a_i$ separated by space ($1 \le a_i \le 5000$), where $s_i$ denotes person's political views (possible values β "00", "10", "01", "11") and $a_i$ β the influence of the $i$-th person.
-----Output-----
Print a single integer β maximal possible total influence of a set of spectators so that at least half of them support Alice and at least half of them support Bob. If it is impossible print 0 instead.
-----Examples-----
Input
6
11 6
10 4
01 3
00 3
00 7
00 9
Output
22
Input
5
11 1
01 1
00 100
10 1
01 1
Output
103
Input
6
11 19
10 22
00 18
00 29
11 29
10 28
Output
105
Input
3
00 5000
00 5000
00 5000
Output
0
-----Note-----
In the first example $4$ spectators can be invited to maximize total influence: $1$, $2$, $3$ and $6$. Their political views are: "11", "10", "01" and "00". So in total $2$ out of $4$ spectators support Alice and $2$ out of $4$ spectators support Bob. The total influence is $6+4+3+9=22$.
In the second example the direction can select all the people except the $5$-th person.
In the third example the direction can select people with indices: $1$, $4$, $5$ and $6$.
In the fourth example it is impossible to select any non-empty set of spectators.
|
n = int(input())
both = []
a = []
b = []
neither = []
for i in range(n):
c, d = map(int, input().split())
if c == 11:
both.append(d)
elif c == 10:
a.append(d)
elif c == 1:
b.append(d)
else:
neither.append(d)
inf = sum(both)
lee = len(both)
a.sort(reverse=True)
b.sort(reverse=True)
x = min(len(a), len(b))
inf += sum(a[:x]) + sum(b[:x])
neither += a[x:] + b[x:]
neither.sort(reverse=True)
if len(neither) < lee:
inf += sum(neither)
else:
inf += sum(neither[:lee])
print(inf)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
def main():
n = int(input())
l = list(map(int, input().split()))
seive = [False, True] * max(l)
a = len(seive)
for i in range(3, int(a**0.5) + 1, 2):
if seive[i]:
for j in range(i * i, a, i):
seive[j] = False
i = l.count(1)
if i:
res = [1] * i
for a in l:
if a > 1 and seive[a + 1]:
res.append(a)
break
if len(res) > 1:
print(len(res))
print(*res)
return
l0, l1 = [], []
for a in l:
if a != 1:
if a & 1:
for b in l0:
if seive[a + b]:
print(2)
print(a, b)
return
l1.append(a)
else:
for b in l1:
if seive[a + b]:
print(2)
print(a, b)
return
l0.append(a)
print(1)
print(l[0])
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
from time import time
n = int(input())
a = list(map(int, input().split()))
start = time()
cache = {}
def is_prime(n):
if n not in cache:
cache[n] = _is_prime(n)
return cache[n]
def _is_prime(n):
if n == 2 or n == 3:
return True
if n < 2 or n % 2 == 0:
return False
if n < 9:
return True
if n % 3 == 0:
return False
r = int(n**0.5)
f = 5
while f <= r:
if n % f == 0:
return False
if n % (f + 2) == 0:
return False
f += 6
return True
s = {}
i = 0
while i < len(a):
if a[i] > 1 and a[i] in s:
a.pop(i)
else:
s[a[i]] = True
i += 1
p = [0] * len(a)
for i in range(0, len(a)):
for j in range(i + 1, len(a)):
if not is_prime(a[i] + a[j]):
p[i] += 1
p[j] += 1
while True:
mx = max(p)
if mx == 0:
break
mi = p.index(mx)
for i in range(0, len(a)):
if i == mi or not is_prime(a[mi] + a[i]):
p[i] -= 1
a.pop(mi)
p.pop(mi)
print(len(a))
print(" ".join(map(str, a)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
n = int(input())
t = list(map(int, input().split()))
k = t.count(1)
s = " ".join("1" * k)
p = [0] + [1, 0] * 1000000
for i in range(3, 1415, 2):
if p[i]:
p[i * i :: 2 * i] = [0] * ((2000000 - i * i) // 2 // i + 1)
if k > 1:
for q in t:
if q > 1 and p[1 + q]:
exit(print(k + 1, q, s))
exit(print(k, s))
for i in range(n):
for j in range(i + 1, n):
if p[t[i] + t[j]]:
exit(print(2, t[i], t[j]))
print(1, t[0])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL STRING BIN_OP STRING VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP LIST NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
def isPrime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i = i + 6
return True
n = int(input())
arr = list(map(int, input().split()))
count = {}
for i in arr:
try:
count[i] += 1
except KeyError:
count[i] = 1
numbers = list(count.keys())
numbers.sort()
a, b = -1, -1
flag = False
for i in range(len(numbers) - 1):
for j in range(i + 1, len(numbers)):
if isPrime(numbers[i] + numbers[j]):
a = numbers[i]
b = numbers[j]
flag = True
break
if flag:
break
if a == b and a == -1:
if numbers[0] == 1 and count[1] > 1:
print(count[1])
for i in range(count[1]):
print(1, end=" ")
print()
else:
print(1)
print(numbers[0])
elif a == 1:
print(count[1] + 1)
for i in range(count[1]):
print(1, end=" ")
print(b)
elif numbers[0] == 1 and count[1] > 2:
print(count[1])
for i in range(count[1]):
print(1, end=" ")
print()
else:
print(2)
print(a, b)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
def main():
input()
l0, l1, ones = [], [], 0
for a in map(int, input().split()):
if a == 1:
ones += 1
else:
(l1 if a & 1 else l0).append(a)
seive = [False, True] * (((max(l0) if l0 else 0) + (max(l1) if l1 else 0)) // 2 + 1)
a = len(seive)
for i in range(3, int(a**0.5) + 1, 2):
if seive[i]:
for j in range(i * i, a, i):
seive[j] = False
if ones:
res = ["1"] * ones
for a in l0:
if a > 1 and seive[a + 1]:
res.append(str(a))
break
if len(res) > 1:
print(len(res))
print(" ".join(res))
return
for a in l1:
for b in l0:
if seive[a + b]:
print(2)
print(a, b)
return
print(1)
print(1 if ones else (l0 if l0 else l1)[0])
def __starting_point():
main()
__starting_point()
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
n = int(input())
L = list(map(int, input().split()))
P = [(-1) for _ in range(2000001)]
def premier(n):
if P[n] >= 0:
return P[n]
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
P[n] = False
return False
P[n] = True
return True
e = L.count(1)
if n == 1:
print(1)
print(L[0])
elif e > 1:
L.sort()
i = 1
while i < n and L[i] == 1:
i += 1
u = i
ok = 0
while i < n:
if premier(L[i] + 1):
print(u + 1)
for j in range(u):
print(1, end=" ")
print(L[i])
ok = 1
break
i += 1
if ok == 0:
print(u)
for i in range(u):
print(1, end=" ")
else:
ok = 0
for i in range(n - 1):
for j in range(i + 1, n):
t = premier(L[i] + L[j])
if t:
print(2)
print(str(L[i]) + " " + str(L[j]))
ok = 1
break
if ok:
break
if ok == 0:
print(1)
print(L[0])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
A tuple of positive integers {x_1, x_2, ..., x_{k}} is called simple if for all pairs of positive integers (i, j) (1 β€ i < j β€ k), x_{i} + x_{j} is a prime.
You are given an array a with n positive integers a_1, a_2, ..., a_{n} (not necessary distinct). You want to find a simple subset of the array a with the maximum size.
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Let's define a subset of the array a as a tuple that can be obtained from a by removing some (possibly all) elements of it.
-----Input-----
The first line contains integer n (1 β€ n β€ 1000) β the number of integers in the array a.
The second line contains n integers a_{i} (1 β€ a_{i} β€ 10^6) β the elements of the array a.
-----Output-----
On the first line print integer m β the maximum possible size of simple subset of a.
On the second line print m integers b_{l} β the elements of the simple subset of the array a with the maximum size.
If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
-----Examples-----
Input
2
2 3
Output
2
3 2
Input
2
2 2
Output
1
2
Input
3
2 1 1
Output
3
1 1 2
Input
2
83 14
Output
2
14 83
|
def primes_upto(limit):
is_prime = [False] * 2 + [True] * (limit - 1)
for n in range(int(limit**0.5 + 1.5)):
if is_prime[n]:
for i in range(n * n, limit + 1, n):
is_prime[i] = False
return [i for i, prime in enumerate(is_prime) if prime]
check = set(primes_upto(2 * 10**6 + 500))
n = int(input())
arr = list(map(int, input().split()))
one_present = False
cnt_ones = 0
for i in arr:
if i == 1:
one_present = True
cnt_ones += 1
num1, num2, prime = 0, 0, 0
for i in range(n):
for j in range(n):
if one_present:
if cnt_ones > 1:
if (
arr[i] + arr[j] in check
and arr[i] + 1 in check
and arr[j] + 1 in check
and arr[i] != 1
and arr[j] != 1
):
num1 = arr[i]
num2 = arr[j]
if arr[i] + 1 in check and arr[i] != 1:
num1 = arr[i]
if arr[i] in check:
prime = arr[i]
else:
if arr[i] + arr[j] in check and arr[i] != 1 and arr[j] != 1:
num1 = arr[i]
num2 = arr[j]
if arr[i] + 1 in check and arr[i] != 1:
num1 = arr[i]
if arr[i] in check:
prime = arr[i]
else:
if arr[i] + arr[j] in check:
num1 = arr[i]
num2 = arr[j]
if arr[i] in check:
prime = arr[i]
if one_present:
if cnt_ones > 1:
if num2 == 0:
if num1 == 0:
print(cnt_ones)
for i in range(cnt_ones):
print(1, end=" ")
else:
print(cnt_ones + 1)
for i in range(cnt_ones):
print(1, end=" ")
print(num1, end=" ")
else:
print(cnt_ones + 2)
for i in range(cnt_ones):
print(i, end=" ")
print(num1, end=" ")
print(num2, end=" ")
elif num2 == 0:
if num1 == 0:
print(1)
print(1)
else:
print(2)
print("1 " + str(num1))
else:
print(2)
print(str(num1) + " " + str(num2))
elif num1 == 0:
if prime == 0:
print(1)
print(arr[0])
else:
print(1)
print(prime)
else:
print(2)
print(str(num1) + " " + str(num2))
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = input()
b = input()
changes = []
for i in range(n):
if a[i] != b[i]:
changes.append(i)
k = len(changes)
if k % 2 == 1:
print(-1)
continue
start = 0
end = k - 1
if not k:
print(0)
continue
if len(changes) > 2:
print(len(changes) // 2 * y)
continue
if changes[1] - changes[0] == 1:
if x > 2 * y:
if n > 4:
print(2 * y)
elif n == 4 and changes[0] != 1:
print(2 * y)
else:
print(x)
else:
print(x)
else:
print(y)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for _ in range(t):
n, x, y = map(int, input().split())
a = input()
b = input()
poss = 0
for j in range(n):
if a[j] != b[j]:
poss += 1
if poss % 2 != 0:
print(-1)
continue
if poss == 0:
print(0)
elif poss > 2:
print(y * (poss // 2))
elif poss == 2:
cons = False
for j in range(1, n):
if a[j] != b[j] and a[j - 1] != b[j - 1]:
cons = True
break
if cons:
print(min(x, 2 * y))
else:
print(y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
tasks = int(input())
for t in range(tasks):
n, x, y = list(map(int, input().split()))
a = input()
b = input()
diff = [i for i in range(n) if a[i] != b[i]]
if len(diff) % 2 != 0:
print(-1)
elif len(diff) != 2:
print(y * len(diff) // 2)
elif diff[0] + 1 != diff[1]:
print(y)
elif x <= 2 * y:
print(x)
elif n <= 3 or n == 4 and diff[0] == 1 and diff[1] == 2:
print(x)
else:
print(2 * y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for _ in range(t):
n, x, y = map(int, input().split())
a = list(input())
b = list(input())
mis = set()
for i in range(n):
a[i] = int(a[i])
b[i] = int(b[i])
if a[i] != b[i]:
mis.add(i)
if x >= y * 2:
better_y = True
else:
better_y = False
if len(mis) % 2 == 1:
print(-1)
else:
ans = 0
if better_y:
if len(mis) == 2:
left = mis.pop()
right = mis.pop()
if abs(left - right) == 1:
ans = 2 * y
else:
ans = y
else:
ans += y * len(mis) // 2
elif len(mis) == 2:
left = mis.pop()
right = mis.pop()
if abs(left - right) == 1:
ans = x
else:
ans = y
else:
ans += y * len(mis) // 2
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
testcases = int(input())
while testcases > 0:
n, x, y = [int(x) for x in input().split()]
array = []
string1 = input()
string2 = input()
for i in range(len(string1)):
if string1[i] != string2[i]:
array.append(i)
if len(array) % 2 != 0:
print("-1")
else:
count = len(array)
if count > 2:
print(int(y * count / 2))
elif count == 0:
print("0")
elif int(array[0]) - int(array[1]) not in [1, -1]:
print(y)
elif 2 * y < x and n > 2:
print(2 * y)
else:
print(x)
testcases -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def f():
n, x, y = map(int, input().split())
a = input()
b = input()
C = 0
CG = 0
for i in range(n - 1):
if a[i] != b[i] and a[i + 1] != b[i + 1]:
C += 1
i += 1
for i in range(n):
if a[i] != b[i]:
CG += 1
if CG % 2:
print(-1)
return
if C == 1 and CG == 2:
if n == 2:
print(x)
elif 2 * y < x:
print(2 * y)
else:
print(x)
else:
temp = CG // 2
print(temp * y)
t = int(input())
while t:
f()
t -= 1
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = input().strip()
b = input().strip()
ao = a.count("1")
bo = b.count("1")
if bo & 1 != ao & 1:
print(-1)
continue
c = []
for i in range(n):
if a[i] != b[i]:
c.append(i)
s = 0
if len(c) == 2 and c[0] + 1 == c[1]:
if x > y * 2:
s = y * 2
else:
s = x
else:
s = y * (len(c) // 2)
print(s)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for mak in range(int(input())):
n, a, b = map(int, input().split())
Flag = 0
s = input()
p = input()
m = []
for i in range(n):
if s[i] != p[i]:
m.append(i)
if len(m) % 2 == 0:
has = len(m)
if has == 0:
print(0)
Flag += 2
elif has == 2:
if abs(m[1] - m[0]) == 1:
print(min(a, 2 * b))
else:
Flag += 3
print(b)
else:
print(has // 2 * b)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = input()
b = input()
yo = []
for i in range(n):
if a[i] != b[i]:
yo.append(i)
if len(yo) % 2:
print(-1)
elif len(yo) == 2:
if yo[1] == yo[0] + 1:
print(min(x, 2 * y))
else:
print(y)
else:
print(len(yo) // 2 * y)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def solve():
n, x, y = [int(i) for i in input().split()]
a, b = input(), input()
q = 0
w = []
for i in range(n):
if a[i] != b[i]:
q += 1
w.append(i)
if q % 2 != 0:
return -1
if q == 0:
return 0
if q != 2 or w[0] + 1 != w[1]:
return q // 2 * y
return min(y * 2, x)
t = int(input())
ans = []
while t:
ans.append(str(solve()))
t -= 1
print("\n".join(ans))
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def solve():
[n, x, y] = [int(x) for x in input().split()]
a = input()
b = input()
arr = []
count = 0
count_idx = []
for idx in range(n):
if a[idx] == b[idx]:
arr.append(0)
else:
arr.append(1)
count += 1
count_idx.append(idx)
if count == 0:
print(0)
return
if count % 2 == 1:
print(-1)
return
if count == 2:
if count_idx[0] == count_idx[-1] - 1:
print(min(x, 2 * y))
return
print(y)
return
p = 0
if y <= x:
print(count // 2 * y)
return
id = 1
while id < n:
if arr[id - 1] == 1 and arr[id] == 1:
p += 1
id += 2
continue
id += 1
print((count // 2 - p) * y + p * x)
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN ASSIGN VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
import sys
input = sys.stdin.readline
def solve():
n, x, y = map(int, input().split())
A = input().strip()
B = input().strip()
diff = []
for i in range(n):
if A[i] != B[i]:
diff.append(i)
m = len(diff)
if m % 2:
return -1
elif m == 2:
return y if diff[0] + 1 < diff[1] else min(2 * y, x)
else:
return y * (m // 2)
for _ in range(int(input())):
print(solve())
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = list(map(int, input().split()))
a = list(input())
b = list(input())
n_d = 0
r = 0
d = []
for i in range(n):
if a[i] != b[i]:
d.append(i)
n_d += 1
if n_d % 2 == 0:
if n_d == 2 and d[1] - d[0] == 1:
r += min(x, y * 2)
else:
r += y * (len(d) // 2)
print(r)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input().strip())
def solve(n, x, y, a, b):
re = 0
cab = a.count("1") + b.count("1")
place = []
k = 0
if cab % 2 == 1:
return -1
cab = 0
for i in range(n):
if a[i] != b[i]:
if a[i] == "1":
cab += 1
if b[i] == "1":
cab += 1
k += 1
if len(place) < 2:
place.append(i)
if k == 2:
if cab == 2 and place[1] - place[0] == 1:
return min(x, 2 * y)
return int(k / 2) * y
for _ in range(t):
n, x, y = map(int, input().split(" "))
a = list(input())
b = list(input())
print(solve(n, x, y, a, b))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for i in range(t):
n, x, y = map(int, input().split(" "))
a = [int(i) for i in input()]
b = [int(i) for i in input()]
sum = 0
flag = 0
found = 0
for i in range(n):
if a[i] - b[i] != 0:
sum += 1
if flag == 1:
found = 1
else:
flag = 1
else:
flag = 0
if sum % 2 == 1:
print("-1")
continue
if sum == 2 and found == 1:
if x > 2 * y:
print(2 * y)
else:
print(x)
elif sum == 2 and found == 0:
print(y)
else:
print(int(sum / 2 * y))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for i in range(t):
l0 = input().split()
n, x, y = int(l0[0]), int(l0[1]), int(l0[2])
a = input()
b = input()
con = 0
l = []
for j in range(n):
if a[j] != b[j]:
l.append(j)
con += 1
if con == 0:
print(0)
elif con % 2 == 1:
print(-1)
else:
if con == 2:
if l[1] - l[0] == 1:
cost = min(2 * y, x)
else:
cost = y
else:
cost = con // 2 * y
print(cost)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for i in range(t):
n, x, y = map(int, input().split())
a = input()
b = input()
k = list()
r = 0
for j in range(n):
if a[j] != b[j]:
k.append(j)
if len(k) % 2 != 0:
print(-1)
else:
for f in range(0, len(k), 2):
if x < y or len(k) == 2:
if k[f + 1] - k[f] == 1:
r += min(y * 2, x)
else:
r += y
else:
r += y
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
while t > 0:
ip = [int(x) for x in input().split()]
n = ip[0]
x = ip[1]
y = ip[2]
s1 = input()
s2 = input()
count = 0
for i in range(n):
if s1[i] != s2[i]:
count += 1
if count % 2 == 1:
print(-1)
elif count == 0:
print(0)
elif count <= 2 and n == 2:
print(x)
elif count <= 2:
for i in range(n):
if s1[i] != s2[i]:
if s1[i + 1] != s2[i + 1]:
print(min(x, 2 * y))
else:
print(y)
break
else:
print(y * (count // 2))
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for i in range(int(input())):
n, x, y = map(int, input().split())
a = input()
b = input()
ch1 = a.count("1")
ch2 = b.count("1")
if abs(ch1 - ch2) % 2 == 0:
j = 0
sum = 0
while j < n:
if a[j] != b[j]:
sum += 1
j += 1
if sum > 2:
print(int(sum // 2 * y))
elif sum == 2:
values = []
p = 0
while p < n:
if a[p] != b[p]:
values.append(p)
p += 1
if values[1] - values[0] == 1:
print(min(2 * y, x))
else:
print(y)
else:
print(0)
else:
print(-1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def main():
for _ in range(int(input())):
n, x, y = map(int, input().split())
a, b = input(), input()
ls = []
for i in range(n):
if a[i] != b[i]:
ls.append(i)
if len(ls) % 2 == 1:
print(-1)
continue
if len(ls) == 2:
if ls[1] - ls[0] > 1:
print(y)
else:
print(min(x, y * 2))
else:
print(y * (len(ls) // 2))
main()
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
x, y = max(x, y), min(x, y)
a = input()
b = input()
s = []
ans = 0
for i in range(n):
if a[i] != b[i]:
ans += 1
s.append(i)
if ans & 1 == 1:
print(-1)
elif ans == 2 and s[1] - s[0] == 1:
print(min(x, y * 2))
else:
print(ans // 2 * y)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = input()
b = input()
p = 0
q = 0
for i in range(n):
if a[i] == "1" and b[i] == "0":
p += 1
elif a[i] == "0" and b[i] == "1":
q += 1
if (p + q) % 2:
print(-1)
else:
if p + q == 2:
ans = 0
count = 0
flag = 0
for i in range(n - 1):
if a[i] != b[i] and a[i + 1] != b[i + 1]:
if x > 2 * y:
ans = 2 * y
else:
ans = x
flag = 1
break
if flag == 0:
ans = y
else:
ans = (p + q) // 2 * y
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for _ in range(t):
n, x, y = map(int, input().split())
A = list(input())
B = list(input())
d = 0
for i in range(n):
if A[i] != B[i]:
d += 1
if d == 0:
print(0)
continue
if d % 2 != 0:
print(-1)
else:
if d == n == 2:
print(x)
if d == 2:
c = 0
for i in range(n - 1):
if A[i] != B[i] and A[i + 1] != B[i + 1]:
c = 1
break
if c and n == 3:
print(x)
elif c and n > 3:
if x >= 2 * y:
print(2 * y)
else:
print(x)
else:
print(y)
else:
print(d * y // 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = eval(input())
for i in range(t):
n, x, y = map(int, input().split())
a = input()
b = input()
ind = []
for i in range(n):
if a[i] != b[i]:
ind.append(i)
if len(ind) % 2 == 1:
print(-1)
else:
l = len(ind)
if l != 2 or ind[0] + 1 != ind[1]:
print(y * l // 2)
else:
print(min(x, 2 * y))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = int(input(), 2)
b = a ^ int(input(), 2)
c = bin(b)[2:].count("1")
if c % 2:
print(-1)
elif c == 2 and b & b << 1:
print(min(2 * y, x))
else:
print(y * c // 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def solve():
n, x, y = [int(x) for x in input().split()]
a = input()
b = input()
ind = []
for i in range(n):
if a[i] != b[i]:
ind.append(i)
if len(ind) % 2:
return -1
if len(ind) == 2:
if ind[0] + 1 == ind[1]:
if n == 2 or n == 3:
return x
elif n == 4:
if ind[0] == 1:
return x
else:
return min(2 * y, x)
else:
return min(2 * y, x)
return y * len(ind) // 2
t = int(input())
while t:
print(solve())
t -= 1
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER IF VAR NUMBER NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP NUMBER VAR VAR RETURN FUNC_CALL VAR BIN_OP NUMBER VAR VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def miis():
return map(int, input().split())
for _ in range(int(input())):
n, x, y = miis()
a = list(map(int, list(input())))
b = list(map(int, list(input())))
sma = sum(a)
smb = sum(b)
if (n - sum(a)) % 2 != (n - sum(b)) % 2:
print(-1)
continue
ans = 0
f = []
for i in range(n):
if a[i] != b[i]:
f.append(i)
if len(f) == 2 and f[1] - f[0] == 1:
ans += min(2 * y, x)
else:
ans += y * len(f) // 2
print(ans)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
testcases = int(input())
for i in range(testcases):
input_1 = input().split()
[n, x, y] = list(map(int, input_1))
input_2 = input()
a_list = list(map(int, [*input_2]))
input_3 = input()
b_list = list(map(int, [*input_3]))
n_diff = 0
cons = False
diff_last = 0
for j in range(n):
diff = abs(a_list[j] - b_list[j])
if diff == 1:
n_diff += 1
if diff_last == 1:
cons = True
diff_last = 1
else:
diff_last = 0
if n_diff % 2 == 1:
print(-1)
elif n_diff == 2 and cons == True:
print(min(x, 2 * y))
else:
print(n_diff // 2 * y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for _ in range(t):
nxy = [int(i) for i in input().split()]
n, x, y = nxy[0], nxy[1], nxy[2]
a = [int(i) for i in input()]
b = [int(i) for i in input()]
if a == b:
print(0)
continue
k, c = 0, 0
for i in range(n):
if a[i] != b[i]:
k += 1
c = i
if k % 2 == 1:
print(-1)
continue
if k != 2:
print(y * k // 2)
continue
if a[c - 1] == b[c - 1]:
print(y)
continue
if x <= 2 * y:
print(x)
continue
if n <= 3:
print(x)
continue
if n == 4 and c == 2:
print(min(x, 3 * y))
print(2 * y)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def get_numbers_list(string_list):
string_split_list = string_list.split()
number_list = []
for element in string_split_list:
number_list.append(int(element))
return number_list
def main():
t = int(input())
for i in range(t):
n, x, y = map(int, input().split())
a = int(input(), 2)
b = a ^ int(input(), 2)
c = bin(b).count("1")
if c % 2:
print(-1)
elif c == 2 and b & b << 1:
print(min(2 * y, x))
else:
print(y * c // 2)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for i in range(int(input())):
n, x, y = input().split(" ")
n, x, y = int(n), int(x), int(y)
a = input()
b = input()
arr = []
p = 0
for i in range(n):
if a[i] != b[i]:
arr.append(i)
p += 1
if p % 2:
print(-1)
continue
if p == 2 and n >= 5 and arr[0] == arr[1] - 1:
print(min(x, 2 * y))
elif p == 2 and n == 2 or n == 3 and arr[0] == arr[1] - 1:
print(x)
elif p == 2 and arr[0] == arr[1] - 1:
if arr == [1, 2]:
print(x)
else:
print(min(x, 2 * y))
else:
print(y * p // 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for i in range(t):
n, x, y = map(int, input().split(" "))
a = input()
b = input()
c = list(map(lambda x: x[0] != x[1], zip(a, b)))
if sum(c) % 2 == 1:
print(-1)
elif sum(c) == 0:
print(0)
elif n == 2:
print(x)
elif n == 3:
if c[1]:
print(x)
else:
print(min(2 * x, y))
elif n == 4:
if sum(c) == 4:
print(min(2 * y, 2 * x))
elif c[1] and c[2]:
print(min(x, 3 * y))
else:
print(min(x, 2 * y))
elif sum(c) == 2:
bb = False
for j1, j2 in zip(c, c[1:]):
if j1 and j2:
bb = True
if bb:
print(min(x, 2 * y))
else:
print(min(y, x))
else:
print(y * (sum(c) // 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for test in range(t):
n, x, y = map(int, input().split())
a = list(map(int, input()))
b = list(map(int, input()))
if a[0] != b[0]:
if a[1] != b[1]:
cnt = 2
ld = 1
else:
cnt = 1
ld = 0
elif a[1] != b[1]:
cnt = 1
ld = 0
else:
cnt = 0
ld = 0
for i in range(2, n):
if a[i] != b[i]:
cnt += 1
if a[i - 1] != b[i - 1] and a[i - 2] == b[i - 2]:
ld += 1
if cnt % 2 == 1:
print(-1)
continue
if ld == 1 and cnt == 2:
if y * 2 > x:
print(x)
else:
print(y * 2)
else:
print(y * (cnt // 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def func():
n, x, y = map(int, input().split())
a = input()
b = input()
diff = []
for i in range(n):
if a[i] != b[i]:
diff.append(i)
if x > 2 * y:
x = 2 * y
if len(diff) % 2 == 1:
print(-1)
return
elif len(diff) == 0:
print(0)
return
elif len(diff) == 2:
if diff[0] + 1 == diff[1]:
print(x)
else:
print(y)
return
else:
print(len(diff) // 2 * y)
return
n_tests = int(input())
for i in range(n_tests):
func()
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
l1 = [int(z) for z in list(input())]
l2 = [int(z) for z in list(input())]
changes = 0
changes_ind = []
out = 0
for v in range(n):
if l1[v] != l2[v]:
changes += 1
changes_ind.append(v)
if changes % 2:
print(-1)
continue
if not changes:
print(0)
continue
changes_ind_len = len(changes_ind)
if changes_ind_len == 2 and abs(changes_ind[0] - changes_ind[1]) == 1:
out = min(x, 2 * y)
else:
out = changes_ind_len // 2 * y
print(out)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
for _ in range(int(input())):
n, x, y = map(int, input().split())
a = input()
b = input()
c = ""
k = min(x, 2 * y)
for i in range(n):
if a[i] == b[i]:
c += "0"
else:
c += "1"
if c.count("1") % 2:
print(-1)
elif c.count("1") == 0:
print(0)
else:
d = c.count("1")
l = c.index("1")
c1 = c[::-1]
r = n - c1.index("1") - 1
if d == 2:
if r - l == 1:
print(min(x, 2 * y))
else:
print(min((r - l) * x, y))
else:
print(y * d // 2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR STRING VAR STRING IF BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
def cal():
if len(p) == 0:
return 0
if len(p) == 2:
if p[1] == p[0] + 1:
return min(x, 2 * y)
else:
return min(y, x * (p[1] - p[0]))
return len(p) // 2 * y
for jj in range(int(input())):
n, x, y = [int(i) for i in input().split()]
a = input()
b = input()
p = []
for i in range(n):
if a[i] != b[i]:
p.append(i)
if len(p) % 2 == 1:
print(-1)
else:
print(cal())
|
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR BIN_OP NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
t = int(input())
for _ in range(t):
n, x, y = map(int, input().split())
a = input()
b = input()
c = [0] * n
count = 0
last_occurence = -1
for i in range(n):
if a[i] != b[i]:
c[i] = 1
count += 1
last_occurence = i
if count % 2 != 0:
print(-1)
elif count == 2:
if c[last_occurence - 1] == 1:
if 2 * y < x and n >= 4:
print(2 * y)
else:
print(x)
else:
print(y)
else:
print(y * (count // 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER
|
This is the easy version of the problem. In this version, $n \le 3000$, $x \ge y$ holds. You can make hacks only if both versions of the problem are solved.
You are given two binary strings $a$ and $b$, both of length $n$. You can do the following operation any number of times (possibly zero).
Select two indices $l$ and $r$ ($l < r$).
Change $a_l$ to $(1 - a_l)$, and $a_r$ to $(1 - a_r)$.
If $l + 1 = r$, the cost of the operation is $x$. Otherwise, the cost is $y$.
You have to find the minimum cost needed to make $a$ equal to $b$ or say there is no way to do so.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 600$) β the number of test cases.
Each test case consists of three lines. The first line of each test case contains three integers $n$, $x$, and $y$ ($5 \le n \le 3000$, $1 \le y \le x \le 10^9$) β the length of the strings, and the costs per operation.
The second line of each test case contains the string $a$ of length $n$. The string only consists of digits $0$ and $1$.
The third line of each test case contains the string $b$ of length $n$. The string only consists of digits $0$ and $1$.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $3000$.
-----Output-----
For each test case, if there is no way to make $a$ equal to $b$, print $-1$. Otherwise, print the minimum cost needed to make $a$ equal to $b$.
-----Examples-----
Input
4
5 8 7
01001
00101
5 7 2
01000
11011
7 8 3
0111001
0100001
5 10 1
01100
01100
Output
8
-1
6
0
-----Note-----
In the first test case, selecting indices $2$ and $3$ costs $8$, which is the minimum possible cost.
In the second test case, we cannot make $a$ equal to $b$ using any number of operations.
In the third test case, we can perform the following operations:
Select indices $3$ and $6$. It costs $3$, and $a$ is 0101011 now.
Select indices $4$ and $6$. It costs $3$, and $a$ is 0100001 now.
The total cost is $6$.
In the fourth test case, we don't have to perform any operations.
|
R = lambda: map(int, input().split())
(t,) = R()
for k in range(t):
n, x, y = R()
a = input()
b = input()
indices = []
for i in range(len(a)):
if a[i] != b[i]:
indices.append(i)
length = len(indices)
if length == 0:
print(0)
elif length % 2 != 0:
print(-1)
elif length == 2:
if indices[0] == indices[1] + -1:
if x > 2 * y and (indices[1] + 3 <= n or indices[0] >= 2):
print(2 * y)
else:
print(x)
else:
print(y)
else:
print(length // 2 * y)
|
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
def input():
return sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
some_val_equal_x = False
some_val_not_equal_x = False
[n, x] = list(map(int, input().split()))
arr = list(map(int, input().split()))
totalDiff = 0
for val in arr:
totalDiff += val - x
if val == x:
some_val_equal_x = True
else:
some_val_not_equal_x = True
if some_val_not_equal_x == False:
print(0)
elif totalDiff == 0 or some_val_equal_x == True:
print(1)
else:
print(2)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for t in range(int(input())):
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
b = True
c = False
ans = 2
if sum(a) / n == x:
ans = 1
for i in a:
if i != x:
b = False
if i == x:
c = True
if c:
ans = 1
if b:
ans = 0
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if x in a and max(a) == min(a):
print(0)
elif x in a or sum(a) / n == x:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for you in range(t):
l = input().split()
n = int(l[0])
x = int(l[1])
l = input().split()
li = [int(i) for i in l]
poss = 1
for i in li:
if i != x:
poss = 0
break
if poss:
print(0)
continue
poss = 0
for i in li:
if i == x:
poss = 1
break
if poss:
print(1)
continue
z = sum(li)
if z == n * x:
print(1)
continue
print(2)
|
ASSIGN VAR FUNC_CALL 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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
l = [int(i) for i in input().split()][:n]
s = list(set(l))
if len(s) == 1 and s[0] == x:
print(0)
else:
cnt = sum(l)
if cnt == n * x or l.count(x) > 0:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
lis = list(map(int, input().split()))
lo = 0
up = 0
for i in lis:
if i < x:
lo += x - i
elif i > x:
up += i - x
if lo == 0 and up == 0:
print(0)
elif lo == up and lo > 0 or x in lis:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
def main():
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
a = list(map(int, input().split()))
case_0 = True
for i in a:
if i != x:
case_0 = False
break
if case_0:
print(0)
continue
case_1_base = False
for j in a:
if j == x:
case_1_base = True
break
if case_1_base:
print(1)
continue
total_diff = 0
for k in a:
total_diff += k - x
if total_diff == 0:
print(1)
else:
print(2)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
input = sys.stdin.buffer.readline
def solution():
n, x = map(int, input().split())
l = list(map(int, input().split()))
if l.count(x) == n:
print(0)
elif l.count(x) > 0:
print(1)
else:
s = 0
for i in range(n):
s += x - l[i]
if s == 0:
print(1)
else:
print(2)
t = int(input())
for _ in range(t):
solution()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
def main():
n, x = map(int, input().split())
lst = list(map(int, input().split()))
all_x = True
one = False
sm = 0
for i in lst:
if i != x:
all_x = False
if i == x:
one = True
sm += i - x
if all_x:
print(0)
elif sm != 0 and not one:
print(2)
else:
print(1)
t = int(input())
for i in range(t):
main()
|
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
while t > 0:
t -= 1
n, k = input().split()
n, k = int(n), int(k)
lt = [int(o) for o in input().split()]
c = 0
for i in lt:
if i == k:
c += 1
if c == n:
print(0)
elif sum(lt) / n == k or c > 0:
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
n, x = map(int, input().split())
v = [(x - int(i)) for i in input().split()]
v.sort()
if set(v) == {0}:
print(0)
elif sum(v) == 0 or 0 in v:
print(1)
else:
print(2)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return map(int, sys.stdin.readline().rstrip().split())
def LI():
return list(map(int, sys.stdin.readline().rstrip().split()))
t = I()
for _ in range(t):
n, x = MI()
A = LI()
b = sum(A[i] == x for i in range(n))
if b == n:
print(0)
continue
if sum(A) == n * x:
print(1)
continue
if b >= 1:
print(1)
continue
print(2)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
ansl = []
for _ in range(int(input())):
n, x = map(int, input().split())
al = list(map(int, input().split()))
al.sort()
if al[0] == x and al[-1] == x:
ansl.append(0)
continue
if x * n == sum(al):
ansl.append(1)
elif x in al:
ansl.append(1)
else:
ansl.append(2)
for a in ansl:
print(a)
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
T = int(input())
for _ in range(0, T):
n, kk = map(int, input().split())
s = [int(x) for x in input().split()]
arr = list(set(s))
if len(arr) == 1 and s[0] == kk:
print(0)
else:
temp = 0
for i in range(0, len(s)):
if s[i] == kk:
temp = 1
tot = 0
for i in range(0, len(s)):
tot += s[i] - kk
if tot == 0 or temp == 1:
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
n, inf = list(map(int, stdin.readline().split()))
a = list(map(int, stdin.readline().split()))
diff = [(inf - v) for v in a]
flag = sm = 0
for v in diff:
if v != 0:
flag = 1
sm += v
if flag == 0:
print(0)
elif inf in a or flag == 1 and sm == 0:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, x = map(int, input().split())
arr = list(map(int, input().split()))
_sum = 0
if arr.count(x) == len(arr):
print(0)
continue
for i in arr:
_sum += x - i
if _sum == 0 or arr.count(x) > 0:
print(1)
else:
print(2)
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
l = list(map(int, input().split()))
f1, f2 = 0, 0
for i in range(n):
if l[i] == x:
f1 = 1
else:
f2 = 1
if f1 == 1 and f2 == 0:
print(0)
elif f1 == 1 and f2 == 1:
print(1)
elif f1 == 0 and f2 == 1:
if sum(l) == x * n:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
rl = lambda: list(map(int, input().split()))
rn = lambda: int(input())
rns = lambda: map(int, input().split())
for _ in range(rn()):
n, k = rns()
l = rl()
if l.count(k) == n:
print(0)
elif l.count(k) > 0 or sum([(k - i) for i in l]) == 0:
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
def input():
return sys.stdin.readline()[:-1]
def getInt():
return int(input())
def getIntIter():
return map(int, input().split())
def getIntList():
return list(getIntIter())
def flush():
sys.stdout.flush()
for _ in range(getInt()):
n, x = getIntIter()
nums = getIntList()
if nums == [x] * n:
print(0)
elif sum(nums) % n == 0 and sum(nums) // n == x or x in nums:
print(1)
else:
print(2)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP LIST VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
def killJoy(x, n, ratings):
initialInfection = 0
for rating in ratings:
if rating == x:
initialInfection += 1
if initialInfection == n:
return 0
if initialInfection >= 1:
return 1
summ = sum(ratings)
if summ == x * n:
return 1
return 2
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
ratings = list(map(int, input().split()))
print(killJoy(x, n, ratings))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
rate_change = 0
n, x = map(int, input().split())
acc = list(map(int, input().split()))
acc1 = []
for i in acc:
if i != x:
acc1.append(i)
if not acc1:
print(0)
continue
if len(acc1) < n:
print(1)
continue
for i in acc1:
rate_change += i - x
if rate_change == 0:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
[
(
lambda N, R, n: (
lambda a, b, c: print(0 if a == b == 0 else 1 if a == b or c else 2)
)(
sum(R - i for i in n if i < R),
sum(i - R for i in n if i > R),
sum(1 for i in n if i == R),
)
)(*map(int, input().split()), list(map(int, input().split())))
for t in range(int(input()))
]
|
EXPR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
A = list(map(int, input().split()))
if sum(A) == n * k:
for a in A:
if a != k:
print(1)
break
else:
print(0)
elif k in A:
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for i in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
c = 0
sumo = 0
for j in range(n):
if a[j] == x:
c = c + 1
sumo = sumo + a[j] - x
if c == n:
print("0")
elif c >= 1 and c < n:
print("1")
elif sumo == 0:
print("1")
else:
print("2")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
def solve():
n, x = map(int, input().split())
A = list(map(int, input().split()))
assert len(A) == n
diff = [(x - xx) for xx in A]
if sum(diff) == 0:
for x in diff:
if x != 0:
return 1
return 0
for x in diff:
if x == 0:
return 1
return 2
for _ in range(t):
print(solve())
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
def main():
n, vir = map(int, input().split(" "))
grade = [i for i in map(int, input().split(" "))]
if grade.count(vir) == n:
return 0
elif vir in grade and sum(grade) != vir * n:
return 1
elif sum(grade) == vir * n:
return 1
else:
return 2
n = int(input())
res = []
for i in range(n):
res.append(main())
for i in res:
print(i)
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
def solve(n, x, ar):
flag = False
for i in range(n):
if ar[i] == x:
continue
else:
flag = True
break
if flag == False:
print(0)
else:
found = False
sumi = 0
for i in range(n):
if ar[i] == x:
found = True
sumi += ar[i] - x
if sumi == 0 or found is True:
print(1)
else:
print(2)
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
ar = list(map(int, input().split()))
solve(n, x, ar)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for case in range(t):
n, x = [int(s) for s in input().split(" ")]
a = [int(s) for s in input().split(" ")]
if set(a) == set([x]):
ans = 0
elif sum([(b - x) for b in a]) == 0 or x in a:
ans = 1
else:
ans = 2
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
l = list(map(int, input().split()))
print((0, 2 - (x in l or sum(l) == x * n))[l != [x] * n])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP LIST VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
c = 0
d = a.count(x)
for i in a:
c += x - i
if d == n:
print("0")
elif c == 0 or a.count(x) > 0:
print("1")
else:
print("2")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for i in range(t):
l, r = map(int, input().split())
a = list(map(int, input().split()))
a = [(r - a[j]) for j in range(l)]
p = sum(a)
if p == 0 and len(set(a)) == 1:
print(0)
elif p == 0 or 0 in a:
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
inp = sys.stdin.buffer.readline
inar = lambda: list(map(int, inp().split()))
inin = lambda: int(inp())
inst = lambda: inp().decode().rstrip("\n\r")
_T_ = inin()
for _t_ in range(_T_):
n, x = inar()
a = inar()
if set(a) == {x}:
print(0)
elif sum(a) / n == x:
print(1)
elif a.count(x) > 0:
print(1)
else:
print(2)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for _ in range(t):
n, x = (int(w) for w in input().split(" "))
A = [int(a) for a in input().split(" ")]
if n * x == sum(A):
if all(a == x for a in A):
print(0)
else:
print(1)
elif any(a == x for a in A):
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
N, M = map(int, input().split())
X = list(map(int, input().split()))
if len(set(X)) == 1 and M == X[0]:
print(0)
continue
t = 0
for x in X:
t += M - x
if t == 0:
print(1)
continue
if M in X:
print(1)
continue
print(2)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
def go():
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
diff = [(a[i] - x) for i in range(len(a))]
flag = True
f2 = False
for i in range(len(diff)):
if diff[i] != 0:
flag = False
if diff[i] == 0:
f2 = True
if flag:
print(0)
return
if sum(diff) == 0 or f2:
print(1)
return
print(2)
for tt in range(int(input())):
go()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
sa = sum(a)
ma, mi = max(a), min(a)
yes = x in a
if ma == mi == x:
print(0)
elif yes:
print(1)
elif sa == x * n:
print(1)
else:
print(2)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
for i in range(t):
n, x = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
diff = []
s = 0
for j in range(n):
if x - arr[j] == 0:
s += 1
diff.append(x - arr[j])
a = sum(diff)
if a == 0:
z = arr[0]
y = arr[-1]
if z == y and x == y:
print(0)
else:
print(1)
elif s > 0:
print(1)
else:
print(2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
q = []
for i in range(t):
l = list(input().split())
n = int(l[0])
x = int(l[1])
m = list(map(int, list(input().split())))
if m.count(x) == n:
q.append(0)
elif sum(m) == x * n or m.count(x) > 0:
q.append(1)
else:
q.append(2)
for i in q:
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).
Killjoy's account is already infected and has a rating equal to $x$. Its rating is constant. There are $n$ accounts except hers, numbered from $1$ to $n$. The $i$-th account's initial rating is $a_i$. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.
Contests are regularly held on Codeforces. In each contest, any of these $n$ accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.
Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.
It can be proven that all accounts can be infected in some finite number of contests.
-----Input-----
The first line contains a single integer $t$ $(1 \le t \le 100)$Β β the number of test cases. The next $2t$ lines contain the descriptions of all test cases.
The first line of each test case contains two integers $n$ and $x$ ($2 \le n \le 10^3$, $-4000 \le x \le 4000$)Β β the number of accounts on Codeforces and the rating of Killjoy's account.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ $(-4000 \le a_i \le 4000)$Β β the ratings of other accounts.
-----Output-----
For each test case output the minimal number of contests needed to infect all accounts.
-----Example-----
Input
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
Output
1
0
2
-----Note-----
In the first test case it's possible to make all ratings equal to $69$. First account's rating will increase by $1$, and second account's rating will decrease by $1$, so the sum of all changes will be equal to zero.
In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to $4$.
|
t = int(input())
i = 0
while i < t:
n, k = [int(j) for j in input().split()]
mas = [int(j) for j in input().split()]
flag = [(0) for j in range(len(mas))]
count = 0
for j in range(len(mas)):
if mas[j] == k:
count += 1
flag[j] = 1
if count == len(mas):
print(0)
elif count != 0:
print(1)
else:
sum_prom = 0
for j in range(len(mas) - 1):
sum_prom += k - mas[j]
mas[j] = k
flag[j] = 1
if mas[-1] - sum_prom == k:
print(1)
else:
print(2)
i += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR 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 NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.