text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Tags: dp
Correct Solution:
```
mod=10**9+7
def main():
t,k=map(int,input().split())
dp=[0]*(10**5+1)
for i in range(k):
dp[i]=1
for i in range(k,10**5+1):
dp[i]=(dp[i-1]+dp[i-k])%mod
for i in range(1,10**5+1):
dp[i]=(dp[i]+dp[i-1])%mod
for _ in range(t):
a,b=map(int,input().split())
print((dp[b]-dp[a-1])%mod)
main()
```
| 100,700 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Tags: dp
Correct Solution:
```
t, k = map(int, input().split())
MOD = int(1e9) + 7
def madd(a, b):
if a + b >= MOD:
return a + b - MOD
return a + b
def msub(a, b):
if a >= b:
return a - b
return a - b + MOD
dp = [0] * 100001
dp[0] = 1
prefix = [0] * 100001
for i in range(1, 100001):
dp[i] = dp[i - 1]
if i >= k:
dp[i] = madd(dp[i], dp[i - k])
prefix[i] = madd(prefix[i - 1], dp[i])
for _ in range(t):
a, b = map(int, input().split())
print(msub(prefix[b], prefix[a - 1]))
```
| 100,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Tags: dp
Correct Solution:
```
t, k = [int(x) for x in input().split(' ')]
d = [1]
c = [1]
l = 1
for i in range(1, 10**5+1):
v = d[i-1] + (d[i-k] if i-k >= 0 else 0)
v %= (10**9+7)
d.append(v)
c.append((v + l) % (10**9+7))
l = (v + l) % (10**9+7)
# print(d[:5], c[:5])
for _ in range(t):
a, b = [int(x) for x in input().split(' ')]
s = c[b] - c[a-1]
print(str(s) if s >= 0 else str(10**9+7+s))
```
| 100,702 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Tags: dp
Correct Solution:
```
import sys
def solve():
MOD = 1000000007
size = 100003
t, groupsize = read()
mem = [0]*size
summ = [0]*size
mem[0] = 1
for i in range(1, len(mem)):
mem[i] = (mem[i - 1] + mem[i - groupsize] if i >= groupsize else mem[i-1]) % MOD
summ[0] = mem[0]
for i in range(1, len(summ)):
summ[i] = (mem[i] + summ[i - 1]) % MOD
res = list()
for i in range(t):
a, b = read()
res.append((summ[b]-summ[a-1]+MOD)%MOD)
return res
def read(mode=2):
inputs = input().strip()
if mode == 0: return inputs # String
if mode == 1: return inputs.split() # List of strings
if mode == 2: return list(map(int, inputs.split())) # List of integers
def write(s="\n"):
if s is None: s = ""
if isinstance(s, list): s = "\n".join(map(str, s))
if isinstance(s, tuple): s = " ".join(map(str, s))
s = str(s)
print(s, end="")
def run():
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
res = solve()
write(res)
run()
```
| 100,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Tags: dp
Correct Solution:
```
#!/usr/bin/python3
from sys import stdin, stdout
t , k = map(int,stdin.readline().split())
a = [0] * 100001
s = [0] * 100001
MOD = 1000000007
for i in range(0,100001):
if i < k:
a[i] = 1
else:
a[i] = (a[i - 1] + a[i - k])%MOD
s[i] = (s[i - 1] + a[i])%MOD
for i in range(0 , t):
l , r = map(int,stdin.readline().split())
stdout.write( str( (s[r]-s[l-1]+MOD )%MOD ) + "\n" )
```
| 100,704 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
t,k=map(int,input().split())
A=[0]
B=[0]
bmax=0
m=1000000007
for _ in range(t):
a,b=map(int,input().split())
A+=[a]
B+=[b]
bmax=max(B)
arr=[0]*(bmax+1)
for i in range(bmax+1):
if i<k:
arr[i]=1
else:
arr[i]=(arr[i-1]%m+arr[i-k]%m)%m
for i in range(bmax+1):
if i!=0:
arr[i]=(arr[i-1]%m+arr[i]%m)%m
for i in range(1,t+1):
print((arr[B[i]]%m-arr[A[i]-1]%m)%m)
```
Yes
| 100,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
#a, b, c, d = [int(x) for x in stdin.readline().split()]
#a, b, c, d = map( int, stdin.readline().split() )
from sys import stdin, stdout
modconst=1000000007
n,k=map(int, stdin.readline().split())
f=[0]*100001
ss=[0]*100001
f[0]=0
for i in range(1,k):
f[i]=1
f[k]=2
for i in range(k+1,100001):
f[i]=(f[i-1]+f[i-k])%modconst
ss[0]=0;
for i in range(1,100001):
ss[i]=(ss[i-1]+f[i])%modconst
for i in range(n):
a,b=map(int, stdin.readline().split())
stdout.write( str( (ss[b]-ss[a-1]+modconst )%modconst ) + "\n" )
```
Yes
| 100,706 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input().strip('\n'))
let = 'abcdefghijklmnopqrstuvwxyz'
N=10**5+1
t,k=f()
dp=[1]*N
dpsm=[0]*N
dpsm[0]=1
for i in range(k,N):
dp[i]=(dp[i-1]+dp[i-k])%MOD
for i in range(1,N):
dpsm[i]=(dpsm[i-1]+dp[i])%MOD
for _ in range(t):
a,b=f()
print((dpsm[b]-dpsm[a-1])%MOD)
```
Yes
| 100,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
# https://codeforces.com/problemset/problem/474/D
MOD = 1000000007
SIZE = 100010
dp = [-1 for i in range(SIZE)]
def flowers(n, k):
if n == 0:
return 1
if dp[n] != -1:
return dp[n]
temp = 0
if n >= k:
temp = (flowers(n-k, k) % MOD)
temp += (flowers(n-1, k) % MOD)
temp %= MOD
dp[n] = temp
return dp[n]
def flowers_runner():
dp[0] = 0
line = input()
sn, sk = line.split(' ')
n = int(sn)
k = int(sk)
for i in range(SIZE-1):
flowers(i+1, k)
for i in range(SIZE-1):
dp[i+1] += dp[i]
dp[i+1] %= MOD
while n != 0:
line = input()
sa, sb = line.split(' ')
a = int(sa)
b = int(sb)
print((MOD + dp[b] - dp[a-1]) % MOD)
n -= 1
flowers_runner()
```
Yes
| 100,708 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
n,k=map(int,input().split())
s=[]
m=0
for i in range(n):
t=list(map(int,input().split()))
s+=t
m=max([m]+t)
r=[[0,0] for i in range(m)]
for i in range(min(k-1,m)):
r[i]=[1,0]
if k<=m:
r[k-1]=[1,1]
for i in range(k,m):
r[i][0]=sum(r[i-1])
r[i][1]=sum(r[i-k])
r=list(map(sum,r))
for i in range(0,len(s),2):
a,b=s[i],s[i+1]
print(sum(r[a-1:b]))
```
No
| 100,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
def cases(i):
if i==0:
return 1
elif i<k:
return 1
else:
if arr[i]!=0:
return arr[i]
else:
arr[i]=cases(i-1)+cases(i-k)
return arr[i]
t,k=map(int,input().split())
A=[]
B=[]
for _ in range(t):
a,b=map(int,input().split())
A+=[a]
B+=[b]
bmax=max(B)
arr=[0]*(bmax+1)
prefixsum=[0]*(bmax+1)
for i in range(bmax+1):
if i!=0:
prefixsum[i]+=prefixsum[i-1]+cases(i)
#print(prefixsum)
for i in range(t):
print(prefixsum[B[i]]-prefixsum[A[i]-1])
```
No
| 100,710 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
t,k=map(int,input().split())
m=10**9+7
power=[1]
for i in range(100001):
power.append((power[-1]*2)%m)
dp=[0 for i in range(100001)]
for i in range(1,100001):
if(i<k):
dp[i]=(dp[i-1]+1)%m
else:
dp[i]=(dp[i-1]+1+power[i-k])%m
while t:
a,b=map(int,input().split())
print(dp[b]-dp[a-1])
t-=1
```
No
| 100,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.
But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.
Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo 1000000007 (109 + 7).
Input
Input contains several test cases.
The first line contains two integers t and k (1 β€ t, k β€ 105), where t represents the number of test cases.
The next t lines contain two integers ai and bi (1 β€ ai β€ bi β€ 105), describing the i-th test.
Output
Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).
Examples
Input
3 2
1 3
2 3
4 4
Output
6
5
5
Note
* For K = 2 and length 1 Marmot can eat (R).
* For K = 2 and length 2 Marmot can eat (RR) and (WW).
* For K = 2 and length 3 Marmot can eat (RRR), (RWW) and (WWR).
* For K = 2 and length 4 Marmot can eat, for example, (WWWW) or (RWWR), but for example he can't eat (WWWR).
Submitted Solution:
```
t, k = map(int, input().split())
a_b_values = []
max_b = 0
mod = 10 ** 9 + 7
for i in range(t):
a, b = map(int, input().split())
a_b_values.append((a, b))
max_b = max(b, max_b)
ways = [None] * (max_b + 1)
sum_ways = [None] * (max_b + 1)
for i in range(k):
ways[i] = 1
if i == 0:
sum_ways[i] = 0
else:
sum_ways[i] = sum_ways[i - 1] + 1
for i in range(k, max_b + 1):
ways[i] = (ways[i - 1] + ways[i - k])
sum_ways[i] = (ways[i] + sum_ways[i - 1])
for a,b in a_b_values:
total = sum_ways[b] - sum_ways[a - 1]
print(total)
```
No
| 100,712 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 β€ ik < jk β€ n.
In one operation you can perform a sequence of actions:
* take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
* divide both numbers by v, i. e. perform the assignments: <image> and <image>.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
Input
The first line contains two space-separated integers n, m (2 β€ n β€ 100, 1 β€ m β€ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 β€ a[i] β€ 109) β the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 β€ ik < jk β€ n, ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output
Output the answer for the problem.
Examples
Input
3 2
8 3 8
1 2
2 3
Output
0
Input
3 2
8 12 8
1 2
2 3
Output
2
Tags: flows, graph matchings, number theory
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def matching(n,m,path):
match1 = [-1]*n
match2 = [-1]*m
for node in range(n):
for nei in path[node]:
if match2[nei] == -1:
match1[node] = nei
match2[nei] = node
break
while 1:
bfs = [node for node in range(n) if match1[node] == -1]
depth = [-1] * n
for node in bfs:
depth[node] = 0
for node in bfs:
for nei in path[node]:
next_node = match2[nei]
if next_node == -1:
break
if depth[next_node] == -1:
depth[next_node] = depth[node] + 1
bfs.append(next_node)
else:
continue
break
else:
break
pointer = [len(c) for c in path]
dfs = [node for node in range(n) if depth[node] == 0]
while dfs:
node = dfs[-1]
while pointer[node]:
pointer[node] -= 1
nei = path[node][pointer[node]]
next_node = match2[nei]
if next_node == -1:
while nei != -1:
node = dfs.pop()
match2[nei], match1[node], nei = node, nei, match1[node]
break
elif depth[node] + 1 == depth[next_node]:
dfs.append(next_node)
break
else:
dfs.pop()
return match1
def fac(x):
ans = []
while not x%2:
x //= 2
ans.append(2)
for i in range(3,int(x**0.5)+1,2):
while not x%i:
x //= i
ans.append(i)
if x != 1:
ans.append(x)
return ans
def main():
n,m = map(int,input().split())
a = list(map(lambda xx:fac(int(xx)),input().split()))
tot = sum(len(a[i]) for i in range(0,n,2))
st,st1 = [0],[0]
for i in range(n):
if not i&1:
st.append(st[-1]+len(a[i]))
else:
st1.append(st1[-1]+len(a[i]))
path = [[] for _ in range(tot)]
for _ in range(m):
u,v = map(lambda xx:int(xx)-1,input().split())
if u&1:
u,v = v,u
for ind,i in enumerate(a[u]):
for ind1,j in enumerate(a[v]):
if i == j:
path[st[u//2]+ind].append(st1[v//2]+ind1)
match = matching(st[-1],st1[-1],path)
print(len(match)-match.count(-1))
# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self,file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))
self.newlines = b.count(b"\n")+(not b)
ptr = self.buffer.tell()
self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd,self.buffer.getvalue())
self.buffer.truncate(0),self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self,file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s:self.buffer.write(s.encode("ascii"))
self.read = lambda:self.buffer.read().decode("ascii")
self.readline = lambda:self.buffer.readline().decode("ascii")
sys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)
input = lambda:sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
main()
```
| 100,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 β€ ik < jk β€ n.
In one operation you can perform a sequence of actions:
* take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
* divide both numbers by v, i. e. perform the assignments: <image> and <image>.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
Input
The first line contains two space-separated integers n, m (2 β€ n β€ 100, 1 β€ m β€ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 β€ a[i] β€ 109) β the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 β€ ik < jk β€ n, ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output
Output the answer for the problem.
Examples
Input
3 2
8 3 8
1 2
2 3
Output
0
Input
3 2
8 12 8
1 2
2 3
Output
2
Tags: flows, graph matchings, number theory
Correct Solution:
```
def g(i):
u[i] = 0
for j in p[i]:
if v[j] < 0 or u[v[j]] and g(v[j]):
v[j] = i
return 1
return 0
f = lambda: map(int, input().split())
n, m = f()
s = k = 0
d = [[]]
for i in f():
j = 2
t = []
while j * j <= i:
while i % j == 0:
t.append((j, k))
k += 1
i //= j
j += 1
if i > 1:
t.append((i, k))
k += 1
d.append(t)
p = [[] for i in range(k)]
for q in range(m):
a, b = f()
if b % 2: a, b = b, a
for x, i in d[a]:
for y, j in d[b]:
if x == y: p[i].append(j)
v = [-1] * k
for i in range(k):
u = [1] * k
s += g(i)
print(s)
```
| 100,714 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 β€ ik < jk β€ n.
In one operation you can perform a sequence of actions:
* take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
* divide both numbers by v, i. e. perform the assignments: <image> and <image>.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
Input
The first line contains two space-separated integers n, m (2 β€ n β€ 100, 1 β€ m β€ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 β€ a[i] β€ 109) β the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 β€ ik < jk β€ n, ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output
Output the answer for the problem.
Examples
Input
3 2
8 3 8
1 2
2 3
Output
0
Input
3 2
8 12 8
1 2
2 3
Output
2
Submitted Solution:
```
def primefactorial(n):
primes = []
d = 2
while d*d <= n:
while (n % d) == 0:
primes.append(d)
n /= d
d += 1
if n > 1:
primes.append(n)
return primes
def arrays():
n, m= [int(i) for i in input().split()]
numlist= [int(i) for i in input().split()]
good= []
for i in range(m):
good.append([int(k)-1 for k in input().split()])
#print(good)
mylist= []
for i in numlist:
mylist.append(primefactorial(i))
#print(mylist)
#comparing using good list
ans= 0
for i in range(len(good)):
a= mylist[good[i][0]]
b= mylist[good[i][1]]
for j in a[:]:
if j in b:
a.remove(j)
b.remove(j)
ans+= 1
print(ans)
return
arrays()
```
No
| 100,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 β€ ik < jk β€ n.
In one operation you can perform a sequence of actions:
* take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
* divide both numbers by v, i. e. perform the assignments: <image> and <image>.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
Input
The first line contains two space-separated integers n, m (2 β€ n β€ 100, 1 β€ m β€ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 β€ a[i] β€ 109) β the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 β€ ik < jk β€ n, ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output
Output the answer for the problem.
Examples
Input
3 2
8 3 8
1 2
2 3
Output
0
Input
3 2
8 12 8
1 2
2 3
Output
2
Submitted Solution:
```
def f(a, b):
i = 2
while i != min(a, b) + 1:
if a % i == 0 and b % i == 0:
return i
i += 1
return 0
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
b = [[int(i) for i in input().split()] for j in range(m)]
p = 1
i = 0
c = 0
count = 0
while c != m:
x = f(a[b[i][0] - 1], a[b[i][1] - 1])
if x:
a[b[i][0] - 1] //= x
a[b[i][1] - 1] //= x
count += 1
elif not x:
c += 1
i += 1
if i == m and c != m:
i = 0
c = 0
print(count)
```
No
| 100,716 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 β€ ik < jk β€ n.
In one operation you can perform a sequence of actions:
* take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
* divide both numbers by v, i. e. perform the assignments: <image> and <image>.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
Input
The first line contains two space-separated integers n, m (2 β€ n β€ 100, 1 β€ m β€ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 β€ a[i] β€ 109) β the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 β€ ik < jk β€ n, ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output
Output the answer for the problem.
Examples
Input
3 2
8 3 8
1 2
2 3
Output
0
Input
3 2
8 12 8
1 2
2 3
Output
2
Submitted Solution:
```
def primefactorial(n):
primes= []
i= 2
while i**2<= n:
while n%i== 0:
primes.append(i)
n/= i
i+= 1
if n> 1:
primes.append(int(n))
return primes
def arrays():
n, m= [int(i) for i in input().split()]
numlist= [int(i) for i in input().split()]
good= []
for i in range(m):
good.append([int(k)-1 for k in input().split()])
#print(good)
mylist= []
for i in numlist:
mylist.append(primefactorial(i))
#print(mylist)
#comparing using good list
ans= 0
for i in range(len(good)):
a= mylist[good[i][0]]
b= mylist[good[i][1]]
for j in a:
if j in b:
a.remove(j)
b.remove(j)
ans+= 1
for k in b:
if k in a:
a.remove(k)
b.remove(k)
ans+= 1
#print(mylist)
print(ans)
return
arrays()
```
No
| 100,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 β€ ik < jk β€ n.
In one operation you can perform a sequence of actions:
* take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
* divide both numbers by v, i. e. perform the assignments: <image> and <image>.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
Input
The first line contains two space-separated integers n, m (2 β€ n β€ 100, 1 β€ m β€ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 β€ a[i] β€ 109) β the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 β€ ik < jk β€ n, ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output
Output the answer for the problem.
Examples
Input
3 2
8 3 8
1 2
2 3
Output
0
Input
3 2
8 12 8
1 2
2 3
Output
2
Submitted Solution:
```
from math import gcd
import sys
def lcm(a, b):
return ((a*b) // gcd(a, b))
def aze(d):
if d==0:return(0)
ans=0
while d%2==0:
d//=2
ans+=1
i=3
while d!=1:
while d%i==0:
ans+=1
d//=i
i+=2
return(ans)
n,m=map(int,input().split())
a=list(map(int,input().split()))
if n==20 and m==10 and a==[512, 64, 536870912, 256, 1, 262144, 8 ,2097152 ,8192, 524288 ,32, 2 ,16 ,16777216, 524288 ,64, 268435456, 256, 67108864, 131072]:
print(65)
sys.exit()
graph=[[0 for i in range(n+2)] for i in range(n+2)]
for _ in range(m):
i,j=map(int,input().split())
g=gcd(a[i-1],a[j-1])
if i%2==0:
graph[i][j]=g
else:
graph[j][i]=g
for i in range(1,n+1):
if i%2==0:
c=1
for j in range(1,n+2,2):
if graph[i][j]!=0:
c=lcm(c,graph[i][j])
graph[0][i]=c
else:
c=1
for j in range(2,n+2,2):
if graph[j][i]!=0:
c=lcm(c,graph[j][i])
graph[i][n+1]=c
for i in range(n+2):
for j in range(n+2):
graph[i][j]=aze(graph[i][j])
def dfs(s,t):
q=[s]
v=[False for i in range(n+2)]
while q:
x=q.pop()
v[x]=True
if x==t:return(True)
for y in range(n+2):
if v[y] or graph[x][y]==0:continue
parent[y]=x
q.append(y)
return False
inf=float("INF")
parent=[-1 for i in range(n+2)]
def flow(s,t):
flow_ans=0
while dfs(s,t):
flow_path=inf
c=t
while c!=s:
u=parent[c]
flow_path=min(flow_path,graph[u][c])
c=u
c=t
while c!=s:
u=parent[c]
graph[u][c]-=flow_path
graph[c][u]+=flow_path
c=u
flow_ans+=flow_path
return(flow_ans)
print(flow(0,n+1))
```
No
| 100,718 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya plays one very well-known and extremely popular MMORPG game. His game character has k skill; currently the i-th of them equals to ai. Also this game has a common rating table in which the participants are ranked according to the product of all the skills of a hero in the descending order.
Vasya decided to 'upgrade' his character via the game store. This store offers n possible ways to improve the hero's skills; Each of these ways belongs to one of three types:
1. assign the i-th skill to b;
2. add b to the i-th skill;
3. multiply the i-th skill by b.
Unfortunately, a) every improvement can only be used once; b) the money on Vasya's card is enough only to purchase not more than m of the n improvements. Help Vasya to reach the highest ranking in the game. To do this tell Vasya which of improvements he has to purchase and in what order he should use them to make his rating become as high as possible. If there are several ways to achieve it, print any of them.
Input
The first line contains three numbers β k, n, m (1 β€ k β€ 105, 0 β€ m β€ n β€ 105) β the number of skills, the number of improvements on sale and the number of them Vasya can afford.
The second line contains k space-separated numbers ai (1 β€ ai β€ 106), the initial values of skills.
Next n lines contain 3 space-separated numbers tj, ij, bj (1 β€ tj β€ 3, 1 β€ ij β€ k, 1 β€ bj β€ 106) β the type of the j-th improvement (1 for assigning, 2 for adding, 3 for multiplying), the skill to which it can be applied and the value of b for this improvement.
Output
The first line should contain a number l (0 β€ l β€ m) β the number of improvements you should use.
The second line should contain l distinct space-separated numbers vi (1 β€ vi β€ n) β the indices of improvements in the order in which they should be applied. The improvements are numbered starting from 1, in the order in which they appear in the input.
Examples
Input
2 4 3
13 20
1 1 14
1 2 30
2 1 6
3 2 2
Output
3
2 3 4
Tags: greedy
Correct Solution:
```
def euclid(a, b):
if b == 0:
return (1, 0, a)
else:
(x, y, g) = euclid(b, a%b)
return (y, x - a//b*y, g)
def modDivide(a, b, p):
(x, y, g) = euclid(b, p)
return a // g * (x + p) % p
def comb(n, k):
return modDivide(fac[n], fac[k] * fac[n-k] % P, P)
k, n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
skill = []
l = [[[], [], []] for i in range(k)]
for j in range(n):
t = list(map(int, input().split()))
skill.append(t)
(t, i, b) = t
l[i-1][t-1].append((b, j+1))
for i in range(k):
for j in range(3):
l[i][j].sort(reverse=True)
op = []
for i in range(k):
t = l[i][1][:]
if len(l[i][0]) != 0 and l[i][0][0][0] > a[i]:
t.append((l[i][0][0][0] - a[i], l[i][0][0][1]))
t.sort(reverse=True)
s = a[i]
for (add, index) in t:
op.append(((s+add)/s, index))
s += add
for (mul, index) in l[i][2]:
op.append((mul, index))
op.sort(reverse=True)
st = set(map(lambda t : t[1], op[:m]))
print(len(st))
for i in range(k):
for j in range(3):
for (mul, index) in l[i][j]:
if index in st:
print(index, end=' ')
```
| 100,719 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
n,m=map(int,input().split(" "))
a=[input() for x in range(n)]
print(sum(sorted(a[x][y:y+2]+a[x+1][y:y+2])==sorted("face") for x in range(n-1) for y in range(m-1)))
```
| 100,720 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
n, m = map(int, input().split())
table = []
for i in range(n):
table.append(input())
ans = 0
for i in range(n - 1):
for j in range(m - 1):
di = [0, 0, 1, 1]
dj = [0, 1, 0, 1]
d = {}
for k in range(4):
c = table[i + di[k]][j + dj[k]]
d[c] = d.get(c, 0) + 1
flg = True
for c in "face":
if c not in d or d[c] != 1:
flg = False
if flg:
ans += 1
print(ans)
```
| 100,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
r, c = map(lambda x: int(x) ,input().split())
img = []
for i in range(r):
img.append([])
line = input()
for j in range(c):
img[i].append(line[j])
count=0
for i in range(r-1):
for j in range(c-1):
test = [img[i][j], img[i+1][j], img[i][j+1], img[i+1][j+1]]
if all([x in test for x in "face"]):
count +=1
print(count)
```
| 100,722 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
x = list(map(int, input().split(' ')))
n, m = x[0], x[1]
a = []
for i in range(n):
a.append(input())
def check(x, y):
mp = set()
for i in range(x-1, x+1):
for j in range(y-1, y+1):
mp.add(a[i][j])
return ('f' in mp) and ('a' in mp) and ('c' in mp) and ('e' in mp)
k = 0
for i in range(1, n):
for j in range(1, m):
if check(i, j):
k += 1
print(k)
```
| 100,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
n,m = map(int,input().split())
a = []
c = 0
for i in range(n):
s = list(input())
a.append(s)
#print(a)
for i in range(m-1):
for j in range(n-1):
s = a[j][i] + a[j+1][i] + a[j][i+1] + a[j+1][i+1]
s = sorted(s)
s = ''.join(s)
#print(s)
if(s == "acef"):
c += 1
print(c)
```
| 100,724 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
n, m =map(int, input().split())
x=[]
for i in range(n):
x.append(input())
c = 0
for i in range(n-1):
for j in range(m-1):
k = [x[i][j], x[i+1][j], x[i][j+1], x[i+1][j+1]]
if ''.join(sorted(k)) == 'acef':
c += 1
print(c)
'''
iterate through all 2 by 2 squares to check face
'''
```
| 100,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
from sys import stdin
n, m = map(int, stdin.readline().split())
a = []
for i in range(0, n):
a.append(stdin.readline())
res = 0
for i in range(0, n - 1):
for j in range(0, m - 1):
r = [a[i][j], a[i][j + 1], a[i + 1][j], a[i + 1][j + 1]]
if "f" not in r:
continue
if "a" not in r:
continue
if "c" not in r:
continue
if "e" not in r:
continue
res += 1
print (res)
```
| 100,726 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Tags: implementation, strings
Correct Solution:
```
n, m = (int(x) for x in input().split())
a = []
for i in range(n):
a.append(input().strip())
ans = 0
for i in range(n-1):
for j in range(m-1):
if sorted([a[i][j], a[i+1][j], a[i][j+1], a[i+1][j+1]]) == sorted(['f', 'a', 'c', 'e']):
ans += 1
print(ans)
```
| 100,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
n, m = [int(x) for x in input().split()]
a = []
for i in range(n):
a.append(input())
#print(a)
res = 0
z = ["face", "faec", "feac", "feca", "fcae", "fcea", "eafc", "eacf", "ecaf", "ecfa", "efac", "efca", "acfe", "acef", "aecf", "aefc", "afce", "afec", "cafe", "caef", "ceaf", "cefa", "cfea", "cfae"]
for i in range(1, n):
for j in range(1, m):
if a[i][j]+a[i][j-1]+a[i-1][j]+a[i-1][j-1] in z:
res += 1
print(res)
```
Yes
| 100,728 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
n, m = map(int, input().split())
ans = 0
A = [input() for i in range(n)]
for i in range(n - 1):
for j in range(m - 1):
if sorted(A[i][j] + A[i][j + 1] + A[i + 1][j] + A[i + 1][j + 1]) == sorted("face"):
ans += 1
print(ans)
```
Yes
| 100,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
n, m = [int(i) for i in input().split()]
lines = []
res = 0
for i in range(n):
lines.append(input().strip())
for x in range(n - 1):
for y in range(m - 1):
line = lines[x][y] + lines[x + 1][y] + lines[x][y + 1] + lines[x + 1][y + 1]
if ('f' in line) and ('a' in line) and ('c' in line) and ('e' in line):
res += 1
print(res)
```
Yes
| 100,730 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
a, b = map(int, input().split())
cases = a
face = set("face")
matrix = []
while cases:
cases -= 1
s = list(input())
matrix.append(s)
check = set()
ans = 0
for row in range(len(matrix)):
for col in range(len(matrix[0])):
if matrix[row][col] in face:
if row < len(matrix)-1 and col < len(matrix[0])-1:
check.add(matrix[row][col])
check.add(matrix[row][col+1])
check.add(matrix[row+1][col])
check.add(matrix[row+1][col+1])
if check == face:
ans += 1
check = set()
print(ans)
```
Yes
| 100,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
a=input().split()
per=input()
answer=0
for j in range(int(a[0])-1):
per1=input()
for i in range(int(a[1])-1):
A=set()
A.add(per[i+1])
A.add(per[i])
A.add(per1[i])
A.add(per1[i+1])
if len(A)==4:
answer +=1
per=per1
print((answer))
```
No
| 100,732 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
n,m = map(int,input().split(' '))
l = []
res = 0
for i in range(n):
col = list(input())
l.append(col)
for i in range(n-1):
for j in range(m-1):
if l[i][j]!='x':
if l[i+1][j]!='x' and l[i][j+1]!='x' and l[i+1][j+1]:
res+=1
print(res)
```
No
| 100,733 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
n, m = input().split(' ')
n = int(n)
m = int(m)
# print(n, m)
f = 0
a = 0
c = 0
e = 0
# print(f, a, c, e)
for i in range(n):
str1 = input()
# print(str1)
for s in str1:
# print(s)
if s == 'f':
f+=1
elif s == 'a':
a+=1
elif s == 'c':
c+=1
elif s == 'e':
e+=1
else:
continue
# print(f, a, c, e)
# print(f, a, c, e)
print(max(f, a, c, e))
```
No
| 100,734 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 Γ 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 β€ n, m β€ 50) β the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
def face_detection():
n, k = map(int, input().split())
arr = []
if n == 1:
print(0)
return
for i in range(n):
arr.append(list(input()))
count = 0
m = [[False] * k] * n
for i in range(n - 1):
for j in range(k - 1):
l = arr[i][j] + arr[i + 1][j] + arr[i][j + 1] + arr[i + 1][j + 1]
l = ''.join(sorted(l))
if l == 'acef' and (
m[i][j] & m[i + 1][j] & m[i][j + 1] & m[i + 1][j + 1] == False):
m[i][j] = True
m[i + 1][j] = True
m[i][j + 1] = True
m[i + 1][j + 1] = True
count += 1
print(count)
if __name__ == '__main__':
face_detection()
```
No
| 100,735 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Note the unusual memory limit for the problem.
People working in MDCS (Microsoft Development Center Serbia) like partying. They usually go to night clubs on Friday and Saturday.
There are N people working in MDCS and there are N clubs in the city. Unfortunately, if there is more than one Microsoft employee in night club, level of coolness goes infinitely high and party is over, so club owners will never let more than one Microsoft employee enter their club in the same week (just to be sure).
You are organizing night life for Microsoft employees and you have statistics about how much every employee likes Friday and Saturday parties for all clubs.
You need to match people with clubs maximizing overall sum of their happiness (they are happy as much as they like the club), while half of people should go clubbing on Friday and the other half on Saturday.
Input
The first line contains integer N β number of employees in MDCS.
Then an N Γ N matrix follows, where element in i-th row and j-th column is an integer number that represents how much i-th person likes j-th clubβs Friday party.
Then another N Γ N matrix follows, where element in i-th row and j-th column is an integer number that represents how much i-th person likes j-th clubβs Saturday party.
* 2 β€ N β€ 20
* N is even
* 0 β€ level of likeness β€ 106
* All values are integers
Output
Output should contain a single integer β maximum sum of happiness possible.
Examples
Input
4
1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
5 8 7 1
6 9 81 3
55 78 1 6
1 1 1 1
Output
167
Note
Here is how we matched people with clubs:
Friday: 1st person with 4th club (4 happiness) and 4th person with 1st club (4 happiness).
Saturday: 2nd person with 3rd club (81 happiness) and 3rd person with 2nd club (78 happiness).
4+4+81+78 = 167
Submitted Solution:
```
n = int(input())
fr = [0] * (n + 1)
sat = [0] * (n + 1)
maxim = -1
for i in range(1, n + 1):
maxim = -1
for j in map(int, input().split()):
if j > maxim:
maxim = j
fr[i] = maxim
for i in range(1, n + 1):
maxim = -1
for j in map(int, input().split()):
if j > maxim:
maxim = j
sat[i] = maxim
i = 0
while i < 2 ** n:
mask = bin(i)[2:]
mask = '0' *(n - len(mask)) + mask
i += 1
ans = 0
kol_one = 0
kol_null = 0
for j in range(n):
if mask[j] == '0':
ans += fr[j + 1]
kol_one += 1
else:
ans += sat[j + 1]
kol_null += 1
if ans > maxim and kol_null == kol_one:
maxim = ans
print(maxim)
```
No
| 100,736 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
k, a, b = map(int, input().split())
if a % k:
a += k - a % k
b -= b % k
print(b // k - a // k + 1)
```
| 100,737 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
k, a, b = map(int, input().split())
if (a >= 0 and b > 0) or (a < 0 and b <= 0):
print(max(abs(a), abs(b)) // k - ((min(abs(a), abs(b))) - 1) // k)
else:
print(abs(a) // k + abs(b) // k + 1)
```
| 100,738 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
(k,a,b)=map(int, input().split())
print(b//k-(a-1)//k)
```
| 100,739 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
from math import floor
def seal(a, b):
return (a + b - 1)//b
k,a,b = map(int,input().split())
ans = abs(b)//k + abs(a)//k
if(a < 0 and b >=0):
values = b - a + 1
print(ans + 1)
else:
a,b = abs(a), abs(b)
a,b = min(a,b), max(a,b)
lower = seal(a,k)
upper = int(b//k)
print(upper - lower + 1)
# if(a % k == 0 and b % k == 0 and k != 1):
# ans += 1
# print(ans)
```
| 100,740 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
k, a, b = [int(i) for i in input().split()]
count = 0
if(a%k!=0):
a = (a + k) - (a%k)
if(b%k!=0):
b = b - (b%k)
if(b<a):
print(0)
else:
print(1 + (b-a)//k)
```
| 100,741 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
k,a,b=map(int,input().split())
m=b//k
if a>0:
x=(a//k)
m-=x
if a%k==0:
m+=1
else:
m+=(abs(a)//k)
m+=1
print(m)
```
| 100,742 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
n,l,h=input().split()
n=int(n)
l=int(l)
h=int(h)
if l>0 and h>0:
print(h//n-(l-1)//n)
else:
print(h//n+abs(l)//n+1)
```
| 100,743 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Tags: math
Correct Solution:
```
import math
def main():
k, a, b = map(int, input().split())
low = (a+k-1)//k
big = b//k
ans = big - low+1
# if a<0 and b>0:
# ans += 1
print(int(ans))
if __name__ == '__main__':
main()
```
| 100,744 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
# your code goes here
k, a, b = map(int, input().split())
#//=floor division
floor_a = a//k
floor_b = b//k
ans = floor_b - floor_a
if a%k==0:
ans += 1
print(ans)
```
Yes
| 100,745 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
k,a,b=map(int,input().split())
if a<=0 and b>=0:
res=abs(a)//k+b//k+1
print(res)
else:
a,b=abs(a),abs(b)
a,b=max(a,b),min(a,b)-1
res=a//k-(b//k)
print(res)
```
Yes
| 100,746 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
k,a,b = list(map(int,input().split()))
if a%k!=0:
n1 = a+k-(a%k)
else:
n1 = a
n2 = b-b%k
n = ((n2-n1)//k)+1
print(n)
```
Yes
| 100,747 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
k, l, r = map(int, input().split())
p = l // k
if(l % k > 0):
p += 1
l = p * k
o = (r - l) // k + 1
if(l > r):
o = 0
print(o)
```
Yes
| 100,748 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
k, a, b = map(int, input().split())
counter = 0
if (a == b):
if (abs(a) % k == 0 or a == 0):
counter = 0
elif ((b > 0 and a >= 0) or (a < 0 and b <= 0)):
n1 = abs(b)//k
n2 = abs(a)//k
counter = max(n1-n2+1, n2-n1+1)
elif(b > 0 and a < 0):
n1 = b//k
n2 = abs(a)//k
counter = n1+n2+1
print(counter)
```
No
| 100,749 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
from math import ceil
def delimost(k, a, b):
if a == b == 0:
return 1
return ceil((b + 1 - a) / k)
K, A, B = [int(j) for j in input().split()]
print(delimost(K, A, B))
```
No
| 100,750 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
import sys
c = 0
k,a,b = map(int,sys.stdin.readline().split())
if(k==1):
print(b-a+1)
elif(k==2):
print(((b-a)/2)+1)
else:
for i in range(a,b+1):
if(i%k==0):
c =c+1
print(c)
```
No
| 100,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a β€ x β€ b and x is divisible by k.
Input
The only line contains three space-separated integers k, a and b (1 β€ k β€ 1018; - 1018 β€ a β€ b β€ 1018).
Output
Print the required number.
Examples
Input
1 1 10
Output
10
Input
2 -4 4
Output
5
Submitted Solution:
```
#!/bin/python3
import math
k, a, b = [int(i) for i in input().split()]
if k > 2:
print(sum([1 for x in range(a,b+1) if x%k==0]))
elif k == 1:
print(b-a+1)
elif k == 2:
print(math.ceil((b-a+1)/2))
```
No
| 100,752 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
def det(a,b,c):
return (b[0]-a[0])*(c[1]-a[1])-(c[0]-a[0])*(b[1]-a[1])
n = int(input())
a = []
for i in range(1,n+1):
x,y=map(int,input().split())
a.append([x,y,i])
a.sort(key=lambda x: (x[0],x[1]))
for i in range(n-2):
x = a[i]
y = a[i+1]
z = a[i+2]
if not(det(x[:2],y[:2],z[:2]) == 0):
break
print(x[2],y[2],z[2])
```
| 100,753 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
stars = []
for i in range(n):
x, y = list(map(int, input().split()))
stars.append((x, y))
x1, y1 = stars[0]
ind1 = 0
x2, y2 = stars[1]
ind2 = 1
x3, y3 = 0, 0
ind3 = 0
for i in range(2, n):
x0, y0 = stars[i]
if (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0) != 0:
x3, y3 = x0, y0
ind3 = i
break
for i in range(2, n):
x0, y0 = stars[i]
if i == ind1 or i == ind2 or i == ind3:
continue
d1 = (x1 - x0) * (y2 - y1) - (x2 - x1) * (y1 - y0)
d2 = (x2 - x0) * (y3 - y2) - (x3 - x2) * (y2 - y0)
d3 = (x3 - x0) * (y1 - y3) - (x1 - x3) * (y3 - y0)
if (d1 >= 0 and d2 >= 0 and d3 >= 0) or (d1 <= 0 and d2 <= 0 and d3 <= 0):
if d1 == 0 or d2 == 0:
ind2 = i
x2, y2 = x0, y0
elif d3 == 0 or (d1 > 0 and d2 > 0 and d3 > 0) or (d1 < 0 and d2 < 0 and d3 < 0):
ind1 = i
x1, y1 = x0, y0
print(ind1 + 1, ind2 + 1, ind3 + 1)
```
| 100,754 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
p = []
for i in range(n):
p += [list(map(int,input().split()))+[i+1]]
p = sorted(p)
l = [[p[0]]]
for i in range(1,n):
if l[-1][0][0] < p[i][0]:
l += [[p[i]]]
else:
l[-1] += [p[i]]
m = len(l)
for i in range(m):
if len(l[i]) > 1:
r = 1 if i == 0 else -1
print(l[i][0][2],l[i][1][2],l[i+r][0][2])
break
else:
u, v = l[0][0], l[1][0]
n = [v[0]-u[0],v[1]-u[1]]
a, b = -n[1], n[0]
c = - a * u[0] - b * u[1]
for i in range(2,m):
z = l[i][0]
if a * z[0] + b * z[1] + c != 0:
print(u[2],v[2],z[2])
break
else:
u = v
v = z
```
| 100,755 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
#!/usr/bin/env python3
from collections import namedtuple
from itertools import islice
Point = namedtuple("Point", "x y")
try:
while True:
n = int(input())
points = [Point(*map(int, input().split())) for i in range(n)]
min_d = 1e20
i1 = i2 = 0
p0 = points[0]
p1 = p2 = None
for i, p in enumerate(islice(points, 1, None), 1):
d = (p.x - p0.x)**2 + (p.y - p0.y)**2
if d < min_d:
min_d = d
p1 = p
i1 = i
assert p1 is not None
dx1 = p1.x - p0.x
dy1 = p1.y - p0.y
min_d = 1e20
for i, p in enumerate(islice(points, 1, None), 1):
if p is p1:
continue
dx2 = p.x - p0.x
dy2 = p.y - p0.y
if dx1 == 0:
ok = dx2 != 0
elif dy1 == 0:
ok = dy2 != 0
else:
ok = dy1 * dx2 != dy2 * dx1
if ok:
d = dx2**2 + dy2**2
if d < min_d:
min_d = d
p2 = p
i2 = i
# assert p2 is not None
while p2 is None:
pass
print(1, i1 + 1, i2 + 1)
except EOFError:
pass
```
| 100,756 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
t = [(list(map(int, input().split())) + [i + 1]) for i in range(int(input()))]
t.sort()
x, y, i = t[0]
u, v, j = t[1]
for a, b, k in t[2:]:
if (u - x) * (b - y) - (v - y) * (a - x): break
print(i, j, k)
# Made By Mostafa_Khaled
```
| 100,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
import math
def on_one_line(x1, y1, x2, y2, x3, y3):
result = x1 * y2 - y1 * x2 + y1 * x3 - x1 * y3 + x2 * y3 - x3 * y2;
if result == 0:
return True
else:
return False
n = int(input().strip())
node = []
for i in range(n):
a, b = input().strip().split()
node.append([int(a), int(b)])
mindis1 = 0
minidx1 = 0
for i in range(1, n):
dis1 = math.sqrt(math.pow((node[i][0]-node[0][0]),2) + math.pow((node[i][1]-node[0][1]),2))
if i == 1:
mindis1 = dis1
minidx1 = i
elif dis1 < mindis1:
mindis1 = dis1
minidx1 = i
mindis2 = 10000000000000
minidx2 = 0
for i in range(1, n):
if on_one_line(node[0][0], node[0][1], node[minidx1][0], node[minidx1][1], node[i][0], node[i][1]) == False:
dis2 = math.sqrt(math.pow((node[i][0]-node[minidx1][0]),2) + math.pow((node[i][1]-node[minidx1][1]),2))
if dis2 < mindis2:
mindis2 = dis2
minidx2 = i
print("1 " + str(minidx1+1) + " " + str(minidx2+1))
```
| 100,758 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
ans = []
arr = [0] * n
for idx in range(n):
x, y = input().split()
arr[idx] = (int(x) + int(y), int(x), idx + 1, int(y))
arr.sort()
ans.append(arr[0][2])
ans.append(arr[1][2])
if arr[0][0] == arr[1][0]:
w = arr[0][0]
idx = 2
while(True):
if arr[idx][0] == w:
idx += 1
else:
ans.append(arr[idx][2])
break
else:
idx = 2
while(True):
if (arr[1][3] - arr[0][3]) * (arr[idx][1] - arr[1][1]) == (arr[idx][3] - arr[1][3]) * (arr[1][1] - arr[0][1]):
idx += 1
else:
ans.append(arr[idx][2])
break
print(' '.join(map(str, ans)))
```
| 100,759 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Tags: geometry, implementation
Correct Solution:
```
import sys
import itertools
def s(p1,p2,p3):
return (p1[0]-p3[0])*(p2[1]-p3[1])-(p2[0]-p3[0])*(p1[1]-p3[1])
e = 1e-22
def inTri(p, p1, p2, p3):
l = [p1,p2,p3]
for i in itertools.permutations(l):
if abs(t(i[0],i[1])-t(i[0],p))<=e and min(i[0][0],i[1][0])<=p[0]<=max(i[0][0],i[1][0]) and min(i[0][1],i[1][1])<=p[1]<=max(i[0][1],i[1][1]):
return True
return (s(p,p1,p2)<=0)==(s(p,p2,p3)<=0) and (s(p,p2,p3)<=0)==(s(p,p3,p1)<=0)
def t(p1, p2):
if p2[0] == p1[0]: return 2e9
return (p2[1]-p1[1])/(p2[0]-p1[0])
n = int(input())
l = []
n1 = 0
n2 = 1
n3 = -1
for i in range(n):
p = tuple(map(int,input().split()))
l.append(p)
for i in range(2,n):
if t(l[n1],l[n2]) == t(l[n1],l[i]) and (l[n1][0]-l[n2][0])**2+(l[n1][1]-l[n2][1])**2 > (l[n1][0]-l[i][0])**2+(l[n1][1]-l[i][1])**2:
n2 = i
for i in range(n):
if i==n1 or i==n2: continue
if abs(t(l[i],l[n1])-t(l[i],l[n2]))<=e:
continue
if n3<0:
n3=i
continue
if inTri(l[i], l[n1],l[n2],l[n3]):
n3 = i
continue
print(n1+1,n2+1,n3+1)
```
| 100,760 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
def cross_pr(a_):
x1, y1, x2, y2 = a_[:]
return x1 * y2 - x2 * y1
def vector(a_):
x1, y1, x2, y2 = a_[:]
return [x1 - x2, y1 - y2]
def dist(a_):
x1, y1 = a_[:]
return (x1 * x1 + y1 * y1) ** 0.5
n = int(input())
x = [[] for i in range(n)]
for i in range(n):
x[i] = [int(i) for i in input().split()]
a = [[0] * 2 for i in range(n - 1)]
for i in range(1, n):
a[i - 1][0] = dist(vector(x[i] + x[0]))
a[i - 1][1] = i
a.sort()
ans = [0] * 3
ans[0] = 0
ans[1] = a[0][1]
now = 2 * 10 ** 21 + 1
v1 = vector(x[ans[0]] + x[ans[1]])
for i in range(n):
v2 = vector(x[i] + x[ans[1]])
if abs(cross_pr(v1 + v2)) > 0:
if abs(cross_pr(v1 + v2)) < now:
now = abs(cross_pr(v1 + v2))
ans[2] = i
for i in range(3):
ans[i] += 1
print(*ans)
```
Yes
| 100,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
t = [(list(map(int, input().split())), i) for i in range(1, int(input()) + 1)]
t.sort()
(x, y), i = t[0]
(u, v), j = t[1]
for (a, b), k in t[2:]:
if (u - x) * (b - y) - (v - y) * (a - x): break
print(i, j, k)
```
Yes
| 100,762 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
n = int(input())
points = []
for i in range(n):
points.append(tuple(int(x) for x in input().split()))
p0 = points[0]
dist = lambda p, q: (p[0]-q[0])**2 + (p[1]-q[1])**2
s_points = sorted(list(enumerate(points)), key = lambda p: dist(p[1], p0))
p1 = s_points[1][1]
def incident(p, q, r):
u = (p[0] - q[0], p[1] - q[1])
v = (p[0] - r[0], p[1] - r[1])
return u[0]*v[1] - u[1]*v[0] == 0
for i in range(2, n):
if not incident(p0, p1, s_points[i][1]):
print(1, s_points[1][0]+1, s_points[i][0]+1)
break
else:
print('wtf, dude?')
```
Yes
| 100,763 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
t = [(list(map(int, input().split())) + [i + 1]) for i in range(int(input()))]
t.sort()
x, y, i = t[0]
u, v, j = t[1]
for a, b, k in t[2:]:
if (u - x) * (b - y) - (v - y) * (a - x): break
print(i, j, k)
```
Yes
| 100,764 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
def check(x1, y1, x2, y2, x, y):
a = (x1 - x) ** 2 + (y - y1) ** 2 + (x2 - x) ** 2 + (y - y2) ** 2
b = (x1 - x2) ** 2 + (y2 - y1) ** 2
b -= a
if b < 0:
return False
b /= 2
b **= 2
a = ((x1 - x) ** 2 + (y - y1) ** 2) * ((x2 - x) ** 2 + (y - y2) ** 2)
if a == b:
return True
else:
return False
def sqr(s):
answer = 0
for i in range(len(s)):
answer += s[i][0] * s[(i + 1) % len(s)][1] - s[i][1] * s[(i + 1) % len(s)][0]
answer /= 2
answer = abs(answer)
return answer
def main():
n = int(input())
s = []
for i in range(n):
a, b = map(int, input().split())
s.append([a, b, i + 1])
s.sort()
i = 0
print(s)
while s[i][0] == s[0][0]:
i += 1
if i > 2:
print(1, 2, i + 1)
else:
while check(s[i][0], s[i][1], s[0][0], s[0][1], s[1][0], s[1][1]):
i += 1
print(s[0][2], s[1][2], s[i][2])
main()
```
No
| 100,765 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
n=int(input())
points=[list(map(int,input().split())) for i in range(n)]
from random import randint
i=0
j=1
p1,p2 = points[i],points[j]
def dis(p1,p2):
return (p1[0]-p2[0])**2 + (p1[1]-p2[1])**2
def Area(p1,p2,p3):
return p1[0]*abs(p2[1]-p3[1])+p2[0]*abs(p3[1]-p1[1])+p3[0]*abs(p1[1]-p2[1])
for k in range(n):
if k==i or k==j:
continue
elif dis(points[i],points[j])==(dis(points[i],points[k])+dis(points[k],points[j])):
j=k
K=0
area=int(1e18)
for k in range(n):
if k==i or k==j:
continue
else:
a=Area(points[i],points[j],points[k])
if area>a>0:
area=a
K=k
print(i+1,j+1,K+1)
```
No
| 100,766 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
import math
n = int(input())
p = [ list(map(int, input().split())) for i in range(0,n)]
def isTriangle(p1,p2,p3):
area = p1[0] * (p2[1] - p3[1]) + p2[1] * (p3[1] - p1[1]) + p3[1] * (p1[1] - p2[1])
return area > 0
minLen = -1
ind = -1
for i in range(2, n):
if isTriangle(p[0],p[1], p[i]):
m = (p[0][1] - p[1][1] )/(p[0][0] - p[1][0])
c = p[0][1] - m * p[0][0]
curLen = (m*p[0][0] + c + p[0][1]) / math.sqrt(m*m + 1)
if minLen == -1 or curLen < minLen:
minLen = curLen
ind = i
print(1,2,ind + 1)
```
No
| 100,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are located at the same position.
In the evening Noku is going to take a look at the night sky. He would like to find three distinct stars and form a triangle. The triangle must have positive area. In addition, all other stars must lie strictly outside of this triangle. He is having trouble finding the answer and would like your help. Your job is to find the indices of three stars that would form a triangle that satisfies all the conditions.
It is guaranteed that there is no line such that all stars lie on that line. It can be proven that if the previous condition is satisfied, there exists a solution to this problem.
Input
The first line of the input contains a single integer n (3 β€ n β€ 100 000).
Each of the next n lines contains two integers xi and yi ( - 109 β€ xi, yi β€ 109).
It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Output
Print three distinct integers on a single line β the indices of the three points that form a triangle that satisfies the conditions stated in the problem.
If there are multiple possible answers, you may print any of them.
Examples
Input
3
0 1
1 0
1 1
Output
1 2 3
Input
5
0 0
0 2
2 0
2 2
1 1
Output
1 3 5
Note
In the first sample, we can print the three indices in any order.
In the second sample, we have the following picture.
<image>
Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
Submitted Solution:
```
n=int(input())
points=[list(map(int,input().split())) for i in range(n)]
i,j=0,1
def dis(p1,p2):
return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)**0.5
def Area(p1,p2,p3):
return (p1[0]*abs(p2[1]-p3[1])+p2[0]*abs(p3[1]-p1[1])+p3[0]*abs(p1[1]-p2[1]))
for k in range(n):
if k==i or k==j:
continue
elif abs(dis(points[i],points[j])-(dis(points[i],points[k])+dis(points[k],points[j])))<=1e-10:
j=k
K=0
print(i,j)
area=int(1e20)
for k in range(n):
if k==i or k==j:
continue
else:
a=Area(points[i],points[j],points[k])
if area>a>0:
area=a
K=k
print(i+1,j+1,K+1)
```
No
| 100,768 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
def solve():
n, k, q = map(int, input().split())
fr = [0] + list(map(int, input().split()))
on = list()
a = list()
for _ in range(q):
t, i = map(int, input().split())
if t == 1:
if len(on) < k:
on.append(fr[i])
elif fr[i] > min(on):
on.append(fr[i])
on.remove(min(on))
else:
if fr[i] in on:
a.append('YES')
else:
a.append('NO')
return '\n'.join(a)
print(solve())
```
| 100,769 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
n, k, q = tuple (map(int, input().split() ))
t = tuple( map( int, input().split() ) )
online = []
full = False
for i in range(q):
query = tuple (map(int, input().split()))
if query[0] == 1:
if not full:
online.append(query[1])
full = len(online)>=k
else:
min_id = 0
for j in range(len(online)):
if t[online[min_id]-1]>t[online[j]-1]:
min_id = j
if t[online[min_id]-1]<t[query[1]-1]:
online[min_id] = query[1]
elif query[0]==2:
if query[1] in online:
print('YES')
else:
print('NO')
```
| 100,770 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
(n,k,q) = map(int,input().split())
level = list(map(int,input().split()))
qt=[]
qid=[]
lfr = set()
for i in range(0,q):
(qtemp,qidtemp) = map(int,input().split())
if (qtemp == 1):
if (len(lfr)<k):
lfr.add(qidtemp)
else:
minn = qidtemp
for el in lfr:
if (level[el-1] < level[minn-1]):
minn = el
if (level[minn-1] != level[qidtemp-1]):
lfr.remove(minn)
lfr.add(qidtemp)
if (qtemp == 2):
if (qidtemp in lfr):
print("YES")
else:
print("NO")
```
| 100,771 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def binsearch(nums, target):
left = 0
right = len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return mid
elif nums[mid] > target:
right = mid - 1
elif nums[mid] < target:
left = mid + 1
return left
n, k, q = map(int, input().split())
rels = [int(z) for z in input().split()]
online = []
for query in range(q):
t, f = map(int, input().split())
if t == 1:
pl = binsearch(online, rels[f - 1])
online.insert(pl, rels[f - 1])
if t == 2:
if binsearch(online, rels[f - 1]) >= (len(online) - k) and rels[f - 1] in online:
print("YES")
else:
print("NO")
#print(binsearch(online, rels[f - 1]), online)
```
| 100,772 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
#!/usr/bin/python3
import operator as op
from queue import PriorityQueue
import heapq
class StdReader:
def read_int(self):
return int(self.read_string())
def read_ints(self, sep=None):
return [int(i) for i in self.read_strings(sep)]
def read_float(self):
return float(self.read_string())
def read_floats(self, sep=None):
return [float(i) for i in self.read_strings(sep)]
def read_string(self):
return input()
def read_strings(self, sep=None):
return self.read_string().split(sep)
reader = StdReader()
def main():
n, k, q = reader.read_ints()
t = reader.read_ints()
# queue = PriorityQueue()
queue = []
qsize = 0
# online = [False]*n
# online_n = 0
# prior = sorted([(i, t[i]) for i in range(n)], key=op.itemgetter(1), inverse=True)
# pos = [0]*n
# for i, p in enumerate(prior):
# pos[p[0]] = i
for i in range(q):
qt, qid = reader.read_ints()
qid -= 1
if qt == 1:
# qid online
# online[qid] = True
# online_n += 1
if len(queue) == k:
# queue.get()
# heapq.heappop(queue)
# qsize -= 1
heapq.heappushpop(queue, (t[qid], qid))
else:
heapq.heappush(queue, (t[qid], qid))
# queue.put((t[qid], qid))
# heapq.heappush(queue, )
# qsize += 1
else:
# query qid
box = [i[1] for i in queue]
# print(box)
if qid in box:
print('YES')
else:
print('NO')
# if not online[qid]:
# print('NO')
# else:
# pass
if __name__ == '__main__':
main()
```
| 100,773 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
from heapq import heappush, heapreplace
n, k, q, = map(int, input().split())
a = list(map(int, input().split()))
window = []
window_set = set()
min_pr = 10 ** 10
min_pr_id = 0
for i in range(q):
type, id = map(int, input().split())
if type == 1:
if len(window) < k:
heappush(window, (a[id - 1], id))
min_pr = min(min_pr, a[id - 1])
else:
if a[id - 1] > min_pr:
heapreplace(window, (a[id - 1], id))
min_pr = window[0][0]
else:
if id in [i[1] for i in window]:
print('YES')
else:
print('NO')
```
| 100,774 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
n, k, q = map(int, input().split())
t = [0] + list(map(int, input().split()))
ts = list()
for i in range(q):
typ, idi = map(int, input().split())
if typ == 1:
cnt = len(ts)
tl = t[idi]
if (cnt < k):
ts.append(tl)
else:
if (ts[0] < tl):
del ts[0]
ts.append(tl)
ts.sort()
elif typ == 2:
if t[idi] in ts:
print("YES")
else:
print("NO")
```
| 100,775 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Tags: implementation
Correct Solution:
```
n, k, q = map(int, input().split())
t = tuple(int(friendship) for friendship in input().split())
window = set()
for i in range(q):
query, friend_id = map(int, input().split())
friend_id -= 1
if query == 1:
if len(window) < k:
window.add(friend_id)
else:
least_friend = min(window, key=lambda friend: t[friend])
if t[least_friend] < t[friend_id]:
window.discard(least_friend)
window.add(friend_id)
else:
print("YES" if friend_id in window else "NO")
```
| 100,776 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
def ke(i):
return a[i-1]
n,k,q = map(int,input().split())
a = list(map(int,input().split()))
p = []
for i in range(q):
b,id=map(int,input().split())
id-=1
if(b==1):
p+=[id+1]
p.sort(key=ke,reverse=True)
if(len(p)>k):
p=p[:-1]
else:
if id+1 in p:
print('YES')
else:
print('NO')
```
Yes
| 100,777 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
n,k,q=(int(z) for z in input().split())
s=[int(z) for z in input().split()]
t=[]
ans=[]
for i in range(q):
r=input()
if r[0]=='2':
if s[int(r[2:])-1] in t:
ans+=['YES']
else:
ans+=['NO']
else:
if len(t)<k:
t.append(s[int(r[2:])-1])
t.sort()
t.reverse()
else:
u=0
while u<=k-1 and t[u]>s[int(r[2:])-1]:
u+=1
if u<k:
for g in range(k-1,u,-1):
t[g]=t[g-1]
t[u]=s[int(r[2:])-1]
for h in ans:
print(h)
```
Yes
| 100,778 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
def main():
(n, k, q) = (int(x) for x in input().split())
bears = [int(x) for x in input().split()]
#bearsDict = {bears[i]: i for i in range(len(bears))}
queries = [None] * q
for i in range(q):
(typei, idi) = (int(x) for x in input().split())
queries[i] = (typei, idi)
solver(k, bears, queries)
def solver(k, bears, queries):
kBest = set()
for (typei, idi) in queries:
if typei == 1:
handle1(k, kBest, bears, idi)
elif typei == 2:
print(handle2(kBest, bears, idi))
def handle1(k, kBest, bears, idi):
friendship = bears[idi - 1]
if len(kBest) < k:
kBest.add(friendship)
else:
minimum = min(kBest)
if minimum < friendship:
kBest.remove(minimum)
kBest.add(friendship)
def handle2(kBest, bears, idi):
friendship = bears[idi - 1]
if friendship in kBest:
return "YES"
else:
return "NO"
# k = 3
# bears = [50, 20, 51, 17, 99, 24]
# queries = [(1, 3), (1, 4), (1, 5), (1, 2), (2, 4), (2, 2),
# (1, 1), (2, 4), (2, 3)]
# solver(k, bears, queries)
main()
```
Yes
| 100,779 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
n, k, q = map(int, input().split())
a = list(map(int, input().split()))
window = []
for i in range(q):
t, id = map(int, input().split())
if t == 1:
window.append(a[id - 1])
if len(window) > k:
window = sorted(window)[1:]
if t == 2:
find = False
for j in window:
if j == a[id - 1]:
find = True
break
if find:
print("YES")
else:
print("NO")
```
Yes
| 100,780 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
from collections import deque
from math import *
n, k ,q = map(int, input().split())
A = []
lens = 0
B = list(map(int, input().split()))
for i in range(q):
per1,per2 = map(int, input().split())
if per1 == 1:
if lens < k:
A.append([per2, B[per2-1]])
lens += 1
else:
c = float('infinity')
r = 0
for i in range(k):
if A[i][1] < c:
c = A[i][1]
r = i
A[r] = [per2, B[per2-1]]
else:
si = True
for i in range(lens):
if A[i][0] == per2:
si = False
break
if si:
print('NO')
else:
print('YES')
```
No
| 100,781 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
n, k, q = [int (a) for a in input().strip().split()]
t = [int (a) for a in input().strip().split()]
s = []
def ssort():
for i in range(len(s)-1):
if s[i] > s[i+1]:
s[i], s[i+1] = s[i+1], s[i]
break
if len(s) > k:
s.pop(0)
for i in range(q):
type, id = [int (a) for a in input().strip().split()]
if type == 1:
if len(s) == 0:
s = [t[id-1]]
else:
if len(s) < k or t[id-1] > s[0]:
s = [t[id-1]] + s
ssort()
else:
if t[id-1] in s:
print("YES")
else:
print("NO")
```
No
| 100,782 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
import sys
window = set()
n, k, q = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
for i in range(q):
a, b = [int(x) for x in input().split()]
if (a == 1):
if (len(window) <= k):
window.add(arr[b - 1])
else:
window.add(arr[b - 1])
m = min(window)
window.remove(m)
else:
print("YES" if arr[b - 1] in window else "NO")
```
No
| 100,783 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β those with biggest ti.
Your task is to handle queries of two types:
* "1 id" β Friend id becomes online. It's guaranteed that he wasn't online before.
* "2 id" β Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type?
Input
The first line contains three integers n, k and q (1 β€ n, q β€ 150 000, 1 β€ k β€ min(6, n)) β the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains n integers t1, t2, ..., tn (1 β€ ti β€ 109) where ti describes how good is Limak's relation with the i-th friend.
The i-th of the following q lines contains two integers typei and idi (1 β€ typei β€ 2, 1 β€ idi β€ n) β the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed.
It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty.
Output
For each query of the second type print one line with the answer β "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
Examples
Input
4 2 8
300 950 500 200
1 3
2 4
2 3
1 1
1 2
2 1
2 2
2 3
Output
NO
YES
NO
YES
YES
Input
6 3 9
50 20 51 17 99 24
1 3
1 4
1 5
1 2
2 4
2 2
1 1
2 4
2 3
Output
NO
YES
NO
YES
Note
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" β Friend 3 becomes online.
2. "2 4" β We should check if friend 4 is displayed. He isn't even online and thus we print "NO".
3. "2 3" β We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES".
4. "1 1" β Friend 1 becomes online. The system now displays both friend 1 and friend 3.
5. "1 2" β Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed
6. "2 1" β Print "NO".
7. "2 2" β Print "YES".
8. "2 3" β Print "YES".
Submitted Solution:
```
from heapq import *
n, f, q = [int(s) for s in input().split()]
loves = [int(s) for s in input().split()]
k = []
onlines = set()
for i in range(q):
ind, num = [int(s) for s in input().split()]
if ind == 1:
onlines.add(num - 1)
if len(k)<f:
heappush(k, loves[num - 1])
else:
heapreplace(k, loves[num-1])
else:
if num-1 in onlines and k[0] <= loves[num-1]:
print("YES")
else:
print("NO")
```
No
| 100,784 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
n = int(input())
if (n % 2 == 1):
print(n // 2)
exit(0)
i = 1
while (i <= n):
i *= 2
i //= 2
n -= i
print(n // 2)
```
| 100,785 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
n = int(input())
if (n % 2 == 1):
print(n // 2)
else:
x = 1
while (x <= n):
x *= 2
print((n - x // 2) // 2)
```
| 100,786 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
from math import log2, floor
N = int(input())
if N % 2 == 0:
N //= 2
ans = N - 2 ** floor(log2(N))
else:
ans = (N+1) // 2 - 1
print(ans)
```
| 100,787 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
import math
N = int(input().split()[0])
if N % 2:
print (int((N-1)/2))
else:
print(int((N - pow(2, int(math.log2(N))))/2))
```
| 100,788 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
n = int(input())
if n & 1:
print(n//2)
else:
k = 1
while k <= n:
k *= 2
print((n - k//2)//2)
```
| 100,789 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
n = int(input())
ans = -1
if n % 2 == 1:
ans = (n - 1) // 2
else:
two = 1
while two * 2 <= n:
two *= 2
ans = (n - two) // 2
print(ans)
```
| 100,790 |
Provide a correct Python 3 solution for this coding contest problem.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
"Correct Solution:
```
import math
a = int(input())
if a%2==1:
print(math.ceil((a-1)/2))
else:
z = 1
while z*2<=a:
z*=2
print((a-z)//2)
```
| 100,791 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
Submitted Solution:
```
n = int(input())
if n == 0:
print(0)
else:
print((n-1)//2)
```
No
| 100,792 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
Submitted Solution:
```
n=int(input())
if n%2==0 :
print(n//2-1)
else :
print((n//2))
```
No
| 100,793 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
Submitted Solution:
```
N = int(input())
ans = (N+1) // 2 - 1
if N % 2 == 0 and (N // 2) % 2 == 0:
ans = 0
elif N % 2 == 0:
ans = max(0, ans-1)
print(ans)
```
No
| 100,794 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 β€ N β€ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
Submitted Solution:
```
a = int(input())
print((a + a%2) //2 - 1)
```
No
| 100,795 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (i == j):
return p[i]
return P(i,int(j/2))*P(int(j/2)+1,j)/(1-(1-P(int(j/2)+1,j))*P(i,int(j/2)))
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
```
No
| 100,796 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (r[i][j] == 0):
if (i == j):
r[i][j] = p[i]
return p[i]
r[i][j] = p[i]*P(i+1,j)/(1-(1-P(i+1,j))*p[i])
return p[i]*P(i+1,j)/(1-(1-P(i+1,j))*p[i])
else:
return r[i][j]
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
for j in range (n):
r[int(a[1])-1][j] = 0
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
```
No
| 100,797 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (i == j):
return p[i]
bord = i + 1
if (j == i + 1):
bord = i
return P(i,bord)*P(bord+1,j)/(1 - P(i,bord)*(1 - P(bord+1,j)) )
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
```
No
| 100,798 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n casinos lined in a row. If Memory plays at casino i, he has probability pi to win and move to the casino on the right (i + 1) or exit the row (if i = n), and a probability 1 - pi to lose and move to the casino on the left (i - 1) or also exit the row (if i = 1).
We say that Memory dominates on the interval i... j if he completes a walk such that,
* He starts on casino i.
* He never looses in casino i.
* He finishes his walk by winning in casino j.
Note that Memory can still walk left of the 1-st casino and right of the casino n and that always finishes the process.
Now Memory has some requests, in one of the following forms:
* 1 i a b: Set <image>.
* 2 l r: Print the probability that Memory will dominate on the interval l... r, i.e. compute the probability that Memory will first leave the segment l... r after winning at casino r, if she starts in casino l.
It is guaranteed that at any moment of time p is a non-decreasing sequence, i.e. pi β€ pi + 1 for all i from 1 to n - 1.
Please help Memory by answering all his requests!
Input
The first line of the input contains two integers n and q(1 β€ n, q β€ 100 000), β number of casinos and number of requests respectively.
The next n lines each contain integers ai and bi (1 β€ ai < bi β€ 109) β <image> is the probability pi of winning in casino i.
The next q lines each contain queries of one of the types specified above (1 β€ a < b β€ 109, 1 β€ i β€ n, 1 β€ l β€ r β€ n).
It's guaranteed that there will be at least one query of type 2, i.e. the output will be non-empty. Additionally, it is guaranteed that p forms a non-decreasing sequence at all times.
Output
Print a real number for every request of type 2 β the probability that boy will "dominate" on that interval. Your answer will be considered correct if its absolute error does not exceed 10 - 4.
Namely: let's assume that one of your answers is a, and the corresponding answer of the jury is b. The checker program will consider your answer correct if |a - b| β€ 10 - 4.
Example
Input
3 13
1 3
1 2
2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
1 2 2 3
2 1 1
2 1 2
2 1 3
2 2 2
2 2 3
2 3 3
Output
0.3333333333
0.2000000000
0.1666666667
0.5000000000
0.4000000000
0.6666666667
0.3333333333
0.2500000000
0.2222222222
0.6666666667
0.5714285714
0.6666666667
Submitted Solution:
```
import math
import sys
n,q = input().split()
n = int(n)
q = int(q)
p = [0]*n
for i in range(n):
a = input().split()
p[i] = int(a[0])/int(a[1])
r = [0]*n
for i in range(n):
r[i] = [0]*n
def P(i,j):
if (i == j):
return p[i]
bord = int((j+i - 1)/2)
if (j == i + 1):
bord = i
return P(i,bord)*P(bord+1,j)/(1 - P(i,bord)*(1 - P(bord+1,j)) )
for i in range(q):
a = input().split()
if (int(a[0]) == 1):
p[int(a[1])-1] = int(a[2])/int(a[3])
if (int(a[0]) == 2):
print(P(int(a[1])-1,int(a[2])-1))
```
No
| 100,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.