message stringlengths 2 48.6k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 318 108k | cluster float64 8 8 | __index_level_0__ int64 636 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} (note that i_j < i_{j+1}, because Orac arranged them properly), i_{j+1} is divisible by i_j and s_{i_j} < s_{i_{j+1}}.
For example, for 6 models with sizes \{3, 6, 7, 7, 7, 7\}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.
Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.
Input
The first line contains one integer t\ (1 ≤ t≤ 100): the number of queries.
Each query contains two lines. The first line contains one integer n\ (1≤ n≤ 100 000): the number of models in the shop, and the second line contains n integers s_1,...,s_n\ (1≤ s_i≤ 10^9): the sizes of models.
It is guaranteed that the total sum of n is at most 100 000.
Output
Print t lines, the i-th of them should contain the maximum number of models that Orac can buy for the i-th query.
Example
Input
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
Output
2
3
1
1
Note
In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.
In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.
In the third query, there are no beautiful arrangements with more than one model.
Submitted Solution:
```
#include <CodeforcesSoutions(contestID = "1350",problemID = "B").h>
"""
Author : thekushalghosh
Team : CodeDiggers
I prefer Python language over the C++ language :p :D
Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
tt = 0
################# ---- USER DEFINED INPUT FUNCTIONS ---- #################
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
return(input().strip())
def invr():
return(map(int,input().split()))
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
def solve():
n = inp()
a = inlt()
q = [0] * len(a)
w = 0
for i in range(len(a) // 2,-1,-1):
qw = 0
for j in range((2 * i) + 1,n,i + 1):
if a[j] > a[i]:
qw = max(qw,q[j] + 1)
q[i] = qw
w = max(w,qw)
print(w + 1)
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
def main():
if not ONLINE_JUDGE:
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
t = 1
t = inp()
for tt in range(t):
solve()
if not ONLINE_JUDGE:
print("Time Elapsed :",time.time() - start_time,"seconds")
sys.stdout.close()
############## ---- USER DEFINED PROGRAMMING FUNCTIONS ---- ##############
def counter(a):
q = [0] * max(a)
for i in range(len(a)):
q[a[i] - 1] = q[a[i] - 1] + 1
return(q)
def string_counter(a):
q = [0] * 26
for i in range(len(a)):
q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
return(q)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
input = sys.stdin.readline
main()
``` | instruction | 0 | 24,931 | 8 | 49,862 |
Yes | output | 1 | 24,931 | 8 | 49,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} (note that i_j < i_{j+1}, because Orac arranged them properly), i_{j+1} is divisible by i_j and s_{i_j} < s_{i_{j+1}}.
For example, for 6 models with sizes \{3, 6, 7, 7, 7, 7\}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.
Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.
Input
The first line contains one integer t\ (1 ≤ t≤ 100): the number of queries.
Each query contains two lines. The first line contains one integer n\ (1≤ n≤ 100 000): the number of models in the shop, and the second line contains n integers s_1,...,s_n\ (1≤ s_i≤ 10^9): the sizes of models.
It is guaranteed that the total sum of n is at most 100 000.
Output
Print t lines, the i-th of them should contain the maximum number of models that Orac can buy for the i-th query.
Example
Input
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
Output
2
3
1
1
Note
In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.
In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.
In the third query, there are no beautiful arrangements with more than one model.
Submitted Solution:
```
import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
n = int(input())
s = list(map(int,input().split()))
d = {i+1:1 for i in range(n)}
for i in range(1,n+1):
for j in range(i*2,n+1,i):
if s[j-1]>s[i-1]:
d[j]=d[i]+1
print(max(d.values()))
``` | instruction | 0 | 24,932 | 8 | 49,864 |
No | output | 1 | 24,932 | 8 | 49,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} (note that i_j < i_{j+1}, because Orac arranged them properly), i_{j+1} is divisible by i_j and s_{i_j} < s_{i_{j+1}}.
For example, for 6 models with sizes \{3, 6, 7, 7, 7, 7\}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.
Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.
Input
The first line contains one integer t\ (1 ≤ t≤ 100): the number of queries.
Each query contains two lines. The first line contains one integer n\ (1≤ n≤ 100 000): the number of models in the shop, and the second line contains n integers s_1,...,s_n\ (1≤ s_i≤ 10^9): the sizes of models.
It is guaranteed that the total sum of n is at most 100 000.
Output
Print t lines, the i-th of them should contain the maximum number of models that Orac can buy for the i-th query.
Example
Input
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
Output
2
3
1
1
Note
In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.
In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.
In the third query, there are no beautiful arrangements with more than one model.
Submitted Solution:
```
t = int(input())
def solve(n, arr):
dp = [1 for _ in range(n+1)] # best number of models at each point
dp[0] = 0
dp[1] = 1 # can always buy 1
for i in range(2, n+1):
# use 1 and/or enumerate out
amt = i
j = i
prev = 1
running = 1
while j < n+1:
#print(prev, j)
if arr[prev-1] < arr[j-1]:
running += 1
else:
running = 1
dp[j] = max(running, dp[j])
prev = j
j += amt
#print(dp)
return max(dp)
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
print(solve(n, arr))
``` | instruction | 0 | 24,933 | 8 | 49,866 |
No | output | 1 | 24,933 | 8 | 49,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} (note that i_j < i_{j+1}, because Orac arranged them properly), i_{j+1} is divisible by i_j and s_{i_j} < s_{i_{j+1}}.
For example, for 6 models with sizes \{3, 6, 7, 7, 7, 7\}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.
Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.
Input
The first line contains one integer t\ (1 ≤ t≤ 100): the number of queries.
Each query contains two lines. The first line contains one integer n\ (1≤ n≤ 100 000): the number of models in the shop, and the second line contains n integers s_1,...,s_n\ (1≤ s_i≤ 10^9): the sizes of models.
It is guaranteed that the total sum of n is at most 100 000.
Output
Print t lines, the i-th of them should contain the maximum number of models that Orac can buy for the i-th query.
Example
Input
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
Output
2
3
1
1
Note
In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.
In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.
In the third query, there are no beautiful arrangements with more than one model.
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
ar=[int(x) for x in input().split()]
d={}
fr={}
for i in range(n+1):
fr[i]=0
br=[]
for i in range(n):
br.append((ar[i],i+1))
br.sort(key=lambda x:x[0])
mx=0
for i in br:
temp=i[1]
val=i[1]+temp
while(val<=n):
fr[val]=max(fr[val],fr[temp]+1)
val+=temp
mx=max(mx,fr[temp])
mx+=1
print(mx)
``` | instruction | 0 | 24,934 | 8 | 49,868 |
No | output | 1 | 24,934 | 8 | 49,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n.
Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).
Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} (note that i_j < i_{j+1}, because Orac arranged them properly), i_{j+1} is divisible by i_j and s_{i_j} < s_{i_{j+1}}.
For example, for 6 models with sizes \{3, 6, 7, 7, 7, 7\}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.
Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.
Input
The first line contains one integer t\ (1 ≤ t≤ 100): the number of queries.
Each query contains two lines. The first line contains one integer n\ (1≤ n≤ 100 000): the number of models in the shop, and the second line contains n integers s_1,...,s_n\ (1≤ s_i≤ 10^9): the sizes of models.
It is guaranteed that the total sum of n is at most 100 000.
Output
Print t lines, the i-th of them should contain the maximum number of models that Orac can buy for the i-th query.
Example
Input
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
Output
2
3
1
1
Note
In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.
In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.
In the third query, there are no beautiful arrangements with more than one model.
Submitted Solution:
```
t=int(input())
while t:
t=t-1
n=int(input())
a=list(map(int,input().split()))
cnt=1
for i in range(2,n+1):
l=1
j=i+1
while(j<=n):
if a[(j//2)-1]<a[j-1]:
l+=1
if cnt<l:
cnt=l
#print(cnt,a[j-i-1],a[j-1],i,j)
else:
l=1
j=j+j
print(cnt)
``` | instruction | 0 | 24,935 | 8 | 49,870 |
No | output | 1 | 24,935 | 8 | 49,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce a board of this type that is a rectangular ai by bi block.
Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.
Vasya is required to construct a fence of length l, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled:
* there are no two successive boards of the same type
* the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one
In other words, the fence is considered beautiful, if the type of the i-th board in the fence is different from the i - 1-th board's type; besides, the i-th board's length is equal to the i - 1-th board's width (for all i, starting from 2).
Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length l.
Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109 + 7).
Input
The first line contains two integers n and l (1 ≤ n ≤ 100, 1 ≤ l ≤ 3000) — the number of different board types and the fence length, correspondingly. Next n lines contain descriptions of board types: the i-th line contains two integers ai and bi (1 ≤ ai, bi ≤ 100) — the sizes of the board of the i-th type. All numbers on the lines are separated by spaces.
Output
Print a single integer — the sought number of variants modulo 1000000007 (109 + 7).
Examples
Input
2 3
1 2
2 3
Output
2
Input
1 2
2 2
Output
1
Input
6 6
2 1
3 2
2 5
3 3
5 1
2 1
Output
20
Note
In the first sample there are exactly two variants of arranging a beautiful fence of length 3:
* As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3.
* Use one board of the second type after you turn it. That makes its length equal 3, and width — 2. | instruction | 0 | 25,020 | 8 | 50,040 |
Tags: dp
Correct Solution:
```
from sys import stdin, stdout
MOD = 10 ** 9 + 7
sze = 101
n, l = map(int, stdin.readline().split())
dp = [[[0, 0] for j in range(l + sze + 1)] for i in range(n)]
bars = []
challengers = [[] for i in range(sze)]
for i in range(n):
a, b = map(int, stdin.readline().split())
bars.append((a, b))
if a != b:
dp[i][a][1] = 1
dp[i][b][0] = 1
else:
dp[i][a][1] = 1
if a == b:
challengers[a].append((a, i))
else:
challengers[a].append((b, i))
challengers[b].append((a, i))
for j in range(l + 1):
for i in range(n):
for z in range(2):
if dp[i][j][z]:
for a, ind in challengers[bars[i][z]]:
if ind != i:
dp[ind][j + bars[i][z]][bars[ind].index(a)] = (dp[ind][j + bars[i][z]][bars[ind].index(a)] + dp[i][j][z]) % MOD
cnt = 0
for i in range(n):
cnt = (cnt + dp[i][l][0] + dp[i][l][1]) % MOD
stdout.write(str(cnt))
``` | output | 1 | 25,020 | 8 | 50,041 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce a board of this type that is a rectangular ai by bi block.
Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.
Vasya is required to construct a fence of length l, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled:
* there are no two successive boards of the same type
* the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one
In other words, the fence is considered beautiful, if the type of the i-th board in the fence is different from the i - 1-th board's type; besides, the i-th board's length is equal to the i - 1-th board's width (for all i, starting from 2).
Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length l.
Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109 + 7).
Input
The first line contains two integers n and l (1 ≤ n ≤ 100, 1 ≤ l ≤ 3000) — the number of different board types and the fence length, correspondingly. Next n lines contain descriptions of board types: the i-th line contains two integers ai and bi (1 ≤ ai, bi ≤ 100) — the sizes of the board of the i-th type. All numbers on the lines are separated by spaces.
Output
Print a single integer — the sought number of variants modulo 1000000007 (109 + 7).
Examples
Input
2 3
1 2
2 3
Output
2
Input
1 2
2 2
Output
1
Input
6 6
2 1
3 2
2 5
3 3
5 1
2 1
Output
20
Note
In the first sample there are exactly two variants of arranging a beautiful fence of length 3:
* As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3.
* Use one board of the second type after you turn it. That makes its length equal 3, and width — 2.
Submitted Solution:
```
from sys import stdin, stdout
MOD = 10 ** 9 + 7
sze = 101
n, l = map(int, stdin.readline().split())
dp = [[[0, 0] for j in range(l + sze + 1)] for i in range(n)]
bars = []
challengers = [[] for i in range(sze)]
MX = 0
for i in range(n):
a, b = map(int, stdin.readline().split())
MX = max(MX, max(a, b))
bars.append((a, b))
if a != b:
dp[i][a][1] = 1
dp[i][b][0] = 1
else:
dp[i][a][1] = 1
if a == b:
challengers[a].append((a, i))
else:
challengers[a].append((b, i))
challengers[b].append((a, i))
for j in range(l + 1):
for i in range(n):
for z in range(2):
if dp[i][j][z]:
for a, ind in challengers[bars[i][z]]:
if ind != i:
dp[ind][j + bars[i][z]][bars[ind].index(a)] = (dp[ind][j + bars[i][z]][bars[ind].index(a)] + dp[i][j][z]) % MOD
cnt = 0
for i in range(n):
cnt += dp[i][l][0] + dp[i][l][1]
stdout.write(str(cnt))
``` | instruction | 0 | 25,021 | 8 | 50,042 |
No | output | 1 | 25,021 | 8 | 50,043 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce a board of this type that is a rectangular ai by bi block.
Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.
Vasya is required to construct a fence of length l, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled:
* there are no two successive boards of the same type
* the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one
In other words, the fence is considered beautiful, if the type of the i-th board in the fence is different from the i - 1-th board's type; besides, the i-th board's length is equal to the i - 1-th board's width (for all i, starting from 2).
Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length l.
Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109 + 7).
Input
The first line contains two integers n and l (1 ≤ n ≤ 100, 1 ≤ l ≤ 3000) — the number of different board types and the fence length, correspondingly. Next n lines contain descriptions of board types: the i-th line contains two integers ai and bi (1 ≤ ai, bi ≤ 100) — the sizes of the board of the i-th type. All numbers on the lines are separated by spaces.
Output
Print a single integer — the sought number of variants modulo 1000000007 (109 + 7).
Examples
Input
2 3
1 2
2 3
Output
2
Input
1 2
2 2
Output
1
Input
6 6
2 1
3 2
2 5
3 3
5 1
2 1
Output
20
Note
In the first sample there are exactly two variants of arranging a beautiful fence of length 3:
* As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3.
* Use one board of the second type after you turn it. That makes its length equal 3, and width — 2.
Submitted Solution:
```
from collections import Counter
mod=10**9+7
n,l=map(int,input().split())
z=[]
for i in range(n):
a,b=map(int,input().split())
z.append((a,b))
dp=[[[0,0] for j in range(n)] for i in range(l+1)]
for j in range(n):
if z[j][1]<=l:
dp[z[j][1]][j][0]=1
if z[j][0]!=z[j][1]:
if z[j][0]<=l:
dp[z[j][0]][j][1]=1
for i in range(1,l+1):
for j in range(n):
for p in range(n):
if j!=p:
if z[j][0]==z[p][1]:
if i>z[j][1]:
dp[i][j][0]=(dp[i][j][0]+dp[i-z[j][1]][p][0])%mod
if z[j][0]==z[p][0]:
if i>z[j][1]:
dp[i][j][0]=(dp[i][j][0]+dp[i-z[j][1]][p][1])%mod
if z[j][0]!=z[j][1]:
if z[j][1] == z[p][1]:
if i>z[j][0]:
dp[i][j][1] = (dp[i][j][1] + dp[i - z[j][0]][p][0])%mod
if z[j][1] == z[p][0]:
if i>z[j][0]:
dp[i][j][1] = (dp[i][j][1] + dp[i - z[j][0]][p][1])%mod
else:
dp[i][j][1]=0
an=0
for j in range(n):
an=((an+dp[-1][j][0])%mod+ dp[-1][j][1])%mod
print(an)
``` | instruction | 0 | 25,022 | 8 | 50,044 |
No | output | 1 | 25,022 | 8 | 50,045 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Do you remember how Kai constructed the word "eternity" using pieces of ice as components?
Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to use as 9 (and vice versa). Similary, 2 and 5 work the same. There is no other pair of digits with similar effect. He called this effect "Digital Mimicry".
Sheldon favourite number is t. He wants to have as many instances of t as possible. How many instances he can construct using the given sequence of ice pieces. He can use any piece at most once.
Input
The first line contains integer t (1 ≤ t ≤ 10000). The second line contains the sequence of digits on the pieces. The length of line is equal to the number of pieces and between 1 and 200, inclusive. It contains digits between 0 and 9.
Output
Print the required number of instances.
Examples
Input
42
23454
Output
2
Input
169
12118999
Output
1
Note
This problem contains very weak pretests.
Submitted Solution:
```
s = list(input())
arr= list(input())
vic = {}
for i in arr:
if i in vic:
vic[i]+=1
else:
vic[i]=1
minimum = 10**9
for i in s:
if i=='2' or i=='5':
if '2' in vic and '5' in vic:
minimum = min(minimum,vic['2']+vic['5'])
elif '2' in vic:
minimum = min(minimum,vic['2'])
else:
minimum = min(minimum,vic['5'])
elif i=='6' or i=='9':
if '6' in vic and '9' in vic:
minimum = min(minimum,vic['6']+vic['9'])
elif '6' in vic:
minimum = min(minimum,vic['6'])
else:
minimum = min(minimum,vic['9'])
else:
minimum = min(minimum,vic[i])
print (minimum)
``` | instruction | 0 | 25,061 | 8 | 50,122 |
No | output | 1 | 25,061 | 8 | 50,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,098 | 8 | 50,196 |
Tags: implementation
Correct Solution:
```
n=int(input())
f=0
for i in range(n):
p,c=map(int,input().split())
if (c-2)>=p:
f+=1
print(f)
``` | output | 1 | 25,098 | 8 | 50,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,099 | 8 | 50,198 |
Tags: implementation
Correct Solution:
```
res = 0
for i in range(int(input())):
p,q = map(int, input().split())
if p+2<=q:
res+=1
print(res)
``` | output | 1 | 25,099 | 8 | 50,199 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,100 | 8 | 50,200 |
Tags: implementation
Correct Solution:
```
x=int(input())
arr=[]
for i in range(x):
arr.append(list(map(int,input().split())))
s=0
for l in range(x):
if arr[l][1]-arr[l][0]>=2:
s+=1
if s>0:
print(s)
else:
print(0)
``` | output | 1 | 25,100 | 8 | 50,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,101 | 8 | 50,202 |
Tags: implementation
Correct Solution:
```
kol=0
n=int(input())
for i in range(n):
a,b = map(int,input().split())
if b-a >= 2:
kol+=1
print(kol)
``` | output | 1 | 25,101 | 8 | 50,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,102 | 8 | 50,204 |
Tags: implementation
Correct Solution:
```
n=int(input())
x=0
for i in range(n):
p,q=(int(i) for i in input().split())
if q-p>=2:
x+=1
print(x)
``` | output | 1 | 25,102 | 8 | 50,205 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,103 | 8 | 50,206 |
Tags: implementation
Correct Solution:
```
mas = 0
for _ in range(int(input())):
p, q =[int(x) for x in input().split()]
if p + 2 <= q:
mas += 1
print(mas)
``` | output | 1 | 25,103 | 8 | 50,207 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,104 | 8 | 50,208 |
Tags: implementation
Correct Solution:
```
from sys import stdin
def fun(lines):
rooms = 0
for line in lines[1:]:
[a, b] = list(map(int, line.split(' ')))
if b - a >= 2:
rooms += 1
return str(rooms)
tests = [
[
"3\n1 1\n2 2\n3 3",
"0"
],
[
"3\n1 10\n0 10\n10 10",
"2"
]
]
# for test in tests:
# result = fun(test[0].split('\n'))
# if not (result == test[1]):
# print(f'expected {result} to equal {test[1]}')
print(fun(stdin.readlines()))
``` | output | 1 | 25,104 | 8 | 50,209 |
Provide tags and a correct Python 3 solution for this coding contest problem.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2 | instruction | 0 | 25,105 | 8 | 50,210 |
Tags: implementation
Correct Solution:
```
n = int(input())
output = 0
for i in range(n):
p, q=map(int, input().split(' '))
if q - p >= 2:
output += 1
print(output)
``` | output | 1 | 25,105 | 8 | 50,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
n=int(input())
count=0
for i in range(n):
p,q=map(int,input().split())
if p<=q-2:
count=count+1
print(count)
``` | instruction | 0 | 25,106 | 8 | 50,212 |
Yes | output | 1 | 25,106 | 8 | 50,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
n = int(input())
p = []
q = []
numberOfRooms = 0
for i in range (0 , n):
x , y = (int(e) for e in input().split(' '))
p.append(x)
q.append(y)
for i in range (0 , n):
if q[i] - p[i] >= 2 :
numberOfRooms += 1
print(numberOfRooms)
``` | instruction | 0 | 25,107 | 8 | 50,214 |
Yes | output | 1 | 25,107 | 8 | 50,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n):
p,q=list(map(int,input().split()))
a.append([p,q])
count=0
for val in a:
if (val[1]-val[0])>=2:
count+=1
print(count)
``` | instruction | 0 | 25,108 | 8 | 50,216 |
Yes | output | 1 | 25,108 | 8 | 50,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
'''
# CodeForce Equalize Prices 900 points
# a = old price / b = new price / k =value input
def Computer_Game():
for _ in range(int(input())):
k, n, a, b = map(int, input().split()) # init charge, num turns in game, a,b bat value
max_turns=0
for turns in range(n):
if k/b > n and (k-a)/b < n-1 and turns == 0:
max_turns=0
break
else:
if k > a:
k -= a
max_turns += 1
elif k > b:
k -= b
if k/b == n-turns:
max_turns = 1
break
else:
max_turns = -1
break
print(max_turns)
return
def bit_plus_plus():
summe = 0
for _ in range(int(input())):
statement = input()
if '+' in statement:
summe += 1
else:
summe -= 1
print(summe)
return
def petya_and_strings():
str_a, str_b = input().lower(), input().lower()
a=(str_a<str_b)
print((str_a>str_b)-(str_a<str_b))
return
def beautiful_matrix():
for idx in range(5):
row_input = list(map(int,input().split()))
if 1 in row_input:
row = idx+1
for idx1, elem in enumerate(row_input):
if elem == 1:
column = idx1+1
output = abs(3 - row) + abs(3 - column)
print(output)
#for row_num in range(4):
# if 1 in row(row_num)
return
def helpful_maths():
string = sorted(list(input().split('+')))
print('+'.join(string))
return
def word_capitalization():
string = input()
string_new = string[0].upper()+string[1:]
print(string_new)
return
def Stones_on_the_Table():
_ = input()
string=list(input())
color_old = ''
color_old_old = ''
take = 0
for color in string:
if color == color_old:
take += 1
else:
color_old = color
print(take)
return
def Boy_or_girl():
print([{*input()}])
string = input()
new_string = ''
for _ in string:
if _ not in new_string:
new_string = new_string + _
if len(new_string) % 2 != 0:
print('IGNORE HIM!')
else:
print('CHAT WITH HER!')
return
def soldier_and_bananas():
k,n,w = map(int,input().split())
prize = 0
for num in range(w):
prize = prize + (num+1)*k
print(prize-n if prize-n > 0 else 0)
return
def bear_and_big_brother():
a,b = map(int, input().split())
years = 0
while a <= b:
a = a*3
b = b*2
years += 1
print(years)
return
def Tram():
passenger = []
cur_pass = 0
for _ in range(int(input())):
exit_passenger, enter_passenger = map(int,input().split())
cur_pass = cur_pass - exit_passenger + enter_passenger
passenger.append(cur_pass)
print(max(passenger))
return
def subtract_one(number):
if float(number)%10 == 0:
result = number / 10
else:
result = number - 1
return int(result)
def wrong_subtraction():
n, k = map(int, input().split())
for _ in range(k):
n = subtract_one(n)
print(n)
return
def wet_shark_and_odd_and_even():
odd = []
even = []
odd_cnt = 0
n = input()
numbers = list(map(int,input().split()))
for number in numbers:
if number%2 == 0:
even.append(number)
else:
odd.append(number)
odd_cnt += 1
odd.sort()
k = int(odd_cnt/2)*2
if k > 0:
summe = sum(even) + sum(odd[-k:])
else:
summe = sum(even)
print(summe)
return
def sorting(volumes):
sorting_steps = 0
idx = 0
cnt = 0
while(idx < len(volumes)-1):
a = volumes[idx]
b = volumes[idx+1]
# print(volumes)
if a > b:
volumes[idx] = b
volumes[idx+1] = a
sorting_steps += 1
if idx > 0:
idx -= 1
else:
cnt = cnt+1
idx = cnt
else:
idx += 1
return sorting_steps
def cubes_sorting():
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
max_sort = n*(n-1)/2-1
sorting_steps = sorting(a)
if sorting_steps > max_sort:
print('NO')
else:
print('YES')
return
def elephant():
coord = int(input())
steps_taken = 0
for steps in range(5,0,-1):
if (coord / steps) >= 1:
steps_taken = int(coord / steps) + steps_taken
coord = int(coord % steps)
print(steps_taken)
return
def queue_at_the_school():
number, time = map(int,input().split())
queue=list(input())
i = 0
while i < time:
idx = 0
while idx < len(queue)-1:
if queue[idx] == 'B' and queue[idx+1] == 'G':
queue[idx] = 'G'
queue[idx+1] = 'B'
idx += 2
else:
idx += 1
i += 1
print(''.join(queue))
return
def nearly_lucky_number():
number = input()
l_number = 0
bla=[sum(i in '47' for i in number) in [4, 7]]
print('4' in number)
for elem in number:
if elem == '7' or elem == '4':
l_number += 1
print('YES' if l_number == 4 or l_number == 7 else 'NO')
return
def word():
string = input()
count = 0
for elem in string:
if elem.isupper():
count += 1
print(string.upper() if count > len(string)/2 else string.lower())
return
'''
def translation():
word_1 = input()
word_2 = input()[::-1]
print(["NO", "YES"] [word_1 == word_2])
return
def anton_and_danik():
games = int(input())
wins=input()
anton_wins = sum(i == 'A' for i in wins)
if anton_wins*2 > len(wins):
print('Anton')
elif anton_wins*2 == len(wins):
print('Friendship')
else:
print('Danik')
return
def acoomodation():
cnt = 0
for _ in range(int(input())):
p, q = map(int, input().split())
if q - p >= 2:
cnt +=1
print(cnt)
return
if __name__ == '__main__':
acoomodation()
'''
if __name__ == '__main__':
num_queries = int(input())
for querie in range(num_queries):
num_products, value_products = map(int, input().split())
price_products = list(map(int, input().split()))
B_Max = min(price_products)+value_products
B_Min = max(price_products)-value_products
if B_Max >= B_Min:
print(B_Max)
else:
print(-1)
'''
``` | instruction | 0 | 25,109 | 8 | 50,218 |
Yes | output | 1 | 25,109 | 8 | 50,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
n = int(input())
rooms = 0
for i in range(n):
p,q = list(map(int,input().split()))
if p > q or p < q:
rooms+=1
print(rooms)
``` | instruction | 0 | 25,110 | 8 | 50,220 |
No | output | 1 | 25,110 | 8 | 50,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
a=int(input())
s=0
for i in range (a):
b,c=map(int,input().split())
if c-2>b:
s+=1
else:
s+=0
print(s)
``` | instruction | 0 | 25,111 | 8 | 50,222 |
No | output | 1 | 25,111 | 8 | 50,223 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
x=int(input())
arr=[]
for i in range(x):
arr.append(list(map(int,input().split())))
s=0
for l in range(x):
if arr[l][1]-arr[l][0]>=2:
s+=1
print("yes")
if s>0:
print(s)
else:
print(0)
``` | instruction | 0 | 25,112 | 8 | 50,224 |
No | output | 1 | 25,112 | 8 | 50,225 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
Submitted Solution:
```
n = int(input())
out = 0
for i in range(n):
v = list(map(int,input().split()))
if v[1] > v[0]:
out +=1
print(out)
``` | instruction | 0 | 25,113 | 8 | 50,226 |
No | output | 1 | 25,113 | 8 | 50,227 |
Provide a correct Python 3 solution for this coding contest problem.
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future.
Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as that of town.
They all had warm and gracious personality and were close each other. However, in this year the two members of them became to hate each other. Since the two members had enormous influence in the family, they were split into two groups.
They hope that the two groups don't meet each other in the new house. Though they are in the same building, they can avoid to meet each other by adjusting passageways.
Now, you have a figure of room layout. Your task is written below.
You have to decide the two groups each room should belong to. Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group. All of the rooms need to belong to exactly one group. And any group has at least one room.
To do the task, you can cancel building passageway. Because the house is under construction, to cancel causes some cost. You'll be given the number of rooms and information of passageway. You have to do the task by the lowest cost.
Please answer the lowest cost.
By characteristics of Mr. Dango's family, they move very slowly. So all passageways are escalators. Because of it, the passageways are one-way.
Constraints
* 2 ≤ n ≤ 100
* -10,000 ≤ Ci ≤ 10,000
* Y1 ... Ym can't be duplicated integer by each other.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
n m
X1 Y1 C1
...
Xm Ym Cm
All numbers in each datasets are integers. The integers in each line are separated by a space.
The first line of each datasets contains two integers. n is the number of rooms in the house, m is the number of passageways in the house. Each room is indexed from 0 to n-1.
Each of following m lines gives the details of the passageways in the house. Each line contains three integers. The first integer Xi is an index of the room, the starting point of the passageway. The second integer Yi is an index of the room, the end point of the passageway. The third integer Ci is the cost to cancel construction of the passageway. The passageways, they are escalators, are one-way. The last dataset is followed by a line containing two zeros (separated by a space).
Output
For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.
Example
Input
3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0
Output
1
100
0
-1 | instruction | 0 | 25,524 | 8 | 51,048 |
"Correct Solution:
```
# AOJ 1065 The House of Huge Family
# Python3 2018.7.10 bal4u
# UNION-FIND library
class UnionSet:
def __init__(self, nmax):
self.size = [1]*nmax
self.id = [i for i in range(nmax+1)]
def root(self, i):
while i != self.id[i]:
self.id[i] = self.id[self.id[i]]
i = self.id[i]
return i
def connected(self, p, q): return self.root(p) == self.root(q)
def unite(self, p, q):
i, j = self.root(p), self.root(q)
if i == j: return
if self.size[i] < self.size[j]:
self.id[i] = j
self.size[j] += self.size[i]
else:
self.id[j] = i
self.size[i] += self.size[j]
# UNION-FIND library
while True:
n, m = map(int, input().split())
if n == 0: break
u = UnionSet(n)
ans, tbl = 0, []
for i in range(m):
x, y, c = map(int, input().split())
if c < 0: ans += c
else: tbl.append((c, x, y))
tbl.sort(reverse=True)
for c, x, y in tbl:
if not u.connected(x, y):
if n > 2:
n -= 1
u.unite(x, y)
else: ans += c
print(ans)
``` | output | 1 | 25,524 | 8 | 51,049 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future.
Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as that of town.
They all had warm and gracious personality and were close each other. However, in this year the two members of them became to hate each other. Since the two members had enormous influence in the family, they were split into two groups.
They hope that the two groups don't meet each other in the new house. Though they are in the same building, they can avoid to meet each other by adjusting passageways.
Now, you have a figure of room layout. Your task is written below.
You have to decide the two groups each room should belong to. Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group. All of the rooms need to belong to exactly one group. And any group has at least one room.
To do the task, you can cancel building passageway. Because the house is under construction, to cancel causes some cost. You'll be given the number of rooms and information of passageway. You have to do the task by the lowest cost.
Please answer the lowest cost.
By characteristics of Mr. Dango's family, they move very slowly. So all passageways are escalators. Because of it, the passageways are one-way.
Constraints
* 2 ≤ n ≤ 100
* -10,000 ≤ Ci ≤ 10,000
* Y1 ... Ym can't be duplicated integer by each other.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
n m
X1 Y1 C1
...
Xm Ym Cm
All numbers in each datasets are integers. The integers in each line are separated by a space.
The first line of each datasets contains two integers. n is the number of rooms in the house, m is the number of passageways in the house. Each room is indexed from 0 to n-1.
Each of following m lines gives the details of the passageways in the house. Each line contains three integers. The first integer Xi is an index of the room, the starting point of the passageway. The second integer Yi is an index of the room, the end point of the passageway. The third integer Ci is the cost to cancel construction of the passageway. The passageways, they are escalators, are one-way. The last dataset is followed by a line containing two zeros (separated by a space).
Output
For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.
Example
Input
3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0
Output
1
100
0
-1
Submitted Solution:
```
while True:
n,m=map(int,input().split())
if (n|m)==0: break
d={}
for i in range(m):
u,v,w=map(int,input().split())
if u>v: u,v=v,u
d[(u,v)]=d.get((u,v),0)+w
print(min(d.values()) if len(d) else 0)
``` | instruction | 0 | 25,525 | 8 | 51,050 |
No | output | 1 | 25,525 | 8 | 51,051 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future.
Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as that of town.
They all had warm and gracious personality and were close each other. However, in this year the two members of them became to hate each other. Since the two members had enormous influence in the family, they were split into two groups.
They hope that the two groups don't meet each other in the new house. Though they are in the same building, they can avoid to meet each other by adjusting passageways.
Now, you have a figure of room layout. Your task is written below.
You have to decide the two groups each room should belong to. Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group. All of the rooms need to belong to exactly one group. And any group has at least one room.
To do the task, you can cancel building passageway. Because the house is under construction, to cancel causes some cost. You'll be given the number of rooms and information of passageway. You have to do the task by the lowest cost.
Please answer the lowest cost.
By characteristics of Mr. Dango's family, they move very slowly. So all passageways are escalators. Because of it, the passageways are one-way.
Constraints
* 2 ≤ n ≤ 100
* -10,000 ≤ Ci ≤ 10,000
* Y1 ... Ym can't be duplicated integer by each other.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
n m
X1 Y1 C1
...
Xm Ym Cm
All numbers in each datasets are integers. The integers in each line are separated by a space.
The first line of each datasets contains two integers. n is the number of rooms in the house, m is the number of passageways in the house. Each room is indexed from 0 to n-1.
Each of following m lines gives the details of the passageways in the house. Each line contains three integers. The first integer Xi is an index of the room, the starting point of the passageway. The second integer Yi is an index of the room, the end point of the passageway. The third integer Ci is the cost to cancel construction of the passageway. The passageways, they are escalators, are one-way. The last dataset is followed by a line containing two zeros (separated by a space).
Output
For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.
Example
Input
3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0
Output
1
100
0
-1
Submitted Solution:
```
while True:
n,m=map(int,input().split())
if (n|m)==0: break
d={}
for i in range(m):
u,v,w=map(int,input().split())
if u>v: u,v=v,u
#d[(u,v)]=d.get((u,v),0)+w
#print(min(d.values()))
``` | instruction | 0 | 25,526 | 8 | 51,052 |
No | output | 1 | 25,526 | 8 | 51,053 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future.
Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as that of town.
They all had warm and gracious personality and were close each other. However, in this year the two members of them became to hate each other. Since the two members had enormous influence in the family, they were split into two groups.
They hope that the two groups don't meet each other in the new house. Though they are in the same building, they can avoid to meet each other by adjusting passageways.
Now, you have a figure of room layout. Your task is written below.
You have to decide the two groups each room should belong to. Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group. All of the rooms need to belong to exactly one group. And any group has at least one room.
To do the task, you can cancel building passageway. Because the house is under construction, to cancel causes some cost. You'll be given the number of rooms and information of passageway. You have to do the task by the lowest cost.
Please answer the lowest cost.
By characteristics of Mr. Dango's family, they move very slowly. So all passageways are escalators. Because of it, the passageways are one-way.
Constraints
* 2 ≤ n ≤ 100
* -10,000 ≤ Ci ≤ 10,000
* Y1 ... Ym can't be duplicated integer by each other.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
n m
X1 Y1 C1
...
Xm Ym Cm
All numbers in each datasets are integers. The integers in each line are separated by a space.
The first line of each datasets contains two integers. n is the number of rooms in the house, m is the number of passageways in the house. Each room is indexed from 0 to n-1.
Each of following m lines gives the details of the passageways in the house. Each line contains three integers. The first integer Xi is an index of the room, the starting point of the passageway. The second integer Yi is an index of the room, the end point of the passageway. The third integer Ci is the cost to cancel construction of the passageway. The passageways, they are escalators, are one-way. The last dataset is followed by a line containing two zeros (separated by a space).
Output
For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.
Example
Input
3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0
Output
1
100
0
-1
Submitted Solution:
```
while True:
n,m=map(int,input().split())
if (n|m)==0: break
d={}
for i in range(m):
u,v,w=map(int,input().split())
if u>v: u,v=v,u
d[(u,v)]=d.get((u,v),0)+w
print(min(d.values()))
``` | instruction | 0 | 25,527 | 8 | 51,054 |
No | output | 1 | 25,527 | 8 | 51,055 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future.
Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as that of town.
They all had warm and gracious personality and were close each other. However, in this year the two members of them became to hate each other. Since the two members had enormous influence in the family, they were split into two groups.
They hope that the two groups don't meet each other in the new house. Though they are in the same building, they can avoid to meet each other by adjusting passageways.
Now, you have a figure of room layout. Your task is written below.
You have to decide the two groups each room should belong to. Besides you must make it impossible that they move from any rooms belonging to one group to any rooms belonging to the other group. All of the rooms need to belong to exactly one group. And any group has at least one room.
To do the task, you can cancel building passageway. Because the house is under construction, to cancel causes some cost. You'll be given the number of rooms and information of passageway. You have to do the task by the lowest cost.
Please answer the lowest cost.
By characteristics of Mr. Dango's family, they move very slowly. So all passageways are escalators. Because of it, the passageways are one-way.
Constraints
* 2 ≤ n ≤ 100
* -10,000 ≤ Ci ≤ 10,000
* Y1 ... Ym can't be duplicated integer by each other.
Input
The input consists of multiple datasets. Each dataset is given in the following format.
n m
X1 Y1 C1
...
Xm Ym Cm
All numbers in each datasets are integers. The integers in each line are separated by a space.
The first line of each datasets contains two integers. n is the number of rooms in the house, m is the number of passageways in the house. Each room is indexed from 0 to n-1.
Each of following m lines gives the details of the passageways in the house. Each line contains three integers. The first integer Xi is an index of the room, the starting point of the passageway. The second integer Yi is an index of the room, the end point of the passageway. The third integer Ci is the cost to cancel construction of the passageway. The passageways, they are escalators, are one-way. The last dataset is followed by a line containing two zeros (separated by a space).
Output
For each dataset, print the lowest cost in a line. You may assume that the all of integers of both the answers and the input can be represented by 32 bits signed integers.
Example
Input
3 2
0 1 2
1 2 1
2 1
0 1 100
2 1
0 1 0
2 1
0 1 -1
0 0
Output
1
100
0
-1
Submitted Solution:
```
INF=1e20
while True:
n,m=map(int,input().split())
if (n|m)==0: break
res=INF
for i in range(m):
u,v,w=map(int,input().split())
res=min(res,w)
print(res)
``` | instruction | 0 | 25,528 | 8 | 51,056 |
No | output | 1 | 25,528 | 8 | 51,057 |
Provide a correct Python 3 solution for this coding contest problem.
Examples
Input
4 5 2
0 1 2 1
0 2 1 2
1 2 1 1
1 3 1 3
2 3 2 1
Output
6
Input
Output | instruction | 0 | 25,563 | 8 | 51,126 |
"Correct Solution:
```
from heapq import *
# G : [to/from, cap, cost, rev]
def minimumCostFlow(N: int, G: list, s: int, t: int, flow: int):
ret = 0
INF = 1 << 60
potential = [0] * N
pre_vtx = [None] * N
pre_edge = [None] * N
while flow > 0:
dist = [INF] * N
dist[s] = 0
visited = [False] * N
q = [(0, s)]
while q:
d, cur = heappop(q)
if visited[cur]:
continue
visited[cur] = True
for i in range(len(G[cur])):
e = G[cur][i]
nxt = e[0]
if e[1] > 0 and dist[nxt] > dist[cur] + e[2] + potential[cur] - potential[nxt]:
dist[nxt] = dist[cur] + e[2] + potential[cur] - potential[nxt]
pre_vtx[nxt] = cur
pre_edge[nxt] = i
heappush(q, (dist[nxt], nxt))
if dist[t] == INF:
return -1
for i in range(N):
potential[i] += dist[i]
df = flow
now = t
while now != s:
df = min(df, G[pre_vtx[now]][pre_edge[now]][1])
now = pre_vtx[now]
flow -= df
ret += df * potential[t]
now = t
while now != s:
G[pre_vtx[now]][pre_edge[now]][1] -= df
G[now][G[pre_vtx[now]][pre_edge[now]][3]][1] += df
now = pre_vtx[now]
return ret
import sys
input = sys.stdin.buffer.readline
def main():
N, M, F = map(int, input().split())
G = [[] for _ in range(N)] # [to/from, cap, cost, rev]
for _ in range(M):
u, v, c, d = map(int, input().split())
G[u].append([v, c, d, len(G[v])])
G[v].append([u, 0, -d, len(G[u]) - 1])
print(minimumCostFlow(N, G, 0, N - 1, F))
if __name__ == '__main__':
main()
``` | output | 1 | 25,563 | 8 | 51,127 |
Provide a correct Python 3 solution for this coding contest problem.
Examples
Input
4 5 2
0 1 2 1
0 2 1 2
1 2 1 1
1 3 1 3
2 3 2 1
Output
6
Input
Output | instruction | 0 | 25,566 | 8 | 51,132 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
from heapq import heappush, heappop
def min_cost_flow_dijkstra(E, s, t, f):
INF = 1 << 100
NN = N
LN = NN.bit_length()
G = [[] for _ in range(NN)]
for a, b, cap, c in E:
G[a].append([b, cap, c, len(G[b])])
G[b].append([a, 0, -c, len(G[a])-1])
prevv = [-1] * NN
preve = [-1] * NN
res = 0
while f > 0:
h = [0] * NN
dist = [INF] * NN
dist[s] = 0
Q = []
heappush(Q, s)
while len(Q):
x = heappop(Q)
d, v = (x>>LN), x % (1<<LN)
if dist[v] < d: continue
for i, (w, _cap, c, r) in enumerate(G[v]):
if _cap > 0 and dist[w] > dist[v] + c + h[v] - h[w]:
dist[w] = dist[v] + c + h[v] - h[w]
prevv[w] = v
preve[w] = i
heappush(Q, (dist[w] << LN) + w)
if dist[t] == INF:
return -1
for v in range(N):
h[v] += dist[v]
d = f
v = t
while v != s:
d = min(d, G[prevv[v]][preve[v]][1])
v = prevv[v]
f -= d
res += d * dist[t]
v = t
while v != s:
G[prevv[v]][preve[v]][1] -= d
G[v][G[prevv[v]][preve[v]][3]][1] += d
v = prevv[v]
return res
N, M, F = map(int, input().split())
E = []
for i in range(M):
u, v, c, d = map(int, input().split())
E.append((u, v, c, d))
print(min_cost_flow_dijkstra(E, 0, N-1, F))
``` | output | 1 | 25,566 | 8 | 51,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.
She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:
* Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
* After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
* After doing so, the box k becomes unavailable for any further actions.
Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.
Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?
As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.
Input
The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.
The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.
Output
Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.
Examples
Input
3
2 6 8
Output
2
Input
5
2 3 4 9 12
Output
4
Input
4
5 7 2 9
Output
1
Note
Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.
In the first example, there are 2 distinct piles possible:
* b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
* b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])
In the second example, there are 4 distinct piles possible:
* b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
* b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
* b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
* b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])
In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty. | instruction | 0 | 25,717 | 8 | 51,434 |
Tags: bitmasks, combinatorics, dp
Correct Solution:
```
MOD = 1000000007
def isSubset(a, b):
return (a & b) == a
def isIntersect(a, b):
return (a & b) != 0
# Solve for each weakly connected component (WCC)
def cntOrder(s, t):
p = len(s)
m = len(t)
inMask = [0 for i in range(m)]
for x in range(p):
for i in range(m):
if t[i] % s[x] == 0:
inMask[i] |= 1 << x
cnt = [0 for mask in range(1<<p)]
for mask in range(1<<p):
for i in range(m):
if isSubset(inMask[i], mask):
cnt[mask] += 1
dp = [[0 for mask in range(1<<p)] for k in range(m+1)]
for i in range(m):
dp[1][inMask[i]] += 1
for k in range(m):
for mask in range(1<<p):
for i in range(m):
if not isSubset(inMask[i], mask) and isIntersect(inMask[i], mask):
dp[k+1][mask | inMask[i]] = (dp[k+1][mask | inMask[i]] + dp[k][mask]) % MOD
dp[k+1][mask] = (dp[k+1][mask] + dp[k][mask] * (cnt[mask] - k)) % MOD
return dp[m][(1<<p)-1]
def dfs(u):
global a, graph, degIn, visited, s, t
visited[u] = True
if degIn[u] == 0:
s.append(a[u])
else:
t.append(a[u])
for v in graph[u]:
if not visited[v]:
dfs(v)
def main():
global a, graph, degIn, visited, s, t
# Reading input
n = int(input())
a = list(map(int, input().split()))
# Pre-calculate C(n, k)
c = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
c[i][0] = 1
for j in range(1, i+1):
c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD
# Building divisibility graph
degIn = [0 for u in range(n)]
graph = [[] for u in range(n)]
for u in range(n):
for v in range(n):
if u != v and a[v] % a[u] == 0:
graph[u].append(v)
graph[v].append(u)
degIn[v] += 1
# Solve for each WCC of divisibility graph and combine result
ans = 1
curLen = 0
visited = [False for u in range(n)]
for u in range(n):
if not visited[u]:
s = []
t = []
dfs(u)
if len(t) > 0:
sz = len(t) - 1
cnt = cntOrder(s, t)
# Number of orders for current WCC
ans = (ans * cnt) % MOD
# Number of ways to insert <sz> number to array of <curLen> elements
ans = (ans * c[curLen + sz][sz]) % MOD
curLen += sz
print(ans)
if __name__ == "__main__":
main()
``` | output | 1 | 25,717 | 8 | 51,435 |
Provide tags and a correct Python 3 solution for this coding contest problem.
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.
She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:
* Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
* After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
* After doing so, the box k becomes unavailable for any further actions.
Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.
Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?
As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.
Input
The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.
The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.
Output
Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.
Examples
Input
3
2 6 8
Output
2
Input
5
2 3 4 9 12
Output
4
Input
4
5 7 2 9
Output
1
Note
Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.
In the first example, there are 2 distinct piles possible:
* b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
* b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])
In the second example, there are 4 distinct piles possible:
* b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
* b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
* b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
* b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])
In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty. | instruction | 0 | 25,718 | 8 | 51,436 |
Tags: bitmasks, combinatorics, dp
Correct Solution:
```
MOD = 1000000007
def isSubset(a, b):
return (a & b) == a
def isIntersect(a, b):
return (a & b) != 0
def cntOrder(s, t):
p = len(s)
m = len(t)
inMask = [0 for i in range(m)]
for x in range(p):
for i in range(m):
if t[i] % s[x] == 0:
inMask[i] |= 1 << x
cnt = [0 for mask in range(1 << p)]
for mask in range(1 << p):
for i in range(m):
if isSubset(inMask[i], mask):
cnt[mask] += 1
dp = [[0 for mask in range(1 << p)] for k in range(m + 1)]
for i in range(m):
dp[1][inMask[i]] += 1
for k in range(m):
for mask in range(1 << p):
for i in range(m):
if not isSubset(inMask[i], mask) and isIntersect(inMask[i], mask):
dp[k + 1][mask | inMask[i]] = (dp[k + 1][mask | inMask[i]] + dp[k][mask]) % MOD
dp[k + 1][mask] = (dp[k + 1][mask] + dp[k][mask] * (cnt[mask] - k)) % MOD
return dp[m][(1 << p) - 1]
def dfs(u):
global a, graph, degIn, visited, s, t
visited[u] = True
if degIn[u] == 0:
s.append(a[u])
else:
t.append(a[u])
for v in graph[u]:
if not visited[v]:
dfs(v)
def main():
global a, graph, degIn, visited, s, t
n = int(input())
a = list(map(int, input().split()))
c = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
c[i][0] = 1
for j in range(1, i + 1):
c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD
degIn = [0 for u in range(n)]
graph = [[] for u in range(n)]
for u in range(n):
for v in range(n):
if u != v and a[v] % a[u] == 0:
graph[u].append(v)
graph[v].append(u)
degIn[v] += 1
ans = 1
curLen = 0
visited = [False for u in range(n)]
for u in range(n):
if not visited[u]:
s = []
t = []
dfs(u)
if len(t) > 0:
sz = len(t) - 1
cnt = cntOrder(s, t)
ans = (ans * cnt) % MOD
ans = (ans * c[curLen + sz][sz]) % MOD
curLen += sz
print(ans)
if __name__ == "__main__":
main()
``` | output | 1 | 25,718 | 8 | 51,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.
She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:
* Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
* After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
* After doing so, the box k becomes unavailable for any further actions.
Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.
Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?
As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.
Input
The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.
The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.
Output
Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.
Examples
Input
3
2 6 8
Output
2
Input
5
2 3 4 9 12
Output
4
Input
4
5 7 2 9
Output
1
Note
Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.
In the first example, there are 2 distinct piles possible:
* b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
* b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])
In the second example, there are 4 distinct piles possible:
* b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
* b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
* b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
* b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])
In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty.
Submitted Solution:
```
num = int(input())
num = num+1
while True:
if len(set(list(str(num)))) == 4:
break
num = num+1
print(num)
``` | instruction | 0 | 25,719 | 8 | 51,438 |
No | output | 1 | 25,719 | 8 | 51,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.
She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:
* Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
* After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
* After doing so, the box k becomes unavailable for any further actions.
Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.
Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?
As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.
Input
The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.
The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.
Output
Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.
Examples
Input
3
2 6 8
Output
2
Input
5
2 3 4 9 12
Output
4
Input
4
5 7 2 9
Output
1
Note
Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.
In the first example, there are 2 distinct piles possible:
* b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
* b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])
In the second example, there are 4 distinct piles possible:
* b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
* b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
* b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
* b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])
In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty.
Submitted Solution:
```
def find():
n = int(input())
l = input().split(" ")
l = list(map(lambda e: int(e), l))
i = 0
out = 0
while (i<n):
for j in range(n):
if (i==j):
continue
elif (l[j]%l[i]==0):
for k in range(j+1, n):
if (i==k):
continue
if (l[k]%l[i]==0):
out+=2
i+=1
if (out==0):
print(1)
else:
print(out)
find()
``` | instruction | 0 | 25,720 | 8 | 51,440 |
No | output | 1 | 25,720 | 8 | 51,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.
She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:
* Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
* After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
* After doing so, the box k becomes unavailable for any further actions.
Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.
Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?
As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.
Input
The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.
The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.
Output
Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.
Examples
Input
3
2 6 8
Output
2
Input
5
2 3 4 9 12
Output
4
Input
4
5 7 2 9
Output
1
Note
Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.
In the first example, there are 2 distinct piles possible:
* b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
* b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])
In the second example, there are 4 distinct piles possible:
* b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
* b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
* b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
* b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])
In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty.
Submitted Solution:
```
q=int(input())
w=list(map(int,input().split()))
e=[-1]*q
for i in range(q):
for j in range(q):
if w[j]%w[i]==0:e[i]+=1
s=0
for i in range(q):
s+=e[i]*(e[i]-1)
print(s)
``` | instruction | 0 | 25,721 | 8 | 51,442 |
No | output | 1 | 25,721 | 8 | 51,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
[SIHanatsuka - EMber](https://soundcloud.com/hanatsuka/sihanatsuka-ember)
[SIHanatsuka - ATONEMENT](https://soundcloud.com/hanatsuka/sihanatsuka-atonement)
Back in time, the seven-year-old Nora used to play lots of games with her creation ROBO_Head-02, both to have fun and enhance his abilities.
One day, Nora's adoptive father, Phoenix Wyle, brought Nora n boxes of toys. Before unpacking, Nora decided to make a fun game for ROBO.
She labelled all n boxes with n distinct integers a_1, a_2, …, a_n and asked ROBO to do the following action several (possibly zero) times:
* Pick three distinct indices i, j and k, such that a_i ∣ a_j and a_i ∣ a_k. In other words, a_i divides both a_j and a_k, that is a_j mod a_i = 0, a_k mod a_i = 0.
* After choosing, Nora will give the k-th box to ROBO, and he will place it on top of the box pile at his side. Initially, the pile is empty.
* After doing so, the box k becomes unavailable for any further actions.
Being amused after nine different tries of the game, Nora asked ROBO to calculate the number of possible different piles having the largest amount of boxes in them. Two piles are considered different if there exists a position where those two piles have different boxes.
Since ROBO was still in his infant stages, and Nora was still too young to concentrate for a long time, both fell asleep before finding the final answer. Can you help them?
As the number of such piles can be very large, you should print the answer modulo 10^9 + 7.
Input
The first line contains an integer n (3 ≤ n ≤ 60), denoting the number of boxes.
The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 60), where a_i is the label of the i-th box.
Output
Print the number of distinct piles having the maximum number of boxes that ROBO_Head can have, modulo 10^9 + 7.
Examples
Input
3
2 6 8
Output
2
Input
5
2 3 4 9 12
Output
4
Input
4
5 7 2 9
Output
1
Note
Let's illustrate the box pile as a sequence b, with the pile's bottommost box being at the leftmost position.
In the first example, there are 2 distinct piles possible:
* b = [6] ([2, 6, 8] \xrightarrow{(1, 3, 2)} [2, 8])
* b = [8] ([2, 6, 8] \xrightarrow{(1, 2, 3)} [2, 6])
In the second example, there are 4 distinct piles possible:
* b = [9, 12] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 3, 4)} [2, 3, 4])
* b = [4, 12] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 3, 4)} [2, 3, 9])
* b = [4, 9] ([2, 3, 4, 9, 12] \xrightarrow{(1, 5, 3)} [2, 3, 9, 12] \xrightarrow{(2, 4, 3)} [2, 3, 12])
* b = [9, 4] ([2, 3, 4, 9, 12] \xrightarrow{(2, 5, 4)} [2, 3, 4, 12] \xrightarrow{(1, 4, 3)} [2, 3, 12])
In the third sequence, ROBO can do nothing at all. Therefore, there is only 1 valid pile, and that pile is empty.
Submitted Solution:
```
q=int(input())
w=list(map(int,input().split()))
e=[-1]*q
for i in range(q):
for j in range(q):
if w[j]%w[i]==0:e[i]+=1
s=1
for i in range(q):
while e[i]>1:
s=s*e[i]%(10**9+7)
e[i]-=1
print(s)
``` | instruction | 0 | 25,722 | 8 | 51,444 |
No | output | 1 | 25,722 | 8 | 51,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
* Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
* Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
* Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | instruction | 0 | 25,888 | 8 | 51,776 |
Tags: dfs and similar, greedy
Correct Solution:
```
read = lambda: [int(i) - 1 for i in input().split()]
n = int(input())
house = read()
prec = [set(read()[1:]) for i in range(n)]
def sub(): # do the job if the precedence is cleared
for i in job_list:
if house[i] == k and not tmp_prec[i]:
return i
ans = float("inf")
for k in [0, 1, 2]:
job_list = [i for i in range(n)]
tmp = -1
tmp_prec = [sub_prec.copy() for sub_prec in prec]
while job_list: # while job not done
i = sub()
while i != None: #exit if we are done
tmp += 1
job_list.remove(i) # 'list' object has no attribute 'discard', only for set
for q in tmp_prec:
q.discard(i) # remove the job from all prec
i = sub()
k += 1
k %= 3
tmp += 1 # move
ans = min(tmp, ans)
print(ans)
``` | output | 1 | 25,888 | 8 | 51,777 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
* Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
* Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
* Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | instruction | 0 | 25,889 | 8 | 51,778 |
Tags: dfs and similar, greedy
Correct Solution:
```
n = int(input())
c = list(map(int, input().split()))
d = dict()
d[1] = []
d[2] = []
d[3] = []
for i in range(n):
d[c[i]].append(i)
done = set()
mas = []
k = 0
poss = set()
for i in range(n):
l = list(map(int, input().split()))
l = l[1:]
mas.append(l)
if len(l) == 0:
k = c[i]
poss.add((k, i))
o = 0
bigans = 1000000000
for a in poss:
k = a[0]
done = set()
done.add(a[1] + 1)
ans = 1
while len(done) != n:
#o += 1
if o == 10:
break
while True:
y = len(done)
for i in d[k]:
if (i + 1) in done:
continue
flag = True
for j in mas[i]:
if j not in done:
flag = False
if flag:
done.add(i + 1)
ans += 1
if y == len(done):
break
if len(done) == n:
break
k += 1
ans += 1
if k == 4:
k = 1
bigans = min(bigans, ans)
print(bigans)
``` | output | 1 | 25,889 | 8 | 51,779 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
* Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
* Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
* Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | instruction | 0 | 25,890 | 8 | 51,780 |
Tags: dfs and similar, greedy
Correct Solution:
```
from collections import *
read_line = lambda: [int(i) for i in input().split(' ')]
n = read_line()[0]
cs = [c - 1 for c in read_line()]
g = [[] for v in range(n)]
parent_cnt = [0] * n
for v in range(n):
parents = read_line()
parent_cnt[v] = len(parents) - 1
for i in range(1, len(parents)):
g[parents[i] - 1].append(v)
def work(x):
pcnt = list(parent_cnt)
qs = [
deque(v for v in range(n) if cs[v] == c and pcnt[v] == 0)
for c in range(3)
]
ans = 0
while True:
while qs[x]:
v = qs[x].popleft()
ans += 1
for w in g[v]:
pcnt[w] -= 1
if pcnt[w] == 0:
qs[cs[w]].append(w)
if qs[0] or qs[1] or qs[2]:
ans += 1
x = (x + 1) % 3
else:
break
return ans
print(min(work(i) for i in range(3)))
# Made By Mostafa_Khaled
``` | output | 1 | 25,890 | 8 | 51,781 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
* Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
* Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
* Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | instruction | 0 | 25,891 | 8 | 51,782 |
Tags: dfs and similar, greedy
Correct Solution:
```
n = int(input())
h = [int(q) - 1 for q in input().split()]
u = [set([int(q) - 1 for q in input().split()][1:]) for i in range(n)]
t = 1e9
def g():
for i in p:
if h[i] == k and not v[i]:
return i
for k in range(3):
p = list(range(n))
d = -1
v = [q.copy() for q in u]
while p:
i = g()
while i != None:
d += 1
p.remove(i)
for q in v :
q.discard(i)
i = g()
k = (k + 1) % 3
d += 1
t = min(d, t)
print(t)
``` | output | 1 | 25,891 | 8 | 51,783 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
* Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
* Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
* Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | instruction | 0 | 25,892 | 8 | 51,784 |
Tags: dfs and similar, greedy
Correct Solution:
```
f = lambda: [int(q) - 1 for q in input().split()]
def g():
for i in p:
if h[i] == k and not v[i]: return i
r = range(int(input()))
t, h = 1e9, f()
u = [set(f()[1:]) for i in r]
for k in (0, 1, 2):
p = list(r)
d = -1
v = [q.copy() for q in u]
while p:
i = g()
while i != None:
d += 1
p.remove(i)
for q in v: q.discard(i)
i = g()
k = (k + 1) % 3
d += 1
t = min(d, t)
print(t)
``` | output | 1 | 25,892 | 8 | 51,785 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that the game can be fully completed, that is, its parts do not form cyclic dependencies.
Rubik has 3 computers, on which he can play this game. All computers are located in different houses. Besides, it has turned out that each part of the game can be completed only on one of these computers. Let's number the computers with integers from 1 to 3. Rubik can perform the following actions:
* Complete some part of the game on some computer. Rubik spends exactly 1 hour on completing any part on any computer.
* Move from the 1-st computer to the 2-nd one. Rubik spends exactly 1 hour on that.
* Move from the 1-st computer to the 3-rd one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 1-st one. Rubik spends exactly 2 hours on that.
* Move from the 2-nd computer to the 3-rd one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 1-st one. Rubik spends exactly 1 hour on that.
* Move from the 3-rd computer to the 2-nd one. Rubik spends exactly 2 hours on that.
Help Rubik to find the minimum number of hours he will need to complete all parts of the game. Initially Rubik can be located at the computer he considers necessary.
Input
The first line contains integer n (1 ≤ n ≤ 200) — the number of game parts. The next line contains n integers, the i-th integer — ci (1 ≤ ci ≤ 3) represents the number of the computer, on which you can complete the game part number i.
Next n lines contain descriptions of game parts. The i-th line first contains integer ki (0 ≤ ki ≤ n - 1), then ki distinct integers ai, j (1 ≤ ai, j ≤ n; ai, j ≠ i) — the numbers of parts to complete before part i.
Numbers on all lines are separated by single spaces. You can assume that the parts of the game are numbered from 1 to n in some way. It is guaranteed that there are no cyclic dependencies between the parts of the game.
Output
On a single line print the answer to the problem.
Examples
Input
1
1
0
Output
1
Input
5
2 2 1 1 3
1 5
2 5 1
2 5 4
1 5
0
Output
7
Note
Note to the second sample: before the beginning of the game the best strategy is to stand by the third computer. First we complete part 5. Then we go to the 1-st computer and complete parts 3 and 4. Then we go to the 2-nd computer and complete parts 1 and 2. In total we get 1+1+2+1+2, which equals 7 hours. | instruction | 0 | 25,893 | 8 | 51,786 |
Tags: dfs and similar, greedy
Correct Solution:
```
from collections import *
read_line = lambda: [int(i) for i in input().split(' ')]
n = read_line()[0]
cs = [c - 1 for c in read_line()]
g = [[] for v in range(n)]
parent_cnt = [0] * n
for v in range(n):
parents = read_line()
parent_cnt[v] = len(parents) - 1
for i in range(1, len(parents)):
g[parents[i] - 1].append(v)
def work(x):
pcnt = list(parent_cnt)
qs = [
deque(v for v in range(n) if cs[v] == c and pcnt[v] == 0)
for c in range(3)
]
ans = 0
while True:
while qs[x]:
v = qs[x].popleft()
ans += 1
for w in g[v]:
pcnt[w] -= 1
if pcnt[w] == 0:
qs[cs[w]].append(w)
if qs[0] or qs[1] or qs[2]:
ans += 1
x = (x + 1) % 3
else:
break
return ans
print(min(work(i) for i in range(3)))
``` | output | 1 | 25,893 | 8 | 51,787 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Examples
Input
3
1 2 3
Output
1 3
Input
4
6 5 6 7
Output
2 3 | instruction | 0 | 25,939 | 8 | 51,878 |
Tags: sortings
Correct Solution:
```
n = int(input())
b = list(map(int, input().split()))
num = len(set(b))
maxx = 0
for i in set(b):
maxx = max(b.count(i), maxx)
print(maxx, num)
``` | output | 1 | 25,939 | 8 | 51,879 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Examples
Input
3
1 2 3
Output
1 3
Input
4
6 5 6 7
Output
2 3 | instruction | 0 | 25,940 | 8 | 51,880 |
Tags: sortings
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
pre = -1
ans = 0
highest = -1
for i in a:
if i != pre:
count = 1
ans += 1
pre = i
else:
count += 1
highest = max(highest, count)
print(highest, ans, end=' ')
``` | output | 1 | 25,940 | 8 | 51,881 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Examples
Input
3
1 2 3
Output
1 3
Input
4
6 5 6 7
Output
2 3 | instruction | 0 | 25,941 | 8 | 51,882 |
Tags: sortings
Correct Solution:
```
from sys import stdin
def result():
numero = int(stdin.readline().strip())
lista1 = [int(x) for x in stdin.readline().split()]
lista2 = []
for a in range(numero):
if lista1[a] not in lista2:
lista2.append(lista1[a])
towers = []
for i in range(len(lista2)):
cont = 0
for j in range(numero):
if lista2[i] == lista1[j]:
cont = cont + 1
towers.append(cont)
print(max(towers),len(towers))
result()
``` | output | 1 | 25,941 | 8 | 51,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Examples
Input
3
1 2 3
Output
1 3
Input
4
6 5 6 7
Output
2 3 | instruction | 0 | 25,942 | 8 | 51,884 |
Tags: sortings
Correct Solution:
```
input()
bars = list(map(int, input().split()))
towers = {}
for b in bars:
towers[b] = towers.get(b, 0) + 1
print(max(towers.values()), len(towers))
``` | output | 1 | 25,942 | 8 | 51,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Examples
Input
3
1 2 3
Output
1 3
Input
4
6 5 6 7
Output
2 3 | instruction | 0 | 25,943 | 8 | 51,886 |
Tags: sortings
Correct Solution:
```
n = int(input())
l = list(map(int, input().split()))
se = len(set(l))
h = []
for i in l:
lt = l.count(i)
h.append(lt)
print(max(h), se)
``` | output | 1 | 25,943 | 8 | 51,887 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
Input
The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
Output
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
Examples
Input
3
1 2 3
Output
1 3
Input
4
6 5 6 7
Output
2 3 | instruction | 0 | 25,944 | 8 | 51,888 |
Tags: sortings
Correct Solution:
```
n = int(input())
arr = sorted(list(map(int,input().strip().split(' '))))
hs = {}
for v in arr :
if v not in hs :
hs[v] = 1
else :
hs[v] += 1
# print()
print("%s %s"%(max(hs.values()),len(hs)))
``` | output | 1 | 25,944 | 8 | 51,889 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.