description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
After defeating a Blacklist Rival, you get a chance to draw $1$ reward slip out of $x$ hidden valid slips. Initially, $x=3$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $c$, $m$, and $p$, respectively. There is also a volatility factor $v$. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the $x$ valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was $a$. Then,
If the item was a Pink Slip, the quest is over, and you will not play any more races.
Otherwise,
If $a\leq v$, the probability of the item drawn becomes $0$ and the item is no longer a valid item for all the further draws, reducing $x$ by $1$. Moreover, the reduced probability $a$ is distributed equally among the other remaining valid items.
If $a > v$, the probability of the item drawn reduces by $v$ and the reduced probability is distributed equally among the other valid items.
For example,
If $(c,m,p)=(0.2,0.1,0.7)$ and $v=0.1$, after drawing Cash, the new probabilities will be $(0.1,0.15,0.75)$.
If $(c,m,p)=(0.1,0.2,0.7)$ and $v=0.2$, after drawing Cash, the new probabilities will be $(Invalid,0.25,0.75)$.
If $(c,m,p)=(0.2,Invalid,0.8)$ and $v=0.1$, after drawing Cash, the new probabilities will be $(0.1,Invalid,0.9)$.
If $(c,m,p)=(0.1,Invalid,0.9)$ and $v=0.2$, after drawing Cash, the new probabilities will be $(Invalid,Invalid,1.0)$.
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
-----Input-----
The first line of input contains a single integer $t$ ($1\leq t\leq 10$) β the number of test cases.
The first and the only line of each test case contains four real numbers $c$, $m$, $p$ and $v$ ($0 < c,m,p < 1$, $c+m+p=1$, $0.1\leq v\leq 0.9$).
Additionally, it is guaranteed that each of $c$, $m$, $p$ and $v$ have at most $4$ decimal places.
-----Output-----
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$.
Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$.
-----Examples-----
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
-----Note-----
For the first test case, the possible drawing sequences are:
P with a probability of $0.6$;
CP with a probability of $0.2\cdot 0.7 = 0.14$;
CMP with a probability of $0.2\cdot 0.3\cdot 0.9 = 0.054$;
CMMP with a probability of $0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$;
MP with a probability of $0.2\cdot 0.7 = 0.14$;
MCP with a probability of $0.2\cdot 0.3\cdot 0.9 = 0.054$;
MCCP with a probability of $0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$.
So, the expected number of races is equal to $1\cdot 0.6 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 = 1.532$.
For the second test case, the possible drawing sequences are:
P with a probability of $0.4$;
CP with a probability of $0.4\cdot 0.6 = 0.24$;
CMP with a probability of $0.4\cdot 0.4\cdot 1 = 0.16$;
MP with a probability of $0.2\cdot 0.5 = 0.1$;
MCP with a probability of $0.2\cdot 0.5\cdot 1 = 0.1$.
So, the expected number of races is equal to $1\cdot 0.4 + 2\cdot 0.24 + 3\cdot 0.16 + 2\cdot 0.1 + 3\cdot 0.1 = 1.86$. | t = int(input())
ex = 0
def dfs(c, m, p, v, count, curr):
global ex
if p:
ex += curr * count * p
if c > 10**-6:
if c > v:
if m > 10**-6:
dfs(c - v, m + v / 2, p + v / 2, v, count + 1, curr * c)
else:
dfs(c - v, 0, p + v, v, count + 1, curr * c)
elif m > 10**-6:
dfs(0, m + c / 2, p + c / 2, v, count + 1, curr * c)
else:
dfs(0, 0, 1, v, count + 1, curr * c)
if m > 10**-6:
if m > v:
if c > 10**-6:
dfs(c + v / 2, m - v, p + v / 2, v, count + 1, curr * m)
else:
dfs(0, m - v, p + v, v, count + 1, curr * m)
elif c > 10**-6:
dfs(c + m / 2, 0, p + m / 2, v, count + 1, curr * m)
else:
dfs(0, 0, 1, v, count + 1, curr * m)
for _ in range(t):
c, m, p, v = list(map(float, input().rstrip().split()))
ex = 0
dfs(c, m, p, v, 1, 1)
print(ex) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER IF VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER IF VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
After defeating a Blacklist Rival, you get a chance to draw $1$ reward slip out of $x$ hidden valid slips. Initially, $x=3$ and these hidden valid slips are Cash Slip, Impound Strike Release Marker and Pink Slip of Rival's Car. Initially, the probability of drawing these in a random guess are $c$, $m$, and $p$, respectively. There is also a volatility factor $v$. You can play any number of Rival Races as long as you don't draw a Pink Slip. Assume that you win each race and get a chance to draw a reward slip. In each draw, you draw one of the $x$ valid items with their respective probabilities. Suppose you draw a particular item and its probability of drawing before the draw was $a$. Then,
If the item was a Pink Slip, the quest is over, and you will not play any more races.
Otherwise,
If $a\leq v$, the probability of the item drawn becomes $0$ and the item is no longer a valid item for all the further draws, reducing $x$ by $1$. Moreover, the reduced probability $a$ is distributed equally among the other remaining valid items.
If $a > v$, the probability of the item drawn reduces by $v$ and the reduced probability is distributed equally among the other valid items.
For example,
If $(c,m,p)=(0.2,0.1,0.7)$ and $v=0.1$, after drawing Cash, the new probabilities will be $(0.1,0.15,0.75)$.
If $(c,m,p)=(0.1,0.2,0.7)$ and $v=0.2$, after drawing Cash, the new probabilities will be $(Invalid,0.25,0.75)$.
If $(c,m,p)=(0.2,Invalid,0.8)$ and $v=0.1$, after drawing Cash, the new probabilities will be $(0.1,Invalid,0.9)$.
If $(c,m,p)=(0.1,Invalid,0.9)$ and $v=0.2$, after drawing Cash, the new probabilities will be $(Invalid,Invalid,1.0)$.
You need the cars of Rivals. So, you need to find the expected number of races that you must play in order to draw a pink slip.
-----Input-----
The first line of input contains a single integer $t$ ($1\leq t\leq 10$) β the number of test cases.
The first and the only line of each test case contains four real numbers $c$, $m$, $p$ and $v$ ($0 < c,m,p < 1$, $c+m+p=1$, $0.1\leq v\leq 0.9$).
Additionally, it is guaranteed that each of $c$, $m$, $p$ and $v$ have at most $4$ decimal places.
-----Output-----
For each test case, output a single line containing a single real number β the expected number of races that you must play in order to draw a Pink Slip.
Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$.
Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$.
-----Examples-----
Input
4
0.2 0.2 0.6 0.2
0.4 0.2 0.4 0.8
0.4998 0.4998 0.0004 0.1666
0.3125 0.6561 0.0314 0.2048
Output
1.532000000000
1.860000000000
5.005050776521
4.260163673896
-----Note-----
For the first test case, the possible drawing sequences are:
P with a probability of $0.6$;
CP with a probability of $0.2\cdot 0.7 = 0.14$;
CMP with a probability of $0.2\cdot 0.3\cdot 0.9 = 0.054$;
CMMP with a probability of $0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$;
MP with a probability of $0.2\cdot 0.7 = 0.14$;
MCP with a probability of $0.2\cdot 0.3\cdot 0.9 = 0.054$;
MCCP with a probability of $0.2\cdot 0.3\cdot 0.1\cdot 1 = 0.006$.
So, the expected number of races is equal to $1\cdot 0.6 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 + 2\cdot 0.14 + 3\cdot 0.054 + 4\cdot 0.006 = 1.532$.
For the second test case, the possible drawing sequences are:
P with a probability of $0.4$;
CP with a probability of $0.4\cdot 0.6 = 0.24$;
CMP with a probability of $0.4\cdot 0.4\cdot 1 = 0.16$;
MP with a probability of $0.2\cdot 0.5 = 0.1$;
MCP with a probability of $0.2\cdot 0.5\cdot 1 = 0.1$.
So, the expected number of races is equal to $1\cdot 0.4 + 2\cdot 0.24 + 3\cdot 0.16 + 2\cdot 0.1 + 3\cdot 0.1 = 1.86$. | import sys
input = sys.stdin.readline
def dfs(c, m, p, Prob, Try):
Ex = Try * Prob * p
if c < 1e-07:
c = 0
if m < 1e-07:
m = 0
if c and m:
Ex += dfs(
max(0, c - V), m + min(c, V) / 2, p + min(c, V) / 2, Prob * c, Try + 1
)
Ex += dfs(
c + min(m, V) / 2, max(0, m - V), p + min(m, V) / 2, Prob * m, Try + 1
)
elif c:
Ex += dfs(max(0, c - V), 0, p + min(c, V), Prob * c, Try + 1)
elif m:
Ex += dfs(0, max(0, m - V), p + min(m, V), Prob * m, Try + 1)
return Ex
T = int(input())
for _ in range(T):
C, M, P, V = map(float, input().split())
print(dfs(C, M, P, 1, 1)) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | nums = input().split()
numPeople = int(nums[0])
numPairs = int(nums[1])
names = []
for i in range(numPeople):
names.append(input())
pair1 = []
pair2 = []
for i in range(numPairs):
pair = input().split()
pair1.append(pair[0])
pair2.append(pair[1])
numSets = pow(2, numPeople)
bestSet = []
for i in range(1, numSets):
currSet = []
for j in range(numPeople):
if i & 1 << j > 0:
currSet.append(names[j])
validSet = True
for j in range(numPairs):
person1 = pair1[j]
person2 = pair2[j]
if person1 in currSet and person2 in currSet:
validSet = False
break
if validSet:
if len(currSet) > len(bestSet):
bestSet = currSet
bestSet.sort()
print(len(bestSet))
for i in bestSet:
print(i) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def do():
n, m = map(int, input().split(" "))
ban = []
names = []
res = []
for _ in range(n):
names.append(input())
d = {name: i for i, name in enumerate(names)}
for _ in range(m):
x, y = input().split(" ")
ban.append(1 << d[x] | 1 << d[y])
for state in range(1 << n):
can = True
for bs in ban:
if state & bs == bs:
can = False
break
if can:
res.append(state)
if not res:
print(0)
return 0
res.sort(key=lambda x: -bin(x).count("1"))
rt = []
for i in range(n):
if res[0] & 1 << i:
rt.append(names[i])
rt.sort()
print(len(rt))
for w in rt:
print(w)
return 0
do() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
ID = {}
name_from_ID = {}
for i in range(n):
name = input()
ID[name] = i
name_from_ID[i] = name
people_I_hate = [set() for i in range(n)]
for j in range(m):
name1, name2 = input().split()
people_I_hate[ID[name1]].add(ID[name2])
people_I_hate[ID[name2]].add(ID[name1])
def conflict(team, people_I_hate):
for guy1 in team:
for guy2 in team:
if guy1 in people_I_hate[guy2] or guy2 in people_I_hate:
return True
return False
ans = []
for mask in range(1 << n):
team = []
for i in range(n):
if mask & 1 << i:
team.append(i)
if not conflict(team, people_I_hate) and len(team) > len(ans):
ans = [name_from_ID[x] for x in team]
print(len(ans))
for name in sorted(ans):
print(name) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def get_subsets(elements):
if not elements:
yield tuple()
else:
for subset_rec in get_subsets(elements[1:]):
yield subset_rec
yield (elements[0],) + subset_rec
def is_valid_set(subset, pairs):
subset = set(subset)
ok = True
for pair in pairs:
ok = ok and not (pair[0] in subset and pair[1] in subset)
return ok
n, m = map(int, input().split())
names = tuple(input() for _ in range(n))
pairs = [input().split() for _ in range(m)]
ok = lambda subset: is_valid_set(subset, pairs)
team = max(filter(ok, get_subsets(names)), key=len)
print(len(team))
for name in sorted(team):
print(name) | FUNC_DEF IF VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER EXPR VAR EXPR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | global res, maxi
res = []
maxi = 0
def check(op):
global maxi, res
flag = 1
if len(op) > maxi:
d = {}
for i in op:
d[i] = None
for i in range(m):
if v[i][0] in d and v[i][1] in d:
flag = 0
break
if flag:
maxi = len(op)
res = op
def func(ip, op):
if len(ip) == 0:
check(op)
return
op1 = op
op2 = op + [ip[-1]]
d = ip[: len(ip) - 1]
func(d, op1)
func(d, op2)
n, m = map(int, input().split())
c = []
for i in range(n):
c.append(input())
v = []
for i in range(m):
v.append(list(map(str, input().split())))
func(c, [])
print(maxi)
res.sort()
for i in res:
print(i) | ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NONE FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR LIST VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | import itertools as it
n, m = map(int, input().split())
edges = set()
friends_M = {}
for i in range(n):
friends_M[input()] = i
for _ in range(m):
a, b = input().split()
a, b = friends_M[a], friends_M[b]
edges.add((a, b))
edges.add((b, a))
best = 0
best_vals = []
for subset in it.product([0, 1], repeat=n):
ss = list(it.compress(range(n), subset))
good = True
for i in range(len(ss)):
for j in range(i + 1, len(ss)):
if (ss[i], ss[j]) in edges:
good = False
if good:
if len(ss) > best:
best = len(ss)
best_vals = ss
print(best)
res = []
for i in range(len(best_vals)):
for j, k in friends_M.items():
if k == best_vals[i]:
res += [j]
break
for name in sorted(res):
print(name) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def GSB(x):
counter = 0
while x != 0:
counter += 1
x = x >> 1
return counter
def friends(checker, enemy):
for i in range(len(enemy)):
if enemy[i][0] in checker and enemy[i][1] in checker:
return 0
return 1
people, conflict = [int(x) for x in input().split()]
person = []
enemy = []
highest = -1
highestarray = []
for i in range(people):
person.append(input())
for j in range(conflict):
enemy.append(input().split())
combinations = [int(x) for x in range(2**people)]
for i in combinations:
checker = []
j = 0
z = GSB(i)
while j != z and i != 0:
if i & 1 == 1:
checker.append(person[j])
i = i >> 1
j += 1
if friends(checker, enemy):
if len(checker) > highest:
highest = len(checker)
highestarray = checker
print(highest)
highestarray.sort()
for i in range(highest):
print(highestarray[i]) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
N = [n]
Names = {}
Numbers = {}
Enemies = []
for i in range(n):
s = input()
Names[s] = i
Enemies.append([])
Numbers[i] = str(s)
for i in range(m):
a, b = input().split()
Enemies[Names[a]].append(Names[b])
Enemies[Names[b]].append(Names[a])
Ans = [[]]
def dp(N, i, Taken, Forbidden):
if i == N:
if len(Taken) > len(Ans[0]):
Ans[0] = list(Taken)
return
if i not in Forbidden:
dp(N, i + 1, Taken, Forbidden)
dp(N, i + 1, Taken + [i], Forbidden + Enemies[i])
else:
dp(N, i + 1, Taken, Forbidden)
return
dp(n, 0, [], [])
print(len(Ans[0]))
Ans = Ans[0]
for i in range(len(Ans)):
Ans[i] = Numbers[Ans[i]]
Ans.sort()
for item in Ans:
print(item) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST LIST FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR RETURN IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN EXPR FUNC_CALL VAR VAR NUMBER LIST LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
names = dict()
ind = dict()
enemies = list()
for i in range(n):
cur = input()
names[i] = cur
ind[cur] = i
enemies.append(set())
for i in range(m):
nm1, nm2 = input().split()
enemies[ind[nm1]].add(ind[nm2])
enemies[ind[nm2]].add(ind[nm1])
ans = 0
for i in range(2**n):
cur = set()
for j in range(n):
if i & 1 << j:
cur.add(j)
f = True
for j in cur:
for jj in enemies[j]:
if jj in cur:
f = False
break
if not f:
break
else:
if len(cur) > ans:
ans = len(cur)
curans = cur
ansarr = sorted([names[_] for _ in curans])
print(ans)
for i in ansarr:
print(i) | ASSIGN 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def s():
[n, m] = list(map(int, input().split()))
a = [input() for _ in range(n)]
b = {input() for _ in range(m)}
res = [[]]
aa = len(a) * [False]
def r(x=0):
if x == n:
p = [a[i] for i in range(n) if aa[i]]
if len(p) <= len(res[0]):
return
for i in p:
for j in p:
if i + " " + j in b or j + " " + i in b:
return
res[0] = p
return x
else:
aa[x] = True
r(x + 1)
aa[x] = False
r(x + 1)
r()
res = res[0]
res.sort()
print(len(res))
print(*res, sep="\n")
s() | FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER FUNC_DEF NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FOR VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR STRING VAR VAR BIN_OP BIN_OP VAR STRING VAR VAR RETURN ASSIGN VAR NUMBER VAR RETURN VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | from itertools import combinations
def solve():
n, m = map(int, input().split())
name = sorted([input().strip() for i in range(n)])
bad = sorted([sorted(input().strip().split()) for i in range(m)])
for i in range(n, -1, -1):
temp = sorted(map(sorted, combinations(name, i)))
for k in temp:
flag = 1
for j in map(sorted, combinations(k, 2)):
if j in bad:
flag = 0
break
if flag:
return k
x = solve()
print(len(x))
print(*x, sep="\n") | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
names = []
mp = {}
for i in range(n):
name = input()
mp[name] = i
names.append(name)
mask = [0] * n
for i in range(m):
a, b = map(mp.get, input().split())
mask[a] |= 1 << b
mask[b] |= 1 << a
ans = 0
result = 0
def bcnt(x):
return 0 if x == 0 else bcnt(x >> 1) + (x & 1)
for val in range(1 << n):
if bcnt(val) <= ans:
continue
valid = True
for i in range(n):
if 1 << i & val and val & mask[i]:
valid = False
break
if valid:
ans = bcnt(val)
result = val
print(ans)
out = []
for i in range(n):
if 1 << i & result:
out.append(names[i])
for s in sorted(out):
print(s) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n_m = input()
n, m = [int(s) for s in n_m.split()]
names = []
reverse = dict()
entente = [([True] * n) for _ in range(n)]
for i in range(n):
name = input()
names.append(name)
reverse[name] = i
entente[i][i] = False
for i in range(m):
i1, i2 = [reverse[s] for s in input().split()]
entente[i2][i1] = False
entente[i1][i2] = False
def rec(valides):
best = [[False] * n, 0]
participants_restants = sum(valides)
for i in range(n):
if valides[i] and participants_restants != sum(best[0]):
res_temp = rec([(valides[j] and entente[i][j] and j > i) for j in range(n)])
if best[1] <= res_temp[1]:
best = res_temp
best[0][i] = True
best[1] += 1
return best
res = [names[i] for i, b in enumerate(rec([True] * n)[0]) if b]
res.sort()
print(len(res))
for s in res:
print(s) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | f_in = input()
f_in = f_in.split(" ")
num_members = int(f_in[0])
num_bad_pairs = int(f_in[1])
members = []
bad_pair = []
bad_pair_dic = {}
for i in range(num_members):
members.append(input())
for i in range(num_bad_pairs):
bad_pair = input().split(" ")
if bad_pair[0] not in bad_pair_dic:
bad_pair_dic[bad_pair[0]] = []
bad_pair_dic[bad_pair[0]].append(bad_pair[1])
if bad_pair[1] not in bad_pair_dic:
bad_pair_dic[bad_pair[1]] = []
bad_pair_dic[bad_pair[1]].append(bad_pair[0])
answer = []
max_answer = []
max_iterations = num_members**2
num_iterations = 0
members.sort()
def recursive_brute_force(members, answer):
global max_iterations
global num_iterations
global max_answer
num_iterations += 1
if num_iterations >= max_iterations:
return
if members == []:
if len(answer) > len(max_answer):
max_answer = answer[:]
return
else:
new_members = members[:]
for member in members:
new_members.remove(member)
flag = False
for key in answer:
if key in bad_pair_dic:
if member in bad_pair_dic[key]:
flag = True
break
else:
continue
if flag:
continue
new_answer = answer[:]
new_answer.append(member)
if len(new_answer) > len(max_answer):
max_answer = new_answer[:]
recursive_brute_force(new_members, new_answer)
return
if num_bad_pairs != 0:
recursive_brute_force(members, answer)
else:
max_answer = members[:]
max_answer.sort()
print(len(max_answer))
for member in max_answer:
print(member) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF VAR NUMBER IF VAR VAR RETURN IF VAR LIST IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
p = {}
for i in range(n):
p[input()] = []
for i in range(m):
a, b = input().split()
p[a].append(b)
p[b].append(a)
t, r, k = [], [], 0
for a in p:
d = set(p[a])
for i in range(k):
if a in t[i]:
continue
q = t[i] | d
if len(q) == len(t[i]):
r[i].append(a)
else:
t.append(q)
r.append(r[i] + [a])
t.append(d)
r.append([a])
k = len(t)
k, j = 0, 0
for i, x in enumerate(r):
if len(x) > k:
k, j = len(x), i
print(k)
print("\n".join(sorted(r[j]))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR LIST LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | ii = lambda: int(input())
kk = lambda: map(int, input().split())
ll = lambda: list(kk())
n, m = kk()
ppl = [input() for _ in range(n)]
others = [set() for _ in range(n)]
for _ in range(m):
a, b = input().split()
a = ppl.index(a)
b = ppl.index(b)
others[a].add(b)
others[b].add(a)
largest = set()
for i in range(2**n):
s = set()
for j in range(n):
if i & 2**j:
if others[j] & s:
break
s.add(j)
else:
if len(s) > len(largest):
largest = s
print(len(largest))
print("\n".join(sorted([ppl[x] for x in largest]))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | tmp = input().split(" ")
N_ppl = int(tmp[0])
N_cstrt = int(tmp[1])
ppl_to_id = {}
id_ppl = [0] * N_ppl
cstrt = [0] * N_ppl
for i in range(N_ppl):
tmp = input()
id_ppl[i] = tmp
ppl_to_id[tmp] = i
cstrt[i] = []
for i in range(N_cstrt):
tmp = input().split()
cstrt[ppl_to_id[tmp[0]]].append(ppl_to_id[tmp[1]])
how_many_ones = [0] * 2**N_ppl
for N in range(2**N_ppl):
i = 0
n = N
while n > 0:
i += n % 2
n //= 2
how_many_ones[N] = i
def test_team(n):
global N_ppl, cstrt
Team = [0] * N_ppl
for k in range(N_ppl):
Team[k] = n % 2
n //= 2
for k in range(N_ppl):
if Team[k]:
for l in cstrt[k]:
if Team[l]:
return False
return Team
def main():
global N_ppl, how_many_ones
for i in range(N_ppl, 0, -1):
for j in range(0, 2**N_ppl):
if how_many_ones[j] != i:
continue
T = test_team(j)
if T:
return T
T = main()
R = []
for i in range(len(T)):
if T[i]:
R.append(i)
print(len(R))
for i in range(len(R)):
R[i] = id_ppl[R[i]]
R.sort()
print("\n".join(R)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | cant_integrantes, cant_lleva_mal = map(int, input().split(" "))
integrantes = []
lleva_mal = []
for i in range(cant_integrantes):
integrantes.append(input())
for i in range(cant_lleva_mal):
n1, n2 = map(str, input().split(" "))
lista = [n1, n2]
lista.sort()
lleva_mal.append(lista)
if cant_lleva_mal == 0:
integrantes.sort()
print(cant_integrantes)
for nombre in integrantes:
print(nombre)
exit()
bit = 1 << cant_integrantes
total_combinaciones = []
for i in range(bit):
combinacion = []
for j in range(cant_integrantes):
if 1 << j & i:
combinacion.append(integrantes[j])
combinacion.sort()
total_combinaciones.append(tuple(combinacion))
total_combinaciones.sort(key=len, reverse=True)
for tupla in total_combinaciones:
flag = True
for n1, n2 in lleva_mal:
if n1 in tupla and n2 in tupla:
flag = False
break
if flag:
break
print(len(tupla))
for elemento in tupla:
print(elemento) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | from itertools import product
n, m = map(int, input().split())
vl = sorted([input() for i in range(n)])
cm = {vl[i]: i for i in range(n)}
cl = []
for i in range(m):
a, b = input().split()
cl += [[cm[a], cm[b]]]
ans = [(), 0]
for x in list(product([1, 0], repeat=n)):
flag = 0
for c in cl:
if x[c[0]] == 1 == x[c[1]]:
flag = 1
break
if flag == 0 and ans[1] < x.count(1):
ans = [x, x.count(1)]
print(ans[1])
print("\n".join([vl[i] for i in range(n) if ans[0][i] == 1])) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST VAR VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def good(a, bad):
for i in bad:
if i[0] in a and i[1] in a:
return False
return True
def f(arr, bad, d):
n = len(arr)
mask = 0
ans = []
while mask < 1 << n:
temp = []
for i in range(len(arr)):
if mask & 1 << i:
temp.append(i)
if good(temp, bad):
ans.append(temp)
mask += 1
mx = max(ans, key=lambda s: len(s))
print(len(mx))
for i in mx:
print(arr[i])
return ""
a, b = map(int, input().strip().split())
blanck = []
for i in range(a):
blanck.append(input())
d = {}
blanck = sorted(blanck)
for i in range(len(blanck)):
d[blanck[i]] = i
bad = []
for i in range(b):
x, y = map(str, input().strip().split())
k = sorted((d[x], d[y]))
bad.append(k)
print(f(blanck, bad, d)) | FUNC_DEF FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def moins(M, N):
L = []
for i in M:
if i not in N:
L += [i]
return L
S = str(input())
l = S.split(" ")
n, m = int(l[0]), int(l[1])
d = {}
S = str(input())
L = [S]
for i in range(n - 1):
S = str(input())
j, f = 0, 0
while f == 0:
if j == len(L):
L += [S]
f = 1
elif L[j] > S:
L = L[:j] + [S] + L[j:]
f = 1
else:
j += 1
T = list(L)
P = []
for m in range(m):
S = str(input())
l = S.split(" ")
S1, S2 = l[0], l[1]
if S1 in d:
d[S1][0] += 1
d[S1] += [S2]
else:
d[S1] = [1, S2]
T.remove(S1)
P += [S1]
if S2 in d:
d[S2][0] += 1
d[S2] += [S1]
else:
d[S2] = [1, S1]
T.remove(S2)
P += [S2]
m = []
O = []
k = 0
for i in d:
m += [[i, moins(P, d[i][1:] + [i])]]
for i in m:
if i[-1] == []:
if len(i[:-1]) > k:
O = i[:-1]
k = len(i[:-1])
for j in i[-1]:
m += [i[:-1] + [j] + [moins(i[-1], d[j][1:] + [j])]]
for i in O:
if T == []:
T = [i]
else:
for j in range(len(T)):
if T[j] > i:
T = T[:j] + [i] + T[j:]
break
if j == len(T) - 1:
T += [i]
print(len(T))
for i in T:
print(i) | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR LIST VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR LIST VAR ASSIGN VAR VAR LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR LIST VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR VAR LIST VAR ASSIGN VAR VAR LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR LIST LIST VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER LIST VAR FOR VAR VAR IF VAR NUMBER LIST IF FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER VAR LIST BIN_OP BIN_OP VAR NUMBER LIST VAR LIST FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER LIST VAR FOR VAR VAR IF VAR LIST ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR LIST VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
names = []
for i in range(n):
names.append(input())
hate = []
for i in range(m):
hate.append(list(input().split()))
ans = set()
for x in range(1, (1 << n) + 1):
a = set()
for i in range(n):
if x & 1 << i:
a.add(names[i])
flag = True
for b in hate:
if b[0] in a and b[1] in a:
flag = False
break
if flag:
if len(a) > len(ans):
ans = a
print(len(ans))
print(*sorted(list(ans)), sep="\n") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def bitmask(m, array):
return [array[i] for i in range(len(array)) if m & 1 << i]
n, k = map(int, input().split())
names = [input() for _ in range(n)]
names.sort()
bads = [input().split() for _ in range(k)]
m_count, bb = -1, []
for m in range(2**n):
if bin(m).count("1") < m_count:
continue
b = bitmask(m, names)
f = True
for x, y in bads:
if x in b and y in b:
f = False
if f:
m_count, bb = len(b), b
print(m_count)
print("\n".join(bb)) | FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | n, m = map(int, input().split())
l = []
for i in range(n):
l.append(input())
c = []
for i in range(m):
s1, s2 = input().split()
c.append([1 << l.index(s1), 1 << l.index(s2)])
ans = []
for i in range(1, 2**n):
flag = 0
for k in c:
if i & k[0] and i & k[1]:
flag = 1
break
if flag:
continue
j = 0
t = i
d = []
while t > 0:
if t & 1:
d.append(l[j])
j += 1
t = t >> 1
if len(ans) < len(d):
ans = d
print(len(ans))
print(*sorted(ans), sep="\n") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING |
When little Petya grew up and entered the university, he started to take part in ΠΠ‘Π contests. Later he realized that he doesn't like how the ΠΠ‘Π contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. β Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.
To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.
Input
The first line contains two integer numbers n (1 β€ n β€ 16) β the number of volunteers, and m (<image>) β the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names β the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.
Output
The first output line should contain the single number k β the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.
Examples
Input
3 1
Petya
Vasya
Masha
Petya Vasya
Output
2
Masha
Petya
Input
3 0
Pasha
Lesha
Vanya
Output
3
Lesha
Pasha
Vanya | def check(b):
for i in b:
for j in b:
if (a[i], a[j]) in pair or (a[j], a[i]) in pair:
return False
return True
n, m = map(int, input().split())
a = []
ind = {}
for i in range(n):
a.append(input())
ind[a[-1]] = i
graph = [[] for i in range(n)]
pair = {}
for i in range(m):
x, y = input().split()
pair[x, y] = 1
graph[ind[x]].append(ind[y])
graph[ind[y]].append(ind[x])
if m == 0:
print(n)
a.sort()
for i in a:
print(i)
exit()
ans = 0
string = ""
for i in range(1, 2**n):
b = bin(i)[2:]
b = "0" * (n - len(b)) + b
temp = []
for j in range(n):
if b[j] == "1":
temp.append(ind[a[j]])
if check(temp):
if len(temp) > ans:
ans = len(temp)
string = b
print(ans)
ansl = []
for i in range(n):
if string[i] == "1":
ansl.append(a[i])
ansl.sort()
for i in ansl:
print(i) | FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of integers $(a_1, b_1, c_1)$ is considered to be lexicographically smaller than triple $(a_2, b_2, c_2)$ if sequence $[a_1, b_1, c_1]$ is lexicographically smaller than sequence $[a_2, b_2, c_2]$. Append $a$, $b$, $c$ to $s$ in this order. Go back to the first step.
You have integer $n$. Find the $n$-th element of $s$.
You have to answer $t$ independent test cases.
A sequence $a$ is lexicographically smaller than a sequence $b$ if in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^5$)Β β the number of test cases.
Each of the next $t$ lines contains a single integer $n$ ($1\le n \le 10^{16}$)Β β the position of the element you want to know.
-----Output-----
In each of the $t$ lines, output the answer to the corresponding test case.
-----Example-----
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
-----Note-----
The first elements of $s$ are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $ | import sys
input = sys.stdin.readline
out = []
t = int(input())
for _ in range(t):
n = int(input())
n -= 1
rem = n % 3
n //= 3
s = []
if n:
n -= 1
while n >= 0:
s.append(
[
["00", "00", "00"],
["01", "10", "11"],
["10", "11", "01"],
["11", "01", "10"],
][n % 4][rem]
)
n //= 4
n -= 1
s.append(["1", "10", "11"][rem])
s.reverse()
out.append(int("".join(s), 2))
print("\n".join(map(str, out))) | IMPORT ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING STRING VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of integers $(a_1, b_1, c_1)$ is considered to be lexicographically smaller than triple $(a_2, b_2, c_2)$ if sequence $[a_1, b_1, c_1]$ is lexicographically smaller than sequence $[a_2, b_2, c_2]$. Append $a$, $b$, $c$ to $s$ in this order. Go back to the first step.
You have integer $n$. Find the $n$-th element of $s$.
You have to answer $t$ independent test cases.
A sequence $a$ is lexicographically smaller than a sequence $b$ if in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^5$)Β β the number of test cases.
Each of the next $t$ lines contains a single integer $n$ ($1\le n \le 10^{16}$)Β β the position of the element you want to know.
-----Output-----
In each of the $t$ lines, output the answer to the corresponding test case.
-----Example-----
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
-----Note-----
The first elements of $s$ are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $ | import sys
input = sys.stdin.readline
t = int(input())
s = [int(input()) for i in range(t)]
res = []
for num in s:
num -= 1
mod = num % 3
num = num // 3
div = 1
while True:
if num // div != 0:
num -= div
div *= 4
else:
break
a = div + num
b = a * 2
tmp = a
coff = 1
while True:
if tmp == 0:
break
if tmp % 4 == 2:
b -= coff
if tmp % 4 == 3:
b -= coff * 5
tmp = tmp // 4
coff *= 4
c = a ^ b
if mod == 0:
print(a)
if mod == 1:
print(b)
if mod == 2:
print(c) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP 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 |
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of integers $(a_1, b_1, c_1)$ is considered to be lexicographically smaller than triple $(a_2, b_2, c_2)$ if sequence $[a_1, b_1, c_1]$ is lexicographically smaller than sequence $[a_2, b_2, c_2]$. Append $a$, $b$, $c$ to $s$ in this order. Go back to the first step.
You have integer $n$. Find the $n$-th element of $s$.
You have to answer $t$ independent test cases.
A sequence $a$ is lexicographically smaller than a sequence $b$ if in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^5$)Β β the number of test cases.
Each of the next $t$ lines contains a single integer $n$ ($1\le n \le 10^{16}$)Β β the position of the element you want to know.
-----Output-----
In each of the $t$ lines, output the answer to the corresponding test case.
-----Example-----
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
-----Note-----
The first elements of $s$ are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $ | import sys
from itertools import combinations
input = sys.stdin.readline
t = int(input())
for tt in range(t):
n = int(input()) - 1
mod3 = n % 3
n = n // 3
i = 0
while n >= 4**i:
n -= 4**i
i += 1
if i == 0:
a = 1
b = 2
c = 3
else:
a = 4**i + n
left = 0
right = 4**i
b = 4**i * 2
t = n
while right - left > 1:
mid1 = (left * 3 + right) // 4
mid2 = (left * 2 + right * 2) // 4
mid3 = (left + right * 3) // 4
rng = right - left
if left <= t < mid1:
b += 0
elif mid1 <= t < mid2:
b += rng // 4 * 2
elif mid2 <= t < mid3:
b += rng // 4 * 3
else:
b += rng // 4 * 1
t %= rng // 4
right //= 4
c = a ^ b
if mod3 == 0:
print(a)
elif mod3 == 1:
print(b)
else:
print(c) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of integers $(a_1, b_1, c_1)$ is considered to be lexicographically smaller than triple $(a_2, b_2, c_2)$ if sequence $[a_1, b_1, c_1]$ is lexicographically smaller than sequence $[a_2, b_2, c_2]$. Append $a$, $b$, $c$ to $s$ in this order. Go back to the first step.
You have integer $n$. Find the $n$-th element of $s$.
You have to answer $t$ independent test cases.
A sequence $a$ is lexicographically smaller than a sequence $b$ if in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^5$)Β β the number of test cases.
Each of the next $t$ lines contains a single integer $n$ ($1\le n \le 10^{16}$)Β β the position of the element you want to know.
-----Output-----
In each of the $t$ lines, output the answer to the corresponding test case.
-----Example-----
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
-----Note-----
The first elements of $s$ are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $ | from sys import stdin
input = stdin.readline
pot = [1] * 40
for i in range(1, 40):
pot[i] = 4 * pot[i - 1]
poczatki = [1, 2]
for i in range(38):
os = poczatki[-1]
poczatki.append(os + pot[i + 1])
tab = [[0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]]
def odp(ind, m3):
if ind == 1:
return m3 + 1
else:
m = ind
while m % 4 != 2:
m -= 1
i = 0
while poczatki[i + 1] <= m:
i += 1
miejsce = (m - poczatki[i]) // 4
pre = poczatki[i - 1] + miejsce
return 4 * odp(pre, m3) + tab[m3][ind - m]
t = int(input())
for _ in range(t):
n = int(input())
a = (n - 1) % 3
b = (n - 1) // 3 + 1
print(odp(b, a)) | ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of integers $(a_1, b_1, c_1)$ is considered to be lexicographically smaller than triple $(a_2, b_2, c_2)$ if sequence $[a_1, b_1, c_1]$ is lexicographically smaller than sequence $[a_2, b_2, c_2]$. Append $a$, $b$, $c$ to $s$ in this order. Go back to the first step.
You have integer $n$. Find the $n$-th element of $s$.
You have to answer $t$ independent test cases.
A sequence $a$ is lexicographically smaller than a sequence $b$ if in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^5$)Β β the number of test cases.
Each of the next $t$ lines contains a single integer $n$ ($1\le n \le 10^{16}$)Β β the position of the element you want to know.
-----Output-----
In each of the $t$ lines, output the answer to the corresponding test case.
-----Example-----
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
-----Note-----
The first elements of $s$ are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $ | import sys
def new_find_pair(n):
stack = []
while n:
N = n.bit_length() - 1
if N % 2 == 0:
i = N // 2
stack.append((n, 1, i))
n -= 4**i
else:
i = N // 2
if n >> 2 * i & 1 == 0:
stack.append((n, 2, i))
n -= 2 * 4**i
else:
stack.append((n, 3, i))
n -= 3 * 4**i
a, b, c = 0, 0, 0
for m, t, i in stack[::-1]:
m -= t * 4**i
if t == 1:
if m == b:
a, b, c = b, c, a
elif m == c:
a, b, c = c, a, b
elif t == 2:
if m == a:
a, b, c = c, a, b
elif m == c:
a, b, c = b, c, a
elif m == a:
a, b, c = b, c, a
elif m == b:
a, b, c = c, a, b
a += 4**i
b += 2 * 4**i
c += 3 * 4**i
return a, b, c
def nth_pair(n):
tmp = 0
for i in range(28):
tmp += 4**i
if tmp >= n:
tmp -= 4**i
first = n - tmp - 1 + 4**i
return new_find_pair(first)
def nth_seq(n):
q = (n - 1) // 3 + 1
fst = (n - 1) % 3
res = nth_pair(q)[fst]
return res
input = sys.stdin.buffer.readline
Q = int(input())
for _ in range(Q):
n = int(input())
r = nth_seq(n)
print(r) | IMPORT FUNC_DEF ASSIGN VAR LIST WHILE VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the infinite sequence $s$ of positive integers, created by repeating the following steps:
Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the bitwise XOR operation. $a$, $b$, $c$ are not in $s$. Here triple of integers $(a_1, b_1, c_1)$ is considered to be lexicographically smaller than triple $(a_2, b_2, c_2)$ if sequence $[a_1, b_1, c_1]$ is lexicographically smaller than sequence $[a_2, b_2, c_2]$. Append $a$, $b$, $c$ to $s$ in this order. Go back to the first step.
You have integer $n$. Find the $n$-th element of $s$.
You have to answer $t$ independent test cases.
A sequence $a$ is lexicographically smaller than a sequence $b$ if in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^5$)Β β the number of test cases.
Each of the next $t$ lines contains a single integer $n$ ($1\le n \le 10^{16}$)Β β the position of the element you want to know.
-----Output-----
In each of the $t$ lines, output the answer to the corresponding test case.
-----Example-----
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
-----Note-----
The first elements of $s$ are $1, 2, 3, 4, 8, 12, 5, 10, 15, \dots $ | def find_answer(n):
trio_num, trio_place = n // 3, n % 3
digit = 1
while trio_num >= 0:
trio_num -= digit
digit *= 4
digit //= 4
trio_num += digit
t1 = digit + trio_num
if trio_place == 0:
return t1
t2, t3 = digit * 2, digit * 3
new_digit = 1
while new_digit < digit:
x = t1 % 4
if x == 1:
t2 += new_digit * 2
t3 += new_digit * 3
elif x == 2:
t2 += new_digit * 3
t3 += new_digit * 1
elif x == 3:
t2 += new_digit * 1
t3 += new_digit * 2
t1 //= 4
new_digit *= 4
return t2 if trio_place == 1 else t3
n = int(input())
ans = []
for i in range(n):
x = int(input())
ans += [find_answer(x - 1)]
for x in ans:
print(x) | FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = int(input())
curr = list([i for i in range(1, 100)])
curr = set(curr)
def isvalid(x):
if x < 1 or x > 10**9:
return 0
if len(set(str(x))) <= 2:
return 1
cnt = 0
while cnt <= 10**5:
curr1 = set()
for i in curr:
for j in range(10):
if isvalid(i * 10 + j):
curr1.add(i * 10 + j)
cnt += 1
curr |= curr1
curr = sorted(list(curr))
ans = 0
for i in curr:
if i >= 1 and i <= n:
ans += 1
elif i > n:
break
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP NUMBER NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | def p(k):
if 0 < k <= n:
s.add(k)
k *= 10
p(k + x)
p(k + y)
n = int(input())
s = set()
for x in range(10):
for y in range(10):
p(x)
print(len(s)) | FUNC_DEF IF NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | num = int(input())
cou = 0
def traverse(x):
if x > num:
return
nonlocal cou
if len(set([int(j) for j in str(x)])) <= 2:
cou += 1
for i in range(0, 10):
traverse(10 * x + i)
for i in range(1, 10):
traverse(i)
print(cou) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = int(input())
use = set()
def calc(x, a, b):
global cnt
if int(x) <= n and not int(x) in use:
use.add(int(x))
elif int(x) > n:
return
calc(x + a, a, b)
calc(x + b, a, b)
def calc2(x, a):
global cnt
if int(x) <= n and not int(x) in use:
use.add(int(x))
elif int(x) > n:
return
calc2(x + a, a)
for i in range(1, 10):
calc2(str(i), str(i))
for i in range(10):
for j in range(i + 1, 10):
if i != 0:
calc(str(i), str(i), str(j))
calc(str(j), str(i), str(j))
print(len(use)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | ii = lambda: int(input())
kk = lambda: map(int, input().split())
ll = lambda: list(kk())
q = []
s = set()
n = ii()
for x in range(10):
for y in range(10):
q.append(x)
while q:
q2 = []
for item in q:
if item > 0 and item <= n:
s.add(item)
item *= 10
q2.append(item + x)
q2.append(item + y)
q = q2
print(len(s)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | import sys
dp = [[[(-1) for j in range(3)] for i in range(1 << 10)] for k in range(11)]
In = sys.stdin
n = In.readline().strip()
def go(idx, mask, equal):
if dp[idx][mask][equal] != -1:
return dp[idx][mask][equal]
if bin(mask).count("1") > 2:
return 0
if idx == len(n):
return 1
res = 0
if idx == 0 or equal == 2:
res += go(idx + 1, mask, 2)
elif equal == 1 and int(n[idx]) == 0:
res += go(idx + 1, mask | 1, 1)
else:
res += go(idx + 1, mask | 1, 0)
for i in range(1, 10):
if equal == 1 and i > int(n[idx]):
break
elif equal == 1 and i == int(n[idx]):
res += go(idx + 1, mask | 1 << i, 1)
else:
res += go(idx + 1, mask | 1 << i, 0)
dp[idx][mask][equal] = res
return res
print(go(0, 0, 1) - 1) | IMPORT ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = int(input())
array = set()
array.add(10**9)
for x in range(10):
for y in range(10):
for l in range(1, 10):
for m in range(1, 2**l + 1):
s = [(str(x) if m & 1 << i else str(y)) for i in range(l)]
u = int("".join(s))
if u <= n:
array.add(u)
array.remove(0)
array = [u for u in array if u <= n]
print(len(array)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = int(input())
def bruteforce(number):
res = 0
liste = []
while number > 0:
integer = number % 10
if integer not in liste:
liste.append(integer)
number = number // 10
return len(liste) <= 2
answer = [0]
def dfs(num):
if num > 0 and num <= n:
answer[0] += 1
for a in range(10):
if bruteforce(num * 10 + a):
dfs(num * 10 + a)
for chiffre in range(1, 10):
dfs(chiffre)
print(answer[0]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | s = set()
def DFS(x, y, num):
s.add(num)
num_x = 10 * num + x
num_y = 10 * num + y
if num_x and num_x <= n:
DFS(x, y, num_x)
if num_y and num_y <= n:
DFS(x, y, num_y)
n = int(input())
for i in range(10):
for j in range(i, 10):
DFS(i, j, 0)
print(len(s) - 1) | ASSIGN VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = int(input())
res = set()
def solve(p, l):
if p > n or l > 10:
return
if p > 0:
res.add(p)
solve(p * 10 + a, l + 1)
solve(p * 10 + b, l + 1)
for a in range(0, 10):
for b in range(0, a):
solve(0, 0)
print(len(res)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | from itertools import product
n = int(input().strip())
if n < 102:
print(n)
else:
from itertools import product
res = set()
combination = (str(i) + str(j) for i in range(10) for j in range(i + 1, 10))
for it in (
product(comb, repeat=l)
for comb in combination
for l in range(1, len(str(n)) + 1)
):
for line in it:
tmp = int("".join(line))
if tmp and tmp <= n:
res.add(tmp)
print(len(res)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | def gen(digit, x, length, S):
S.append(x)
if length == 10:
return
if len(digit) == 1:
for i in range(0, 10):
next_x = x * 10 + i
if i == digit[0]:
gen(digit, next_x, length + 1, S)
else:
gen(digit + [i], next_x, length + 1, S)
else:
next_x1 = x * 10 + digit[0]
next_x2 = x * 10 + digit[1]
gen(digit, next_x1, length + 1, S)
gen(digit, next_x2, length + 1, S)
S = []
for i in range(1, 10):
gen([i], i, 1, S)
S = sorted(S)
x = int(input())
l = -1
u = len(S)
while u - l > 1:
md = (u + l) // 2
if x >= S[md]:
l = md
else:
u = md
print(u) | FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = int(input())
a = []
def foo(x, i, j):
if x > n:
return
if x:
a.append(x)
if 10 * x + i != x:
foo(10 * x + i, i, j)
foo(10 * x + j, i, j)
for i in range(10):
for j in range(i + 1, 10):
foo(0, i, j)
print(len(set(a))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN IF VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | nset = set()
n = int(input())
def reslove(x, y, num, flag):
if num > n or flag and num == 0:
return
if num > 0:
nset.add(num)
reslove(x, y, num * 10 + x, True)
reslove(x, y, num * 10 + y, True)
for i in range(10):
for j in range(i + 1, 10):
reslove(i, j, 0, False)
print(len(nset)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | n = str(int(input()) + 1)
a = int(n[0])
l = len(n)
d = 1 << l - 1
def f(a, i):
global n, l
if i == l:
return 0
b = int(n[i])
i += 1
d = 1 << l - i
if a > b:
return b * d + g(b, a, i)
if a == b:
return b * d + f(a, i)
return (b - 1) * d + g(a, b, i) + 9 * d - 8
def g(a, b, i):
global n, l
if i == l:
return 0
c = int(n[i])
i += 1
d = 1 << l - i
if c < a:
return 0
if c == a:
return g(a, b, i)
if c < b:
return d
if c == b:
return d + g(a, b, i)
return 2 * d
print(a * (9 * d - 8) + 72 * (d - l) + f(a, 1) - 1) | ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER |
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are such digits x and y (0 β€ x, y β€ 9), that the decimal representation of number a (without leading zeroes) contains only digits x and y.
Polycarpus has integer n. He wants to know how many positive integers that do not exceed n, are undoubtedly lucky. Help him, count this number.
-----Input-----
The first line contains a single integer n (1 β€ n β€ 10^9) β Polycarpus's number.
-----Output-----
Print a single integer that says, how many positive integers that do not exceed n are undoubtedly lucky.
-----Examples-----
Input
10
Output
10
Input
123
Output
113
-----Note-----
In the first test sample all numbers that do not exceed 10 are undoubtedly lucky.
In the second sample numbers 102, 103, 104, 105, 106, 107, 108, 109, 120, 123 are not undoubtedly lucky. | def cnt(s, p):
ans = 0
if p > s:
ans = 0
elif len(p) == len(s):
ans = 1 if len(set(p.lstrip("0"))) <= 2 else 0
elif len(set(p.lstrip("0"))) > 2:
ans = 0
elif s[: len(p)] > p:
if len(set(p.lstrip("0"))) == 2:
ans = 2 ** (len(s) - len(p))
elif len(set(p.lstrip("0"))) == 1:
ans = 1 + 9 * (2 ** (len(s) - len(p)) - 1)
else:
ans = 10 + 45 * (2 ** (len(s) - len(p)) - 2)
ans += 36 * sum([(2**l - 2) for l in range(2, len(s) - len(p))])
else:
ans = sum(cnt(s, p + c) for c in "0123456789")
return ans
print(cnt(input().strip(), "") - 1) | FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR STRING RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
for _ in range(int(sys.stdin.readline())):
n = int(sys.stdin.readline())
q, r = (n - 1) // 3, n % 3
i = 0
while q >= 1 << (i << 1):
q -= 1 << (i << 1)
i += 1
quad = [0] * i
if r == 1:
s = 0
while q > 0:
quad[s] += q % 4
q >>= 2
s += 1
res = 1 << len(quad) * 2
for j, x in enumerate(quad):
res += {(0): 0, (1): 1, (2): 2, (3): 3}[x] << j * 2
print(res)
continue
if r == 2:
s = 0
while q > 0:
quad[s] += q % 4
q >>= 2
s += 1
res = 2 << len(quad) * 2
for j, x in enumerate(quad):
res += {(0): 0, (1): 2, (2): 3, (3): 1}[x] << j * 2
print(res)
continue
if r == 0:
s = 0
while q > 0:
quad[s] += q % 4
q >>= 2
s += 1
res = 3 << len(quad) * 2
for j, x in enumerate(quad):
res += {(0): 0, (1): 3, (2): 1, (3): 2}[x] << j * 2
print(res)
continue | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | def level(m):
l = 0
while m - (1 << l * 2) >= 0:
m -= 1 << l * 2
l += 1
return l, m
def to_bin(l, r):
ls = []
for __ in range(l):
ls.append(r % 4)
r //= 4
return ls
def off(b, t):
magic = [[0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]]
base = 1
ans = 0
for d in b:
ans += base * magic[t][d]
base *= 4
return ans
def basic(l, t):
return 4**l * (t + 1)
def get_ans(n):
m, t = divmod(n - 1, 3)
l, r = level(m)
b = to_bin(l, r)
o = off(b, t)
s = basic(l, t)
return s + o
input = __import__("sys").stdin.readline
T = int(input())
for __ in range(T):
print(get_ans(int(input()))) | FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
lines = sys.stdin.readlines()
t = int(lines[0].strip())
pows = [(4**i) for i in range(64)]
vals = (0, 1, 2, 3), (0, 2, 3, 1), (0, 3, 1, 2)
prt = []
for iter in range(t):
n = int(lines[iter + 1].strip())
pow = 0
for i in range(64):
if pows[i + 1] > n:
pow = i
break
n -= pows[pow]
front = n % 3
n = n // 3
ret = (front + 1) * pows[pow]
for i in range(pow):
v = vals[front][n % 4]
ret += v * pows[i]
n = n // 4
if iter == 0:
prt += [str(ret)]
else:
prt += ["\n" + str(ret)]
print("".join(prt)) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR LIST FUNC_CALL VAR VAR VAR LIST BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | tail = [["00", "00", "00"], ["01", "10", "11"], ["10", "11", "01"], ["11", "01", "10"]]
top = ["01", "10", "11"]
S = []
E = []
cur = 1
for i in range(32):
S.append(cur)
E.append(4 * cur - 1)
cur *= 4
def convert(s):
cur = 1
ans = 0
for x in s[::-1]:
if x == "1":
ans |= cur
cur <<= 1
return ans
def solve(n):
i = 0
while n > E[i]:
i += 1
remain = n - S[i]
d, r = remain // 3, remain % 3
ans = []
for _ in range(i):
ans.append(tail[d % 4][r])
d //= 4
ans.append(top[(n - 1) % 3])
return convert("".join(ans[::-1]))
print("\n".join([str(solve(int(input()))) for _ in range(int(input()))])) | ASSIGN VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF VAR STRING VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
def input():
return sys.stdin.readline()[:-1]
t = int(input())
rep = [[0, 1, 2, 3], [0, 2, 3, 1], [0, 3, 1, 2]]
pows = [(1) for _ in range(30)]
for i in range(1, 30):
pows[i] = pows[i - 1] * 4
for _ in range(t):
n = int(input())
n -= 1
quo, mod = n // 3, n % 3
stage, cum = 0, 0
while cum + pows[stage] <= quo:
cum += pows[stage]
stage += 1
quo -= cum
ans = pows[stage] * rep[mod][1]
for k in range(stage):
ans += pows[k] * rep[mod][quo % 4]
quo //= 4
print(ans) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
N = int(input())
if N <= 3:
print(N)
continue
if N % 3 == 1:
k = N.bit_length() - 1
if k & 1:
k -= 1
print(2**k + (N - 2**k) // 3)
elif N % 3 == 2:
N1 = N - 1
k = N1.bit_length() - 1
if k & 1:
k -= 1
ans1 = 2**k + (N1 - 2**k) // 3
ans = 0
cnt = 0
while ans1:
a = ans1 % 4
if a == 1:
a = 2
elif a == 2:
a = 3
elif a == 3:
a = 1
ans += a * 4**cnt
cnt += 1
ans1 >>= 2
print(ans)
else:
N1 = N - 2
k = N1.bit_length() - 1
if k & 1:
k -= 1
ans1 = 2**k + (N1 - 2**k) // 3
ans = 0
cnt = 0
while ans1:
a = ans1 % 4
if a == 1:
a = 3
elif a == 2:
a = 1
elif a == 3:
a = 2
ans += a * 4**cnt
cnt += 1
ans1 >>= 2
print(ans)
main() | IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
lines = sys.stdin.readlines()
T = int(lines[0].strip())
partial = [
1,
2,
3,
4,
8,
12,
5,
10,
15,
6,
11,
13,
7,
9,
14,
16,
32,
48,
17,
34,
51,
18,
35,
49,
19,
33,
50,
20,
40,
60,
21,
42,
63,
22,
43,
61,
23,
41,
62,
24,
44,
52,
25,
46,
55,
26,
47,
53,
27,
45,
54,
28,
36,
56,
29,
38,
59,
30,
39,
57,
31,
37,
58,
64,
128,
192,
65,
130,
195,
66,
131,
193,
67,
129,
194,
68,
136,
204,
69,
138,
207,
70,
139,
205,
71,
137,
206,
72,
140,
196,
73,
142,
199,
74,
143,
197,
75,
141,
198,
76,
132,
200,
77,
134,
203,
78,
135,
201,
79,
133,
202,
80,
160,
240,
81,
162,
243,
82,
163,
241,
83,
161,
242,
84,
168,
252,
85,
170,
255,
86,
171,
253,
87,
169,
254,
88,
172,
244,
89,
174,
247,
90,
175,
245,
91,
173,
246,
92,
164,
248,
93,
166,
251,
94,
167,
249,
95,
165,
250,
96,
176,
208,
97,
178,
211,
98,
179,
209,
99,
177,
210,
100,
184,
220,
101,
186,
223,
102,
187,
221,
103,
185,
222,
104,
188,
212,
105,
190,
215,
106,
191,
213,
107,
189,
214,
108,
180,
216,
109,
182,
219,
110,
183,
217,
111,
181,
218,
112,
144,
224,
113,
146,
227,
114,
147,
225,
115,
145,
226,
116,
152,
236,
117,
154,
239,
118,
155,
237,
119,
153,
238,
120,
156,
228,
121,
158,
231,
122,
159,
229,
123,
157,
230,
124,
148,
232,
125,
150,
235,
126,
151,
233,
127,
149,
234,
256,
512,
768,
]
for t in range(T):
n = int(lines[t + 1].strip())
if n <= 255:
print(partial[n - 1])
continue
index = n % 3
lowPow4 = 4 ** (len(bin(n)[3:]) // 2)
first = lowPow4 + (n - lowPow4) // 3
tmp = [0, 2, 3, 1]
def theSecond(fi):
if fi < 128:
j = partial.index(fi)
return partial[j + 1]
prev = theSecond(fi // 4)
return prev * 4 + tmp[fi % 4]
second = theSecond(first)
if index == 1:
print(first)
elif index == 2:
print(second)
else:
print(first ^ second) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
memo = [(0, 0, 0)]
def new_find_pair(n):
stack = []
while n >= len(memo):
N = n.bit_length() - 1
if N % 2 == 0:
i = N // 2
stack.append((n, 1, i))
n -= 4**i
else:
i = N // 2
if n >> 2 * i & 1 == 0:
stack.append((n, 2, i))
n -= 2 * 4**i
else:
stack.append((n, 3, i))
n -= 3 * 4**i
a, b, c = memo[n]
for m, t, i in stack[::-1]:
m -= t * 4**i
if t == 1:
if m == b:
a, b, c = b, c, a
elif m == c:
a, b, c = c, a, b
elif t == 2:
if m == a:
a, b, c = c, a, b
elif m == c:
a, b, c = b, c, a
elif m == a:
a, b, c = b, c, a
elif m == b:
a, b, c = c, a, b
a += 4**i
b += 2 * 4**i
c += 3 * 4**i
return a, b, c
for i in range(1, 4**5):
memo.append(new_find_pair(i))
def nth_pair(n):
tmp = 0
for i in range(28):
tmp += 4**i
if tmp >= n:
tmp -= 4**i
first = n - tmp - 1 + 4**i
return new_find_pair(first)
def nth_seq(n):
q = (n - 1) // 3 + 1
fst = (n - 1) % 3
res = nth_pair(q)[fst]
return res
input = sys.stdin.buffer.readline
Q = int(input())
for _ in range(Q):
n = int(input())
r = nth_seq(n)
print(r) | IMPORT ASSIGN VAR LIST NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
def log4(n):
k = 0
while n > 3:
n //= 4
k += 1
return k
def manual_test(n):
a = 0
s = []
forbidden = set()
while len(s) < n:
a = a + 1
while a in forbidden:
a += 1
b = a + 1
while b in forbidden or a ^ b in forbidden or a ^ b < b:
b += 1
s.append((a, b, a ^ b))
forbidden.add(a)
forbidden.add(b)
forbidden.add(a ^ b)
for i, x in enumerate(s):
print("{:3d} {}".format(i + 1, x))
y = abc(i + 1)
assert x == y, y
exit(0)
return
def f(x, y):
if y == 0:
return 0
q, r = divmod(x, y)
return [0, 2, 3, 1][q] * y + f(r, y // 4)
def abc(n):
if n == 1:
a, b = 1, 2
else:
m = n * 3 - 2
x = 4 ** log4(m)
d = (m - x) // 3
a, b = x + d, 2 * x + f(d, x // 4)
return a, b, a ^ b
ints = (int(s) for s in sys.stdin.read().split())
ntc = next(ints)
ans = []
for tc in range(1, 1 + ntc):
n = next(ints)
n, r = divmod(n + 2, 3)
ans.append(abc(n)[r])
print("\n".join(map(str, ans))) | IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP LIST NUMBER NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
input = sys.stdin.readline
Q = int(input())
Query = [int(input()) for _ in range(Q)]
for N in Query:
N -= 1
seq = N // 3
where = N % 3
T = 0
for l in range(100):
a = 4**l
if T + a > seq:
start = seq - T + a
break
T += a
if where == 0:
print(start)
else:
b = start - a
b_str = bin(b)[2:]
b_str = "0" * (a.bit_length() - 1 - len(b_str)) + b_str
L = len(b_str) // 2
p_str = ""
for l in range(L):
tmp = b_str[2 * l : 2 * l + 2]
if tmp == "00":
p_str += "00"
elif tmp == "01":
p_str += "10"
elif tmp == "10":
p_str += "11"
else:
p_str += "01"
second = int("10" + p_str, 2)
if where == 1:
print(second)
else:
print(start ^ second) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR STRING VAR STRING IF VAR STRING VAR STRING IF VAR STRING VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
Consider the infinite sequence s of positive integers, created by repeating the following steps:
1. Find the lexicographically smallest triple of positive integers (a, b, c) such that
* a β b β c = 0, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
* a, b, c are not in s.
Here triple of integers (a_1, b_1, c_1) is considered to be lexicographically smaller than triple (a_2, b_2, c_2) if sequence [a_1, b_1, c_1] is lexicographically smaller than sequence [a_2, b_2, c_2].
2. Append a, b, c to s in this order.
3. Go back to the first step.
You have integer n. Find the n-th element of s.
You have to answer t independent test cases.
A sequence a is lexicographically smaller than a sequence b if in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
The first line contains a single integer t (1 β€ t β€ 10^5) β the number of test cases.
Each of the next t lines contains a single integer n (1β€ n β€ 10^{16}) β the position of the element you want to know.
Output
In each of the t lines, output the answer to the corresponding test case.
Example
Input
9
1
2
3
4
5
6
7
8
9
Output
1
2
3
4
8
12
5
10
15
Note
The first elements of s are 1, 2, 3, 4, 8, 12, 5, 10, 15, ... | import sys
input = sys.stdin.buffer.readline
for f in range(int(input())):
n = int(input())
size = 2
ma = 4
while n >= ma:
ma *= 4
size += 2
pr = ma // 4
ind = n - pr
ind //= 3
first = [0] * size
first[1] = 1
i = size - 1
while ind > 0:
if ind % 2 == 1:
first[i] = 1
ind //= 2
i -= 1
if n % 3 == 1:
s = 0
for i in range(size):
s *= 2
if first[i] == 1:
s += 1
print(s)
if n % 3 == 2:
for i in range(size // 2):
if first[2 * i] == 0 and first[2 * i + 1] == 1:
first[2 * i] = 1
first[2 * i + 1] = 0
elif first[2 * i] == 1 and first[2 * i + 1] == 0:
first[2 * i] = 1
first[2 * i + 1] = 1
elif first[2 * i] == 1 and first[2 * i + 1] == 1:
first[2 * i] = 0
first[2 * i + 1] = 1
s = 0
for i in range(size):
s *= 2
if first[i] == 1:
s += 1
print(s)
if n % 3 == 0:
for i in range(size // 2):
if first[2 * i] == 0 and first[2 * i + 1] == 1:
first[2 * i] = 1
first[2 * i + 1] = 1
elif first[2 * i] == 1 and first[2 * i + 1] == 0:
first[2 * i] = 0
first[2 * i + 1] = 1
elif first[2 * i] == 1 and first[2 * i + 1] == 1:
first[2 * i] = 1
first[2 * i + 1] = 0
s = 0
for i in range(size):
s *= 2
if first[i] == 1:
s += 1
print(s) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER IF VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
A company of $n$ friends wants to order exactly two pizzas. It is known that in total there are $9$ pizza ingredients in nature, which are denoted by integers from $1$ to $9$.
Each of the $n$ friends has one or more favorite ingredients: the $i$-th of friends has the number of favorite ingredients equal to $f_i$ ($1 \le f_i \le 9$) and your favorite ingredients form the sequence $b_{i1}, b_{i2}, \dots, b_{if_i}$ ($1 \le b_{it} \le 9$).
The website of CodePizza restaurant has exactly $m$ ($m \ge 2$) pizzas. Each pizza is characterized by a set of $r_j$ ingredients $a_{j1}, a_{j2}, \dots, a_{jr_j}$ ($1 \le r_j \le 9$, $1 \le a_{jt} \le 9$) , which are included in it, and its price is $c_j$.
Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 10^5, 2 \le m \le 10^5$) β the number of friends in the company and the number of pizzas, respectively.
Next, the $n$ lines contain descriptions of favorite ingredients of the friends: the $i$-th of them contains the number of favorite ingredients $f_i$ ($1 \le f_i \le 9$) and a sequence of distinct integers $b_{i1}, b_{i2}, \dots, b_{if_i}$ ($1 \le b_{it} \le 9$).
Next, the $m$ lines contain pizza descriptions: the $j$-th of them contains the integer price of the pizza $c_j$ ($1 \le c_j \le 10^9$), the number of ingredients $r_j$ ($1 \le r_j \le 9$) and the ingredients themselves as a sequence of distinct integers $a_{j1}, a_{j2}, \dots, a_{jr_j}$ ($1 \le a_{jt} \le 9$).
-----Output-----
Output two integers $j_1$ and $j_2$ ($1 \le j_1,j_2 \le m$, $j_1 \ne j_2$) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.
-----Examples-----
Input
3 4
2 6 7
4 2 3 9 5
3 2 3 9
100 1 7
400 3 3 2 5
100 2 9 2
500 3 2 9 5
Output
2 3
Input
4 3
1 1
1 2
1 3
1 4
10 4 1 2 3 4
20 4 1 2 3 4
30 4 1 2 3 4
Output
1 2
Input
1 5
9 9 8 7 6 5 4 3 2 1
3 4 1 2 3 4
1 4 5 6 7 8
4 4 1 3 5 7
1 4 2 4 6 8
5 4 1 9 2 8
Output
2 4 | import itertools
from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
friends = [0] * 512
exists = [0] * 512
costs_min = [0] * 512
costs_2 = [0] * 512
index_min = [0] * 512
index_2 = [0] * 512
count_friends = [0] * 512
def top_to_idx(top):
ans = 0
for t in top:
ans += 1 << t - 1
return ans
def idx_to_top(idx):
ans = []
for i in range(9):
if idx & 1 << i:
ans.append(i + 1)
return ans
for i in range(n):
top = list(map(int, stdin.readline().split()))[1:]
friends[top_to_idx(top)] += 1
def subset(i, j):
for s in range(9):
if i & 1 << s and not j & 1 << s:
return False
return True
for i in range(512):
for j in range(512):
if subset(j, i):
count_friends[i] += friends[j]
for i in range(m):
pizza = list(map(int, stdin.readline().split()))
top_idx = top_to_idx(pizza[2:])
cost = pizza[0]
exists[top_idx] = True
if costs_min[top_idx] == 0 or cost < costs_min[top_idx]:
costs_2[top_idx] = costs_min[top_idx]
index_2[top_idx] = index_min[top_idx]
costs_min[top_idx] = cost
index_min[top_idx] = i + 1
elif costs_2[top_idx] == 0 or cost < costs_2[top_idx]:
costs_2[top_idx] = cost
index_2[top_idx] = i + 1
best_matches = -1
best_cost = -1
best = None
for p1 in range(512):
for p2 in range(p1, 512):
if not exists[p1] or not exists[p2]:
continue
if p1 == p2 and index_2[p1] == 0:
continue
p = p1 | p2
matches = count_friends[p]
cost = (
costs_min[p1] + costs_min[p2] if p1 != p2 else costs_min[p1] + costs_2[p2]
)
if (
best_matches == -1
or matches > best_matches
or matches == best_matches
and cost < best_cost
):
best = (
(index_min[p1], index_min[p2])
if p1 != p2
else (index_min[p1], index_2[p2])
)
best_matches = matches
best_cost = cost
print(best[0], best[1]) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
A company of $n$ friends wants to order exactly two pizzas. It is known that in total there are $9$ pizza ingredients in nature, which are denoted by integers from $1$ to $9$.
Each of the $n$ friends has one or more favorite ingredients: the $i$-th of friends has the number of favorite ingredients equal to $f_i$ ($1 \le f_i \le 9$) and your favorite ingredients form the sequence $b_{i1}, b_{i2}, \dots, b_{if_i}$ ($1 \le b_{it} \le 9$).
The website of CodePizza restaurant has exactly $m$ ($m \ge 2$) pizzas. Each pizza is characterized by a set of $r_j$ ingredients $a_{j1}, a_{j2}, \dots, a_{jr_j}$ ($1 \le r_j \le 9$, $1 \le a_{jt} \le 9$) , which are included in it, and its price is $c_j$.
Help your friends choose exactly two pizzas in such a way as to please the maximum number of people in the company. It is known that a person is pleased with the choice if each of his/her favorite ingredients is in at least one ordered pizza. If there are several ways to choose two pizzas so as to please the maximum number of friends, then choose the one that minimizes the total price of two pizzas.
-----Input-----
The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 10^5, 2 \le m \le 10^5$) β the number of friends in the company and the number of pizzas, respectively.
Next, the $n$ lines contain descriptions of favorite ingredients of the friends: the $i$-th of them contains the number of favorite ingredients $f_i$ ($1 \le f_i \le 9$) and a sequence of distinct integers $b_{i1}, b_{i2}, \dots, b_{if_i}$ ($1 \le b_{it} \le 9$).
Next, the $m$ lines contain pizza descriptions: the $j$-th of them contains the integer price of the pizza $c_j$ ($1 \le c_j \le 10^9$), the number of ingredients $r_j$ ($1 \le r_j \le 9$) and the ingredients themselves as a sequence of distinct integers $a_{j1}, a_{j2}, \dots, a_{jr_j}$ ($1 \le a_{jt} \le 9$).
-----Output-----
Output two integers $j_1$ and $j_2$ ($1 \le j_1,j_2 \le m$, $j_1 \ne j_2$) denoting the indices of two pizzas in the required set. If there are several solutions, output any of them. Pizza indices can be printed in any order.
-----Examples-----
Input
3 4
2 6 7
4 2 3 9 5
3 2 3 9
100 1 7
400 3 3 2 5
100 2 9 2
500 3 2 9 5
Output
2 3
Input
4 3
1 1
1 2
1 3
1 4
10 4 1 2 3 4
20 4 1 2 3 4
30 4 1 2 3 4
Output
1 2
Input
1 5
9 9 8 7 6 5 4 3 2 1
3 4 1 2 3 4
1 4 5 6 7 8
4 4 1 3 5 7
1 4 2 4 6 8
5 4 1 9 2 8
Output
2 4 | import sys
def popcount(i):
assert 0 <= i < 4294967296
i = i - (i >> 1 & 1431655765)
i = (i & 858993459) + (i >> 2 & 858993459)
return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24
N, M = map(int, sys.stdin.readline().split())
table = [0] * 2**9
for _ in range(N):
S = tuple(map(int, sys.stdin.readline().split()))
table[sum(2 ** (a - 1) for a in S[1:])] += 1
dp = [0] * 2**9
for s in range(2**9):
ppc = popcount(s)
res = table[s]
t = s & s - 1
for _ in range(2**ppc - 1):
res += table[t]
t = t - 1 & s
dp[s] = res
table = [False] * 2**9
cost = [[] for _ in range(2**9)]
idx = [[] for _ in range(2**9)]
for i in range(M):
T = tuple(map(int, sys.stdin.readline().split()))
x = sum(2 ** (a - 1) for a in T[2:])
table[x] = True
cost[x].append(T[0])
idx[x].append(i + 1)
minidx = [(cost[x].index(min(cost[x])) if cost[x] else -1) for x in range(2**9)]
mincost = [10**10] * 2**9
mincostidx = [(0, 0) for _ in range(2**9)]
reachable = [False] * 2**9
for i in range(2**9):
if not table[i]:
continue
for j in range(2**9):
if not table[j]:
continue
reachable[i | j] = True
if i != j:
mi = min(cost[i])
mj = min(cost[j])
if mincost[i | j] > mi + mj:
mincost[i | j] = mi + mj
mincostidx[i | j] = idx[i][minidx[i]], idx[j][minidx[j]]
ctr = -1
candi = []
for i in range(2**9):
if not reachable[i]:
continue
if ctr > dp[i]:
continue
elif ctr == dp[i]:
candi.append(i)
else:
ctr = dp[i]
candi = [i]
ans = 10**11
Ans = -1, -1
for c in candi:
if table[c] and len(cost[c]) > 1:
D = cost[c][:]
res = min(D)
a = D.index(res)
D.remove(res)
r = min(D)
b = D.index(r)
if cost[c][b] != r:
b += 1
if a == b:
b += 1
res += r
if ans > res:
ans = res
Ans = idx[c][a], idx[c][b]
if ans > mincost[c]:
ans = mincost[c]
Ans = mincostidx[c]
print(*Ans) | IMPORT FUNC_DEF NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR IF VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
ans = [0]
mask = 1
for l in range(n):
for c in ans[::-1]:
ans.append(mask | c)
mask <<= 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
if n == 0:
return [0]
result = [0, 1]
for i in range(2, n + 1):
mask = 1 << i - 1
temp = []
for j in range(len(result)):
temp.append(result[-j - 1] | mask)
result += temp
return result | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
if n == 0:
return [0]
concat = ""
res = [0, 1]
for i in range(1, n):
newRes = []
for j in res:
newRes.append(j)
for j in reversed(res):
newRes.append(j + 2**i)
res = newRes
return res | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR STRING ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR VAR RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
if n < 0:
return []
elif n == 0:
return [0]
elif n == 1:
return [0, 1]
result = [0, 1]
res_len = 2**n
cnt = 1
while len(result) != res_len:
cnt *= 2
result.extend(result[::-1])
offset = 0
for i in range(len(result)):
if i > 0 and i % cnt == 0:
offset = cnt
result[i] += offset
return result | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST NUMBER IF VAR NUMBER RETURN LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def helper(self, n):
if n == 0:
return ["0"]
if n == 1:
return ["0", "1"]
ret = []
for code in self.helper(n - 1):
ret.append("0" + code)
for code in reversed(self.helper(n - 1)):
ret.append("1" + code)
return ret
def grayCode(self, n):
if n == 0:
return [0]
ret = []
code = self.grayCode(n - 1)
ret += code
for v in reversed(code):
ret.append(2 ** (n - 1) + v)
return ret | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST STRING IF VAR NUMBER RETURN LIST STRING STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR RETURN VAR FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
result = [0]
for i in range(n):
temp = []
for num in result:
temp.append(num + 2**i)
result += temp[::-1]
return result | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
if n == 0:
return [0]
q = [0, -1]
for i in range(n):
tag = 0
while q[0] != -1:
item = q.pop(0)
q.append(item * 2 + tag)
q.append(item * 2 + (1 - tag))
tag = 1 - tag
q.pop(0)
q.append(-1)
q.pop(-1)
return q | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN VAR |
The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
Example 1:
Input:Β 2
Output:Β [0,1,3,2]
Explanation:
00 - 0
01 - 1
11 - 3
10 - 2
For a givenΒ n, a gray code sequence may not be uniquely defined.
For example, [0,2,3,1] is also a valid gray code sequence.
00 - 0
10 - 2
11 - 3
01 - 1
Example 2:
Input:Β 0
Output:Β [0]
Explanation: We define the gray code sequence to begin with 0.
Β A gray code sequence of n has size = 2n, which for n = 0 the size is 20 = 1.
Β Therefore, for n = 0 the gray code sequence is [0]. | class Solution:
def grayCode(self, n):
result = [0, 1]
if n <= 1:
return result[: n + 1]
res_len = 2**n
cnt = 1
while len(result) != res_len:
cnt *= 2
result.extend(result[::-1])
start = len(result) // 2
for i in range(start, len(result)):
result[i] += cnt
return result | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR |
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
* the winner of the tournament gets place 1;
* the team eliminated in the finals gets place 2;
* both teams eliminated in the semifinals get place 3;
* all teams eliminated in the quarterfinals get place 5;
* all teams eliminated in the 1/8 finals get place 9, and so on.
For example, this picture describes one of the possible ways the tournament can go with k = 3, and the resulting places of the teams:
<image>
After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let p_i be the place of the i-th team in the tournament. The hash value of the tournament h is calculated as h = (β _{i=1}^{2^k} i β
A^{p_i}) mod 998244353, where A is some given integer.
Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of k, A and h. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.
Input
The only line contains three integers k, A and h (1 β€ k β€ 5; 100 β€ A β€ 10^8; 0 β€ h β€ 998244352).
Output
If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer -1.
Otherwise, print 2^k integers, where i-th integer should be equal to p_i (the place of the i-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams 1 and 2 always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.
Examples
Input
3 1337 75275197
Output
5 3 5 2 1 5 5 3
Input
2 100 5040100
Output
1 3 3 2
Input
2 100 7020100
Output
-1
Note
The tournament for the first example is described in the statement.
For the third example, the placing [1, 2, 3, 3] (team 1 gets place 1, team 2 gets place 2, teams 3 and 4 get place 3) could result in a hash value of 7020100 with A = 100, but no tournament can result in such placing since teams 1 and 2 play against each other in the semifinals, so they cannot get two first places. | from itertools import product
M = 998244353
k, A, h = map(int, input().split())
def play_half(os, lo, lo_win):
j = 0
teams = list(range(2 ** (k - 1)))
places = [(0) for _ in teams]
for i in range(k - 1):
tt = []
z = 2 ** (k - 2 - i)
for r in range(z):
o = os[j]
j += 1
places[teams[r * 2 + o]] = z * 2 + 1
tt.append(teams[r * 2 + (1 - o)])
teams = tt
places[teams[0]] = 1 + (lo != lo_win)
h = (
sum((i + 1 + [len(places), 0][lo]) * pow(A, v, M) for i, v in enumerate(places))
% M
)
return h, places
def find():
for lo_win in [0, 1]:
lo = {}
z = 0
for p in product(*([0, 1] for _ in range(2 ** (k - 1) - 1))):
x, y = play_half(p, True, lo_win)
z += 1
lo[x] = y
for p in product(*([0, 1] for _ in range(2 ** (k - 1) - 1))):
x, y = play_half(p, False, lo_win)
if (h - x) % M in lo:
return " ".join(map(str, lo[(h - x) % M] + y))
return -1
print(find()) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER LIST FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF FOR VAR LIST NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR |
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
* the winner of the tournament gets place 1;
* the team eliminated in the finals gets place 2;
* both teams eliminated in the semifinals get place 3;
* all teams eliminated in the quarterfinals get place 5;
* all teams eliminated in the 1/8 finals get place 9, and so on.
For example, this picture describes one of the possible ways the tournament can go with k = 3, and the resulting places of the teams:
<image>
After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let p_i be the place of the i-th team in the tournament. The hash value of the tournament h is calculated as h = (β _{i=1}^{2^k} i β
A^{p_i}) mod 998244353, where A is some given integer.
Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of k, A and h. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.
Input
The only line contains three integers k, A and h (1 β€ k β€ 5; 100 β€ A β€ 10^8; 0 β€ h β€ 998244352).
Output
If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer -1.
Otherwise, print 2^k integers, where i-th integer should be equal to p_i (the place of the i-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams 1 and 2 always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.
Examples
Input
3 1337 75275197
Output
5 3 5 2 1 5 5 3
Input
2 100 5040100
Output
1 3 3 2
Input
2 100 7020100
Output
-1
Note
The tournament for the first example is described in the statement.
For the third example, the placing [1, 2, 3, 3] (team 1 gets place 1, team 2 gets place 2, teams 3 and 4 get place 3) could result in a hash value of 7020100 with A = 100, but no tournament can result in such placing since teams 1 and 2 play against each other in the semifinals, so they cannot get two first places. | MOD = 998244353
k, A, H = map(int, input().split())
sgames = 2 ** (k - 1) - 1
steams = 2 ** (k - 1)
def build(wp: int, offset: int):
pos = {}
for outcomes in range(2**sgames):
i = 0
res = 0
teams = [i for i in range(steams)]
place = [-1] * steams
for p in range(k - 1, 0, -1):
nteams = []
for a, b in zip(teams[::2], teams[1::2]):
winner = outcomes & 1 << i
i += 1
if winner:
a, b = b, a
nteams.append(a)
place[b] = 2**p + 1
teams = nteams
assert len(teams) == 1, teams
place[teams[0]] = wp
h = 0
for i, p in enumerate(place):
h = (h + (i + offset + 1) * pow(A, p, MOD)) % MOD
pos[h] = place
return pos
W1, L1 = build(1, 0), build(2, 0)
W2, L2 = build(1, steams), build(2, steams)
for a, b in ((W1, L2), (L1, W2)):
for h1, p1 in a.items():
h2 = (H - h1) % MOD
p2 = b.get(h2)
if p2 is not None:
print(*(p1 + p2))
raise SystemExit
print(-1) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_DEF VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER |
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
* the winner of the tournament gets place 1;
* the team eliminated in the finals gets place 2;
* both teams eliminated in the semifinals get place 3;
* all teams eliminated in the quarterfinals get place 5;
* all teams eliminated in the 1/8 finals get place 9, and so on.
For example, this picture describes one of the possible ways the tournament can go with k = 3, and the resulting places of the teams:
<image>
After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let p_i be the place of the i-th team in the tournament. The hash value of the tournament h is calculated as h = (β _{i=1}^{2^k} i β
A^{p_i}) mod 998244353, where A is some given integer.
Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of k, A and h. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.
Input
The only line contains three integers k, A and h (1 β€ k β€ 5; 100 β€ A β€ 10^8; 0 β€ h β€ 998244352).
Output
If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer -1.
Otherwise, print 2^k integers, where i-th integer should be equal to p_i (the place of the i-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams 1 and 2 always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.
Examples
Input
3 1337 75275197
Output
5 3 5 2 1 5 5 3
Input
2 100 5040100
Output
1 3 3 2
Input
2 100 7020100
Output
-1
Note
The tournament for the first example is described in the statement.
For the third example, the placing [1, 2, 3, 3] (team 1 gets place 1, team 2 gets place 2, teams 3 and 4 get place 3) could result in a hash value of 7020100 with A = 100, but no tournament can result in such placing since teams 1 and 2 play against each other in the semifinals, so they cannot get two first places. | k, A, h = map(int, input().split())
team = 1 << k
mod = 998244353
POW = [1]
for i in range(100):
POW.append(POW[-1] * A % mod)
ANS = [(1 << k - 1) + 1] * (team // 2)
X = tuple([i for i in range(team // 2)])
ALLLIST = []
def half_all(ANS, X, Y, i):
if i == 0:
ALLLIST.append(tuple(ANS))
return ANS
if X == tuple():
X = Y
Y = tuple()
half_all(ANS, X, Y, i - 1)
return
X = list(X)
ANS = list(ANS)
p = X.pop()
q = X.pop()
ANS[p] = ANS[p] // 2 + 1
half_all(tuple(ANS), tuple(X), Y + (p,), i)
ANS[p] = ANS[p] * 2 - 1
ANS[q] = ANS[q] // 2 + 1
half_all(tuple(ANS), tuple(X), Y + (q,), i)
half_all(ANS, X, tuple(), k - 1)
SCORE01 = [0] * len(ALLLIST)
SCORE02 = [0] * len(ALLLIST)
SCORE11 = [0] * len(ALLLIST)
SCORE12 = [0] * len(ALLLIST)
for i in range(len(ALLLIST)):
LIST = ALLLIST[i]
sc01 = sc02 = sc11 = sc12 = 0
for j in range(team // 2):
if LIST[j] != 2:
sc01 += (j + 1) * POW[LIST[j]] % mod
sc02 += (j + 1) * POW[LIST[j]] % mod
sc01 %= mod
sc02 %= mod
sc11 += (j + 1 + team // 2) * POW[LIST[j]] % mod
sc12 += (j + 1 + team // 2) * POW[LIST[j]] % mod
sc11 %= mod
sc12 %= mod
else:
sc01 += (j + 1) * POW[1] % mod
sc02 += (j + 1) * POW[2] % mod
sc01 %= mod
sc02 %= mod
sc11 += (j + 1 + team // 2) * POW[1] % mod
sc12 += (j + 1 + team // 2) * POW[2] % mod
sc11 %= mod
sc12 %= mod
SCORE01[i] = sc01
SCORE02[i] = sc02
SCORE11[i] = sc11
SCORE12[i] = sc12
SCSET11 = set(SCORE11)
SCSET12 = set(SCORE12)
for i in range(len(ALLLIST)):
if (h - SCORE01[i]) % mod in SCSET12:
k = SCORE12.index((h - SCORE01[i]) % mod)
LANS = list(ALLLIST[i] + ALLLIST[k])
for j in range(len(LANS)):
if LANS[j] == 2:
LANS[j] = 1
break
print(*LANS)
break
if (h - SCORE02[i]) % mod in SCSET11:
k = SCORE11.index((h - SCORE02[i]) % mod)
LANS = list(ALLLIST[i] + ALLLIST[k])
for j in range(len(LANS) - 1, -1, -1):
if LANS[j] == 2:
LANS[j] = 1
break
print(*LANS)
break
else:
print(-1) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
* the winner of the tournament gets place 1;
* the team eliminated in the finals gets place 2;
* both teams eliminated in the semifinals get place 3;
* all teams eliminated in the quarterfinals get place 5;
* all teams eliminated in the 1/8 finals get place 9, and so on.
For example, this picture describes one of the possible ways the tournament can go with k = 3, and the resulting places of the teams:
<image>
After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let p_i be the place of the i-th team in the tournament. The hash value of the tournament h is calculated as h = (β _{i=1}^{2^k} i β
A^{p_i}) mod 998244353, where A is some given integer.
Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of k, A and h. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.
Input
The only line contains three integers k, A and h (1 β€ k β€ 5; 100 β€ A β€ 10^8; 0 β€ h β€ 998244352).
Output
If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer -1.
Otherwise, print 2^k integers, where i-th integer should be equal to p_i (the place of the i-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams 1 and 2 always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.
Examples
Input
3 1337 75275197
Output
5 3 5 2 1 5 5 3
Input
2 100 5040100
Output
1 3 3 2
Input
2 100 7020100
Output
-1
Note
The tournament for the first example is described in the statement.
For the third example, the placing [1, 2, 3, 3] (team 1 gets place 1, team 2 gets place 2, teams 3 and 4 get place 3) could result in a hash value of 7020100 with A = 100, but no tournament can result in such placing since teams 1 and 2 play against each other in the semifinals, so they cannot get two first places. | import sys
def pr(x):
sys.stdout.write(str(x) + "\n")
def inp():
return sys.stdin.readline()
M = 998244353
k, a, h = [int(i) for i in inp().split()]
pp = [[], [2], [3, 2], [5, 3, 2], [9, 5, 3, 2], [17, 9, 5, 3, 2]]
pa = [(a**i % M) for i in pp[k]]
rgs = [
[],
[[1, 3]],
[[4, 7], [1, 5]],
[[16, 21], [6, 13], [1, 9]],
[[64, 73], [28, 41], [10, 25], [1, 17]],
[[256, 273], [120, 145], [52, 81], [18, 49], [1, 33]],
]
rg = rgs[k]
xa = {}
for i in range(1, (1 << k) + 1):
xa[i * a % M] = i
r = [0] * (k + 1)
def dfs(n, num):
if n == k:
x = (h + M - num) % M
if x in xa:
r[n] = xa[x]
if sum(r) == sum(range(1, (1 << k) + 1)):
return True
else:
for i in range(rg[n][0], rg[n][1]):
r[n] = i
if dfs(n + 1, (num + i * pa[n]) % M):
return True
return False
if not dfs(0, 0):
pr(-1)
sys.exit()
if sum(r) != sum(range(1, (1 << k) + 1)):
pr(-1)
sys.exit()
res = [pp[k][0]] * (1 << k)
res[r[-1] - 1] = 1
res[r[-2] - 1] = 2
if (r[-1] - 1) // 1 << k - 1 == (r[-2] - 1) // 1 << k - 1:
pr(-1)
sys.exit()
for i in range(k - 2, 0, -1):
t = [1] * (1 << k - i)
for j in range(1 << k):
if res[j] != pp[k][0]:
t[j // (1 << i)] = 0
r[i] -= sum((j * 1 << i) + 1 for j in range(len(t)) if t[j])
for j in range(len(t)):
if t[j]:
x = min(r[i], (1 << i) - 1)
r[i] -= x
res[j * (1 << i) + x] = pp[k][i]
if r[i]:
pr(-1)
sys.exit()
print(" ".join(str(i) for i in res)) | IMPORT FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST LIST NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST LIST LIST LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR |
2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
* the winner of the tournament gets place 1;
* the team eliminated in the finals gets place 2;
* both teams eliminated in the semifinals get place 3;
* all teams eliminated in the quarterfinals get place 5;
* all teams eliminated in the 1/8 finals get place 9, and so on.
For example, this picture describes one of the possible ways the tournament can go with k = 3, and the resulting places of the teams:
<image>
After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let p_i be the place of the i-th team in the tournament. The hash value of the tournament h is calculated as h = (β _{i=1}^{2^k} i β
A^{p_i}) mod 998244353, where A is some given integer.
Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of k, A and h. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.
Input
The only line contains three integers k, A and h (1 β€ k β€ 5; 100 β€ A β€ 10^8; 0 β€ h β€ 998244352).
Output
If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer -1.
Otherwise, print 2^k integers, where i-th integer should be equal to p_i (the place of the i-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams 1 and 2 always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.
Examples
Input
3 1337 75275197
Output
5 3 5 2 1 5 5 3
Input
2 100 5040100
Output
1 3 3 2
Input
2 100 7020100
Output
-1
Note
The tournament for the first example is described in the statement.
For the third example, the placing [1, 2, 3, 3] (team 1 gets place 1, team 2 gets place 2, teams 3 and 4 get place 3) could result in a hash value of 7020100 with A = 100, but no tournament can result in such placing since teams 1 and 2 play against each other in the semifinals, so they cannot get two first places. | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def LI1():
return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number):
return [LI1() for _ in range(rows_number)]
def SI():
return sys.stdin.readline().rstrip()
inf = 10**16
md = 998244353
def cal_all(l, r, top):
n = r - l - 1
res = {}
for bit in range(1 << n):
tt = list(range(l, r))
ntt = []
p = len(tt) + 1
cur = 0
for i in range(n):
t0 = tt.pop()
t1 = tt.pop()
if bit >> i & 1:
win, lose = t0, t1
else:
win, lose = t1, t0
cur += lose * pow(a, p, md) % md
cur %= md
ntt.append(win)
if not tt:
tt, ntt = ntt, tt
p = len(tt) + 1
t = tt[0]
cur += t * pow(a, top, md) % md
res[cur % md] = bit
return res
def team(bit, l, r, top):
res = [-1] * (r - l)
tt = list(range(l, r))
ntt = []
p = len(tt) + 1
for i in range(r - l - 1):
t0 = tt.pop()
t1 = tt.pop()
if bit >> i & 1:
win, lose = t0, t1
else:
win, lose = t1, t0
res[lose - l] = p
ntt.append(win)
if not tt:
tt, ntt = ntt, tt
p = len(tt) + 1
t = tt[0]
res[t - l] = top
return res
def search(ss, tt, stop, ttop):
for s in ss.keys():
if (h - s) % md in tt:
b1 = ss[s]
b2 = tt[(h - s) % md]
return team(b1, 1, 1 + (1 << k - 1), stop) + team(
b2, 1 + (1 << k - 1), 1 + (1 << k), ttop
)
return []
k, a, h = LI()
ss = cal_all(1, 1 + (1 << k - 1), 1)
tt = cal_all(1 + (1 << k - 1), 1 + (1 << k), 2)
ans = search(ss, tt, 1, 2)
if ans:
print(*ans)
exit()
ss = cal_all(1, 1 + (1 << k - 1), 2)
tt = cal_all(1 + (1 << k - 1), 1 + (1 << k), 1)
ans = search(ss, tt, 2, 1)
if ans:
print(*ans)
else:
print(-1) | IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER VAR VAR RETURN LIST ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | memo = dict()
def knpsk(c, w, index, k):
if index in memo.keys():
if k in memo[index].keys():
return memo[index][k]
if k == 0 or index == -1:
return 0
if c[index] > k:
return knpsk(c, w, index - 1, k)
if index not in memo:
memo[index] = dict()
memo[index][k] = max(
w[index] + knpsk(c, w, index - 1, k - c[index]), knpsk(c, w, index - 1, k)
)
return memo[index][k]
tcase = int(input())
while tcase > 0:
tcase -= 1
c, w = [], []
n, k = map(int, input().split())
for i in range(n):
cost, weight = map(int, input().split())
c.append(cost)
w.append(weight)
print(knpsk(c, w, n - 1, k))
memo = dict() | ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR 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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def make_set(arr, l):
ans = []
for i in range(2**l):
bits = bin(i)[2:]
bits = "0" * (l - len(bits)) + bits
temp = []
for x in range(l):
if bits[x] == "1":
temp += [arr[x]]
ans += [temp]
return ans
t = int(input())
for i in range(t):
n, k = map(int, input().split())
arr = []
for j in range(n):
c, w = map(int, input().split())
arr += [[c, w]]
s = make_set(arr, n)
maxw = 0
for j in s:
cost = 0
weight = 0
for x in j:
weight += x[1]
cost += x[0]
if weight > maxw and cost <= k:
maxw = weight
print(maxw) | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR LIST VAR VAR VAR LIST VAR RETURN VAR 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR LIST LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | import itertools
import sys
T = int(sys.stdin.readline())
for _ in range(T):
n, k = list(map(int, sys.stdin.readline().split()))
cost, weight = zip(
*[list(map(int, sys.stdin.readline().split())) for _ in range(n)]
)
weights = []
for seq in itertools.product([0, 1], repeat=n):
if sum(x * y for x, y in zip(seq, cost)) <= k:
weights.append(sum(x * y for x, y in zip(seq, weight)))
print(max(weights)) | IMPORT IMPORT 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 VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR LIST NUMBER NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def bitmask(cost, wt, W, n):
s = ""
for i in range(n):
s += "1"
s = int(s, 2)
ans = 0
for i in range(1, s + 1):
curr = i
curr_val, j = 0, n - 1
curr_cost = W
while curr != 0:
if curr & 1:
if curr_cost - cost[j] >= 0:
curr_val += wt[j]
curr_cost -= cost[j]
j -= 1
curr = curr >> 1
ans = max(curr_val, ans)
return ans
for _ in range(int(input())):
n, W = map(int, input().split())
cost, wt = [], []
for i in range(n):
a, b = map(int, input().split())
cost.append(a)
wt.append(b)
ans = bitmask(cost, wt, W, n)
print(ans) | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN 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 VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | T = int(input())
for t in range(T):
n, k = [int(i) for i in input().split(" ")]
C = []
W = []
for X in range(n):
c, w = [int(i) for i in input().split(" ")]
C.append(c)
W.append(w)
maxwt = 0
for i in range(1 << n):
curwt = 0
curcost = 0
for j in range(n):
if i & 1 << j:
curcost += C[j]
curwt += W[j]
if curcost <= k:
maxwt = max(maxwt, curwt)
print(maxwt) | 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | import sys
from itertools import combinations as combn
stdin = sys.stdin
for i, line in enumerate(stdin):
if i == 0:
T = int(line.strip())
N = -1
oranges = []
cur_i = 0
elif cur_i > N:
N, K = [int(s) for s in line.strip().split(" ")]
oranges = []
cur_i = 1
else:
oranges += [[int(s) for s in line.strip().split(" ")]]
if cur_i == N:
oranges = [[cost, weight] for cost, weight in oranges if cost <= K]
max_weight = 0
for size in range(1, len(oranges) + 1):
baskets = [
basket
for basket in combn(oranges, size)
if sum(cost for cost, _ in basket) <= K
]
if baskets:
max_weight = max(
max_weight,
max(sum(weight for _, weight in basket) for basket in baskets),
)
print(max_weight)
cur_i += 1 | IMPORT ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER VAR LIST FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | from itertools import combinations
for _ in range(int(input())):
toranges, trubles = list(map(int, input().split()))
ocost_oweight = []
for i in range(toranges):
ocost_oweight.append(list(map(int, input().split())))
pos_choices = []
for i in range(1, toranges + 1):
pos_choices.append(list(combinations(ocost_oweight, i)))
pos_weights = []
for choice_type in pos_choices:
for choice in choice_type:
weight = 0
cost = 0
feasible = True
for pair in choice:
weight += pair[1]
cost += pair[0]
if cost > trubles:
feasible = False
break
if feasible:
pos_weights.append(weight)
print(max(pos_weights)) | 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def knapsack(k, c, w, n):
if n == 0 or k == 0:
return 0
if c[n - 1] > k:
return knapsack(k, c, w, n - 1)
else:
return max(
w[n - 1] + knapsack(k - c[n - 1], c, w, n - 1), knapsack(k, c, w, n - 1)
)
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
cost = []
weight = []
for _ in range(n):
c, w = map(int, input().split())
cost.append(c)
weight.append(w)
print(knapsack(k, cost, weight, len(cost))) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def snek(l, a, k, s, b):
if a == len(l):
return s
if b == 0:
return max(snek(l, a + 1, k, s, 0), snek(l, a + 1, k, s, 1))
if b == 1:
if l[a][0] <= k:
k -= l[a][0]
s += l[a][1]
return max(snek(l, a + 1, k, s, 0), snek(l, a + 1, k, s, 1))
else:
return s
t = int(input())
for i in range(t):
n, k = map(int, input().split())
l1 = []
for j in range(n):
l1.append(list(map(int, input().split())))
print(max(snek(l1, 0, k, 0, 0), snek(l1, 0, k, 0, 1))) | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | import itertools
t = int(input().strip())
for i in range(t):
[n, k] = map(int, input().strip().split(" "))
l = []
for j in range(n):
s = list(map(int, input().strip().split(" ")))
l.append(s)
l1 = []
for L in range(0, n + 1):
for i in itertools.combinations(l, L):
l1.append(i)
w2 = 0
for j in range(len(l1)):
p = l1[j]
c1 = 0
w1 = 0
for m in range(len(p)):
c1 += p[m][0]
w1 += p[m][1]
if c1 <= k:
w2 = max(w2, w1)
print(w2) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def solve(C, W, K):
n = len(C)
max_ = 0
for i in range(1 << n):
weight = 0
ans = []
k = K
for j in range(n):
if i & 1 << j:
ans.append(W[j])
if C[j] <= k:
k -= C[j]
weight += W[j]
max_ = max(max_, weight)
return max_
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
C = []
W = []
for i in range(n):
c, w = map(int, input().split())
C.append(c)
W.append(w)
print(solve(C, W, k)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | ans = []
def solve(id, remW):
if remW <= 0 or id == n:
return 0
marker = id, remW
if marker in memo:
return memo[marker]
ans = solve(id + 1, remW)
if remW >= pairs[id][0]:
ans = max(ans, solve(id + 1, remW - pairs[id][0]) + pairs[id][1])
memo[marker] = ans
return ans
for t in range(int(input())):
[n, k] = [int(i) for i in input().split()]
memo = {}
pairs = []
for i in range(n):
pairs.append([int(i) for i in input().split()])
ans.append(str(solve(0, k)))
print("\n".join(ans)) | ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def knapsack(W, cost, wt, n):
if n < 0 or W == 0:
return 0
if cost[n] > W:
return knapsack(W, cost, wt, n - 1)
else:
inc = wt[n] + knapsack(W - cost[n], cost, wt, n - 1)
exc = knapsack(W, cost, wt, n - 1)
return max(inc, exc)
for _ in range(int(input())):
n, W = map(int, input().split())
cost, wt = [], []
for i in range(n):
a, b = map(int, input().split())
cost.append(a)
wt.append(b)
ans = knapsack(W, cost, wt, n - 1)
print(ans) | FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR 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 VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def solve(costs, weights, k, n):
limit = 2**n
ans = float("-inf")
for i in range(1, limit):
rep = "{:0" + str(n) + "b}"
rep = [int(x) for x in rep.format(i)]
curr_sum = sum([(x * y) for x, y in zip(weights, rep)])
curr_cost = sum([(x * y) for x, y in zip(costs, rep)])
if curr_cost <= k:
ans = max(ans, curr_sum)
return ans
for t in range(int(input())):
n, k = [int(x) for x in input().split()]
costs = []
weights = []
for i in range(n):
a, b = [int(x) for x in input().split()]
costs.append(a)
weights.append(b)
print(solve(costs, weights, k, n)) | FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | for _ in range(int(input())):
n, k = map(int, input().split())
app = []
for i in range(n):
cost, weight = map(int, input().split())
app.append([cost, weight])
maxi = 0
def calc(curr):
sm = 0
ans = 0
for i in curr:
sm += app[i][0]
ans += app[i][1]
if sm <= k:
return ans
return 0
tot = 1 << n
for i in range(tot):
curr = []
for j in range(n):
if i & 1 << j:
curr.append(j)
maxi = max(maxi, calc(curr))
print(maxi) | 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 LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def search(n, k, c, w):
if k == 0:
return 0
elif n == 0:
return 0
elif k < c[n - 1]:
return search(n - 1, k, c, w)
else:
return max(search(n - 1, k, c, w), w[n - 1] + search(n - 1, k - c[n - 1], c, w))
t = int(input())
for i in range(t):
n, k = map(int, input().split())
c = [(0) for x in range(n)]
w = [(0) for y in range(n)]
for j in range(n):
c[j], w[j] = map(int, input().split())
print(search(n, k, c, w)) | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR 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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | from itertools import combinations
for _ in range(int(input())):
n, k = map(int, input().split())
a = []
b = []
c = list(range(n))
for _ in range(n):
d, e = map(int, input().split())
a.append(d)
b.append(e)
ans = 0
for r in range(1, n + 1):
x = combinations(c, r)
for i in x:
cost = 0
weight = 0
for j in i:
cost += a[j]
weight += b[j]
if cost <= k and weight > ans:
ans = weight
print(ans) | 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 LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | def mainstuff(k, cost, weight):
global a
m = -1
for i in range(2 ** len(cost)):
t = list(map(int, list(str(format(i, "0" + str(n) + "b")))))
t1 = sum([(a * b) for a, b in zip(cost, t)])
t2 = sum([(a * b) for a, b in zip(weight, t)])
if t1 <= k:
if t2 > m:
m = t2
print(m)
t = int(input())
for a0 in range(t):
n, k = map(int, input().strip().split(" "))
cost = []
weight = []
t = {}
for a1 in range(n):
t1, t2 = map(int, input().strip().split(" "))
cost.append(t1)
weight.append(t2)
mainstuff(k, cost, weight) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR 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 FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
Read problems statements in Russian also.
Chef likes shopping, and especially he likes to buy oranges. But right now he is short of money. He has only k rubles. There are n oranges. The i-th one costs cost_{i} rubles and has weight equal to weight_{i}. Chef wants to buy a set of oranges with the maximal possible weight. Please help him, and tell him this weight.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The first line of each test case contains two numbers n and k. The following n lines contain two numbers cost_{i} and weight_{i} respectively.
------ Output ------
For each test case, output a single line containing maximal weight among all the affordable sets of oranges.
------ Constraints ------
$1 β€ T β€ 250 $
$1 β€ n β€ 10 $
$1 β€ k β€ 100000000 $
$1 β€ weight_{i} β€ 100000000 $
$1 β€ cost_{i} β€ 100000000 $
------ Scoring ------
Subtask 1 (30 points): All the oranges' weights equals to 1.
Subtask 2 (30 points): N = 5
Subtask 2 (40 points): See the constraints
----- Sample Input 1 ------
2
1 3
2 2
3 4
2 1
2 2
3 5
----- Sample Output 1 ------
2
5 | from itertools import combinations
try:
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
weight = []
cost = []
ind = []
res = 0
for i in range(n):
c, w = map(int, input().split())
weight.append(w)
cost.append(c)
ind.append(i)
maxk = -float("inf")
for i in range(1, n + 1):
for itert in combinations(ind, i):
c = 0
w = 0
for j in itert:
c += cost[j]
w += weight[j]
if c <= k:
maxk = max(maxk, w)
print(maxk)
except:
pass | 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 LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
d = []
for i in range(4):
d.append(n % 2)
n //= 2
x = 1
for i in range(3, -1, -1):
d[i] ^= x
x &= d[i]
r = 0
for v in d[::-1]:
r = 2 * r + v
print(r) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
bits = bin(n + 16)[3:]
bits = [int(x) for x in bits]
bits[0] ^= 1
if bits[0]:
bits[1] ^= 1
if bits[0] and bits[1]:
bits[2] ^= 1
if bits[0] and bits[1] and bits[2]:
bits[3] ^= 1
print(int("".join(str(x) for x in bits), 2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | N = int(input())
if N:
S = bin(N)[2:]
S = "0" * (4 - len(S)) + S
Z = 0
for I in range(4):
if S[I] == "1":
Z += 2**I
S = bin(Z - 1)[2:]
S = "0" * (4 - len(S)) + S
Z = 0
for I in range(4):
if S[I] == "1":
Z += 2**I
print(Z)
else:
print(15) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | a = int(input())
if a == 0 or a == 6 or a == 9 or a == 15:
c = a
if a == 2 or a == 5 or a == 7:
c = a * 2
if a == 4 or a == 10 or a == 14:
c = a // 2
if a == 1:
c = 8
if a == 8:
c = 1
if a == 3:
c = 12
if a == 12:
c = 3
if a == 11:
c = 13
if a == 13:
c = 11
if a != 0:
e = c - 1
else:
e = 15
if e == 0 or e == 6 or e == 9 or e == 15:
f = e
if e == 2 or e == 5 or e == 7:
f = e * 2
if e == 4 or e == 10 or e == 14:
f = e // 2
if e == 1:
f = 8
if e == 8:
f = 1
if e == 3:
f = 12
if e == 12:
f = 3
if e == 11:
f = 13
if e == 13:
f = 11
print(f) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input(""))
a = [0, 0, 0, 0]
a[0] = n % 2
n = n // 2
a[1] = n % 2
n = n // 2
a[2] = n % 2
n = n // 2
a[3] = n % 2
def intnot(x):
return 0 if x == 1 else 1
a[3] = intnot(a[3])
if a[3] == 1:
a[2] = intnot(a[2])
if a[3] + a[2] == 2:
a[1] = intnot(a[1])
if a[3] + a[2] + a[1] == 3:
a[0] = intnot(a[0])
n = 8 * a[3] + 4 * a[2] + 2 * a[1] + a[0]
print(n) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF RETURN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | def run():
a = eval(input())
def get_bin(num):
result = ""
for i in [8, 4, 2, 1]:
if num >= i:
result = result + "1"
num -= i
else:
result = result + "0"
return result
def get_dec(s):
result = 0
for i in range(len(s)):
if s[i] == "1":
result += 2 ** (3 - i)
return result
a = get_bin(a)[::-1]
a = get_dec(a) - 1
if a < 0:
a = get_bin(a)
temp = ""
for i in range(len(a)):
if a[i] == "0":
temp += "1"
else:
temp += "0"
a = temp
a = get_dec(a)
a += 1
a = get_bin(a)
else:
a = get_bin(a)
a = get_dec(a[::-1])
print(a)
run() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING FOR VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR STRING RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP NUMBER BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR STRING VAR STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.