text stringlengths 198 433k | conversation_id int64 0 109k |
|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.
However, the site is not so simple on the inside. There are two servers, each with its separate counts for the upvotes and the downvotes.
n reviewers enter the site one by one. Each reviewer is one of the following types:
* type 1: a reviewer has watched the movie, and they like it — they press the upvote button;
* type 2: a reviewer has watched the movie, and they dislike it — they press the downvote button;
* type 3: a reviewer hasn't watched the movie — they look at the current number of upvotes and downvotes of the movie on the server they are in and decide what button to press. If there are more downvotes than upvotes, then a reviewer downvotes the movie. Otherwise, they upvote the movie.
Each reviewer votes on the movie exactly once.
Since you have two servers, you can actually manipulate the votes so that your movie gets as many upvotes as possible. When a reviewer enters a site, you know their type, and you can send them either to the first server or to the second one.
What is the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of testcases.
Then the descriptions of t testcases follow.
The first line of each testcase contains a single integer n (1 ≤ n ≤ 50) — the number of reviewers.
The second line of each testcase contains n integers r_1, r_2, ..., r_n (1 ≤ r_i ≤ 3) — the types of the reviewers in the same order they enter the site.
Output
For each testcase print a single integer — the maximum total number of upvotes you can gather over both servers if you decide which server to send each reviewer to.
Example
Input
4
1
2
3
1 2 3
5
1 1 1 1 1
3
3 3 2
Output
0
2
5
2
Note
In the first testcase of the example you can send the only reviewer to either of the servers — they'll downvote anyway. The movie won't receive any upvotes.
In the second testcase of the example you can send all reviewers to the first server:
* the first reviewer upvotes;
* the second reviewer downvotes;
* the last reviewer sees that the number of downvotes is not greater than the number of upvotes — upvote themselves.
There are two upvotes in total. Alternatevely, you can send the first and the second reviewers to the first server and the last reviewer — to the second server:
* the first reviewer upvotes on the first server;
* the second reviewer downvotes on the first server;
* the last reviewer sees no upvotes or downvotes on the second server — upvote themselves.
Submitted Solution:
```
"""
Author : Ashish Sasmal
Python3
"""
from sys import stdin as sin
def aint():return int(input())
def amap():return map(int,sin.readline().split())
def alist():return list(map(int,sin.readline().split()))
def astr():return input()
for _ in range(aint()):
n = aint()
l = alist()
up1=0
up2=0
d1=0
d2=0
for i in range(n):
if l[i]==1:
if d1>=0 and d2>=0:
if d1>=d2:
up2+=1
d2+=1
else:
up1+=1
d1+=1
elif d1>=0:
up1+=1
d1+=1
elif d2>=0:
up2+=1
d2+=1
elif d1<d2:
d1+=1
up1+=1
else:
d2+=1
up2+=1
elif l[i]==2:
if d1>=0 and d2>=0:
if d1>=d2:
d1-=1
else:
d2-=1
elif d1>=0:
d1-=1
elif d2>=0:
d2-=1
elif d1<d2:
d2-=1
else:
d1-=1
else:
if d1>=0 and d2>=0:
if d1<=d2:
up1+=1
d1+=1
else:
up2+=1
d2+=1
elif d1>=0:
up1+=1
d1+=1
elif d2>=0:
up2+=1
d2+=1
elif d1<=d2:
d2-=1
else:
d1-=1
print(up1+up2)
```
No
| 102,300 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
t = int(input())
while(t > 0):
t -= 1
l, r = [int(x) for x in input().split()]
num1 = str(l)
num2 = str(r)
ans = 0
while(len(num1) != len(num2)):
num1 = '0' + num1
for i in range(len(num1)):
k1 = int(num1[:i+1])
k2 = int(num2[:i+1])
ans += k2 - k1
print(ans)
```
| 102,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
for _ in range(int(input())):
l,r=map(int,input().split())
ansl=0
ansr=0
ansl+=l-1
ansr+=r-1
# print(ansl,ansr)
while(l):
ansl+=l//10
l//=10
while(r):
ansr+=r//10
r//=10
print(ansr-ansl)
```
| 102,302 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
L, R = [int(x) for x in input().split()]
ans = R - L
cnt_r = 0
cnt_l = 0
for i in range(1, 20):
cnt_r += R // pow(10, i)
cnt_l += L // pow(10, i)
ans += cnt_r - cnt_l
print(ans)
if __name__ == '__main__':
main()
```
| 102,303 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
for s in[*open(0)][1:]:
x,y=map(int,s.split());r=0
while y:r+=y-x;x//=10;y//=10
print(r)
```
| 102,304 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
def main():
ans = [] #Respuestas
for _ in range(int(input())):
l, t = map(int, input().split()) #Numeros iniciales
cha = 0 #Cantidad de cambios
while t > 0:
cha += t - l
l //= 10
t //= 10
ans.append(cha)
for i in ans: print(i)
if __name__ == "__main__":
main()
```
| 102,305 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
t=int(input())
for _ in range(t):
l,r=map(int,input().split())
c1=r-l
for i in range(1,10):
c1+=r//(10**i)
c2=0
for i in range(1,10):
c2+=l//(10**i)
print(c1-c2)
```
| 102,306 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
for _ in range(int(input())):
l,r = map(int,input().split())
ans = 0
while r:
ans += r-l
r //= 10
l //= 10
print(ans)
```
| 102,307 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Tags: binary search, dp, math, number theory
Correct Solution:
```
import sys
input=sys.stdin.readline
t=int(input())
c=[1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111]
for _ in range(t):
l,r=map(int,input().split())
aa=0
a=len(str(r))
r=str(r)
for i in range(a):
aa+=int(r[i])*c[a-i-1]
bb=0
b=len(str(l))
l=str(l)
for i in range(b):
bb+=int(l[i])*c[b-i-1]
print(aa-bb)
```
| 102,308 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
def func(r):
if r==1:
return 0
total_digits = len(str(r))
nums_divisible_by_ten = [0 for i in range(total_digits+1)]
starting = total_digits-1
count = 0
while starting>0:
divisor = 10**(starting)
nums_divisible_by_ten[starting] = (r//divisor)-count
count = (r//divisor)
starting-=1
total_sum = 0
for j in range(1, total_digits+1):
total_sum += nums_divisible_by_ten[j]*(j+1)
total_sum += r-sum(nums_divisible_by_ten)-1
return total_sum
t = int(input())
for i in range(t):
l, r = map(int, input().split())
print(func(r)-func(l))
```
Yes
| 102,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
T=int(input())
for t in range(T):
l,r=map(int,input().split())
ans=0
for i in range(10):
div=10**i
ans+=r//div-l//div
print(ans)
```
Yes
| 102,310 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
for s in[*open(0)][1:]:
r=0;k=-1
for x in map(int,s.split()):
while x:r+=k*x;x//=10
k=1
print(r)
```
Yes
| 102,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
import time,math as mt,bisect as bs,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
return int(stdin.readline())
def IP(): # to take tuple as input
return map(int,stdin.readline().split())
def L(): # to take list as input
return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
if a==0:
return b
elif b==0:
return a
if a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
def bfs(adj,v): # a schema of bfs
visited=[False]*(v+1)
q=deque()
while q:
pass
def setBit(n):
count=0
while n!=0:
n=n&(n-1)
count+=1
return count
def readTree(n,e): # to read tree
adj=[set() for i in range(n+1)]
for i in range(e):
u1,u2=IP()
adj[u1].add(u2)
return adj
def sieve():
li=[True]*(10**3+5)
li[0],li[1]=False,False
for i in range(2,len(li),1):
if li[i]==True:
for j in range(i*i,len(li),i):
li[j]=False
prime,cur=[0]*200,0
for i in range(10**3+5):
if li[i]==True:
prime[cur]=i
cur+=1
return prime
def SPF():
mx=(10**7+1)
spf=[mx]*(mx)
spf[1]=1
for i in range(2,mx):
if spf[i]==mx:
spf[i]=i
for j in range(i*i,mx,i):
if i<spf[j]:
spf[j]=i
return spf
def prime(n,d):
while n!=1:
d[spf[n]]=d.get(spf[n],0)+1
n=n//spf[n]
return
#####################################################################################
mod = 1000000007
inf = 1e18
def solve():
l,r=IP()
strt = 1
ans=0
while r:
ans+=(r-l)
r//=10
l//=10
print(ans)
return
t = II()
for i in range(t):
solve()
#######
#
#
####### # # # #### # # #
# # # # # # # # # # #
# #### # # #### #### # #
###### # # #### # # # # #
# ``````¶0````1¶1_```````````````````````````````````````
# ```````¶¶¶0_`_¶¶¶0011100¶¶¶¶¶¶¶001_````````````````````
# ````````¶¶¶¶¶00¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶0_````````````````
# `````1_``¶¶00¶0000000000000000000000¶¶¶¶0_`````````````
# `````_¶¶_`0¶000000000000000000000000000¶¶¶¶¶1``````````
# ```````¶¶¶00¶00000000000000000000000000000¶¶¶_`````````
# ````````_¶¶00000000000000000000¶¶00000000000¶¶`````````
# `````_0011¶¶¶¶¶000000000000¶¶00¶¶0¶¶00000000¶¶_````````
# ```````_¶¶¶¶¶¶¶00000000000¶¶¶¶0¶¶¶¶¶00000000¶¶1````````
# ``````````1¶¶¶¶¶000000¶¶0¶¶¶¶¶¶¶¶¶¶¶¶0000000¶¶¶````````
# ```````````¶¶¶0¶000¶00¶0¶¶`_____`__1¶0¶¶00¶00¶¶````````
# ```````````¶¶¶¶¶00¶00¶10¶0``_1111_`_¶¶0000¶0¶¶¶````````
# ``````````1¶¶¶¶¶00¶0¶¶_¶¶1`_¶_1_0_`1¶¶_0¶0¶¶0¶¶````````
# ````````1¶¶¶¶¶¶¶0¶¶0¶0_0¶``100111``_¶1_0¶0¶¶_1¶````````
# ```````1¶¶¶¶00¶¶¶¶¶¶¶010¶``1111111_0¶11¶¶¶¶¶_10````````
# ```````0¶¶¶¶__10¶¶¶¶¶100¶¶¶0111110¶¶¶1__¶¶¶¶`__````````
# ```````¶¶¶¶0`__0¶¶0¶¶_¶¶¶_11````_0¶¶0`_1¶¶¶¶```````````
# ```````¶¶¶00`__0¶¶_00`_0_``````````1_``¶0¶¶_```````````
# ``````1¶1``¶¶``1¶¶_11``````````````````¶`¶¶````````````
# ``````1_``¶0_¶1`0¶_`_``````````_``````1_`¶1````````````
# ``````````_`1¶00¶¶_````_````__`1`````__`_¶`````````````
# ````````````¶1`0¶¶_`````````_11_`````_``_``````````````
# `````````¶¶¶¶000¶¶_1```````_____```_1``````````````````
# `````````¶¶¶¶¶¶¶¶¶¶¶¶0_``````_````_1111__``````````````
# `````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶01_`````_11____1111_```````````
# `````````¶¶0¶0¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶1101_______11¶_```````````
# ``````_¶¶¶0000000¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶0¶0¶¶¶1````````````
# `````0¶¶0000000¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶1`````````````
# ````0¶0000000¶¶0_````_011_10¶110¶01_1¶¶¶0````_100¶001_`
# ```1¶0000000¶0_``__`````````_`````````0¶_``_00¶¶010¶001
# ```¶¶00000¶¶1``_01``_11____``1_``_`````¶¶0100¶1```_00¶1
# ``1¶¶00000¶_``_¶_`_101_``_`__````__````_0000001100¶¶¶0`
# ``¶¶¶0000¶1_`_¶``__0_``````_1````_1_````1¶¶¶0¶¶¶¶¶¶0```
# `_¶¶¶¶00¶0___01_10¶_``__````1`````11___`1¶¶¶01_````````
# `1¶¶¶¶¶0¶0`__01¶¶¶0````1_```11``___1_1__11¶000`````````
# `1¶¶¶¶¶¶¶1_1_01__`01```_1```_1__1_11___1_``00¶1````````
# ``¶¶¶¶¶¶¶0`__10__000````1____1____1___1_```10¶0_```````
# ``0¶¶¶¶¶¶¶1___0000000```11___1__`_0111_```000¶01```````
# ```¶¶¶00000¶¶¶¶¶¶¶¶¶01___1___00_1¶¶¶`_``1¶¶10¶¶0```````
# ```1010000¶000¶¶0100_11__1011000¶¶0¶1_10¶¶¶_0¶¶00``````
# 10¶000000000¶0________0¶000000¶¶0000¶¶¶¶000_0¶0¶00`````
# ¶¶¶¶¶¶0000¶¶¶¶_`___`_0¶¶¶¶¶¶¶00000000000000_0¶00¶01````
# ¶¶¶¶¶0¶¶¶¶¶¶¶¶¶_``_1¶¶¶00000000000000000000_0¶000¶01```
# 1__```1¶¶¶¶¶¶¶¶¶00¶¶¶¶00000000000000000000¶_0¶0000¶0_``
# ```````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶00000000000000000000010¶00000¶¶_`
# ```````0¶¶¶¶¶¶¶¶¶¶¶¶¶¶00000000000000000000¶10¶¶0¶¶¶¶¶0`
# ````````¶¶¶¶¶¶¶¶¶¶0¶¶¶00000000000000000000010¶¶¶0011```
# ````````1¶¶¶¶¶¶¶¶¶¶0¶¶¶0000000000000000000¶100__1_`````
# `````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶000000000000000000¶11``_1``````
# `````````1¶¶¶¶¶¶¶¶¶¶¶0¶¶¶00000000000000000¶11___1_`````
# ``````````¶¶¶¶¶¶0¶0¶¶¶¶¶¶¶0000000000000000¶11__``1_````
# ``````````¶¶¶¶¶¶¶0¶¶¶0¶¶¶¶¶000000000000000¶1__````__```
# ``````````¶¶¶¶¶¶¶¶0¶¶¶¶¶¶¶¶¶0000000000000000__`````11``
# `````````_¶¶¶¶¶¶¶¶¶000¶¶¶¶¶¶¶¶000000000000011_``_1¶¶¶0`
# `````````_¶¶¶¶¶¶0¶¶000000¶¶¶¶¶¶¶000000000000100¶¶¶¶0_`_
# `````````1¶¶¶¶¶0¶¶¶000000000¶¶¶¶¶¶000000000¶00¶¶01`````
# `````````¶¶¶¶¶0¶0¶¶¶0000000000000¶0¶00000000011_``````_
# ````````1¶¶0¶¶¶0¶¶¶¶¶¶¶000000000000000000000¶11___11111
# ````````¶¶¶¶0¶¶¶¶¶00¶¶¶¶¶¶000000000000000000¶011111111_
# ```````_¶¶¶¶¶¶¶¶¶0000000¶0¶00000000000000000¶01_1111111
# ```````0¶¶¶¶¶¶¶¶¶000000000000000000000000000¶01___`````
# ```````¶¶¶¶¶¶0¶¶¶000000000000000000000000000¶01___1````
# ``````_¶¶¶¶¶¶¶¶¶00000000000000000000000000000011_111```
# ``````0¶¶0¶¶¶0¶¶0000000000000000000000000000¶01`1_11_``
# ``````¶¶¶¶¶¶0¶¶¶0000000000000000000000000000001`_0_11_`
# ``````¶¶¶¶¶¶¶¶¶00000000000000000000000000000¶01``_0_11`
# ``````¶¶¶¶0¶¶¶¶00000000000000000000000000000001```_1_11
```
Yes
| 102,312 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
for _ in range(int(input())):
l,r=map(int,input().split())
tmp=1
count=0
a=1
while tmp//a>0:
count += tmp//a
a*=10
tmp=r
count1=0
a=1
while tmp//a>0:
count1 += tmp//a
a*=10
print(count1-count)
```
No
| 102,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
# by the authority of GOD author: Kritarth Sharma #
import math,copy
from collections import defaultdict,Counter
#from itertools import permutations
def fact(n):
return 1 if (n == 1 or n == 0) else n * fact(n - 1)
def prime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def inp():
l=list(map(int,input().split()))
return l
## code starts here
#################################################################################################################
def ll(s):
s=str(s)
k=1
for i in range(len(s)-1,-1,-1):
if s[i]=='9':
k+=1
else:
break
return k
def main():
for _ in range(int(input())):
l,r=inp()
k=0
while l<r:
if l+1000000000<r:
k+=1111111111
l+=1000000000
elif l+100000000<r:
k+=111111111
l+=100000000
elif l+10000000<r:
k+=11111111
l+=10000000
elif l+1000000<r:
k+=1111111
l+=1000000
elif l+100000<r:
k+=111111
l+=100000
elif l+10000<r:
k+=11111
l+=10000
elif l+1000<r:
k+=1111
l+=1000
elif l+100<r:
k+=111
l+=100
elif l+10<r:
k+=11
l+=10
else:
k+=ll(l)
l+=1
print(k)
import os,sys
from io import BytesIO,IOBase
#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()
def random():
"""My code gets caught in plagiarism check for no reason due to the fast IO template, .
Due to this reason, I am making useless functions"""
rating=100
rating=rating*100
rating=rating*100
print(rating)
def random():
"""My code gets caught in plagiarism check for no reason due to the fast IO template, .
Due to this reason, I am making useless functions"""
rating=100
rating=rating*100
rating=rating*100
print(rating)
def random():
"""My code gets caught in plagiarism check for no reason due to the fast IO template, .
Due to this reason, I am making useless functions"""
rating=100
rating=rating*100
rating=rating*100
print(rating)
def random():
"""My code gets caught in plagiarism check for no reason due to the fast IO template, .
Due to this reason, I am making useless functions"""
rating=100
rating=rating*100
rating=rating*100
print(rating)
```
No
| 102,314 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
t = int(input())
for _ in range(t):
l,r = map(int,input().split())
res = r-l
nin = res//9
res+= (nin)
if(l%9==0 and r%10==2):
res+=1
print(res)
```
No
| 102,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers l and r, where l < r. We will add 1 to l until the result is equal to r. Thus, there will be exactly r-l additions performed. For each such addition, let's look at the number of digits that will be changed after it.
For example:
* if l=909, then adding one will result in 910 and 2 digits will be changed;
* if you add one to l=9, the result will be 10 and 2 digits will also be changed;
* if you add one to l=489999, the result will be 490000 and 5 digits will be changed.
Changed digits always form a suffix of the result written in the decimal system.
Output the total number of changed digits, if you want to get r from l, adding 1 each time.
Input
The first line contains an integer t (1 ≤ t ≤ 10^4). Then t test cases follow.
Each test case is characterized by two integers l and r (1 ≤ l < r ≤ 10^9).
Output
For each test case, calculate the total number of changed digits if you want to get r from l, adding one each time.
Example
Input
4
1 9
9 10
10 20
1 1000000000
Output
8
2
11
1111111110
Submitted Solution:
```
t = int(input())
for _ in range(t):
# n = int(input())
l,r = map(int, input().split())
q = str(l)
w = str(r)
cnt = -len(q)+len(w)
x = r-l
while x>0:
cnt+=x
x=x//10
print(cnt)
```
No
| 102,316 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
def isLeft(pt,pt_l):
return (pt[1] == pt_l[1] and pt_l[0]<pt[0])
def isRight(pt,pt_r):
return (pt[1] == pt_r[1] and pt_r[0]>pt[0])
def isUpper(pt,pt_u):
return (pt[1]< pt_u[1] and pt_u[0]==pt[0])
def isLower(pt,pt_lo):
return (pt[1] > pt_lo[1] and pt_lo[0]== pt[0])
n=int(input())
points =[]
for i in range(n):
points.append(list(map(int,input().split(' '))))
count=0
ori_points = points
super_central ={'Left':False,'Right':False,'Lower':False,'Upper':False }
for i in range(len(ori_points)):
for k in super_central: super_central[k] = False
for j in range(len(ori_points)):
if(i!=j):
if(isLeft(ori_points[i],ori_points[j])):
super_central['Left'] = True
elif(isRight(ori_points[i],ori_points[j])):
super_central['Right'] = True
elif(isUpper(ori_points[i],ori_points[j])):
super_central['Upper'] = True
elif(isLower(ori_points[i],ori_points[j])):
super_central['Lower'] = True
if all(super_central.values()):
count +=1
print(count)
```
| 102,317 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
l=[]
count=0
for _ in range(int(input())):
l.append(list(map(int,input().split())))
for i in l:
top=[]
bottom=[]
left=[]
right=[]
for j in l:
if i is not j:
if i[0]==j[0] and i[1]>j[1]:
bottom.append(j)
elif i[0]==j[0] and i[1]<j[1]:
top.append(j)
elif i[1]==j[1] and i[0]>j[0]:
left.append(j)
elif i[1]==j[1] and i[0]<j[0]:
right.append(j)
if(len(top)>0 and len(bottom)>0 and len(right)>0 and len(left)>0):
count+=1
print(count)
```
| 102,318 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
n=int(input())
a=[]
for i in range(0,n):
a.append([int(j)for j in input().split()])
flag=0
for i in range(0,n):
c1=0
c2=0
c3=0
c4=0
for j in range(0,n):
if i!=j:
if a[i][0]<a[j][0]and a[i][1]==a[j][1]:
c1+=1
if a[i][0]>a[j][0]and a[i][1]==a[j][1]:
c2+=1
if a[i][0]==a[j][0] and a[i][1]>a[j][1]:
c3+=1
if a[i][0]==a[j][0] and a[i][1]<a[j][1]:
c4+=1
if c1>=1 and c2>=1 and c3>=1 and c4>=1:
flag+=1
print(flag)
```
| 102,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
n = int(input())
points = []
for j in range(n):
x,y = map(int,input().split())
points.append([x,y])
count = 0
for j in range(n):
corr = points[j]
lower,upper,left,right = False,False,False,False
for k in range(n):
value = points[k]
if(value[0]==corr[0] and value[1]<corr[1]):
lower = True
if(value[0]==corr[0] and value[1]>corr[1]):
upper = True
if(value[0]<corr[0] and value[1]==corr[1]):
left = True
if(value[0]>corr[0] and value[1]==corr[1]):
right = True
if(lower and upper and left and right):
count+=1
print(count)
```
| 102,320 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 18 23:27:19 2020
@author: Tanmay
"""
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 18 22:29:52 2020
@author: Tanmay
"""
from collections import OrderedDict
leflis=[]
rightlis=[]
checkl=[]
lis=[]
n=int(input())
for i in range(n):
arr=list(map(int,input().strip().split()))
lis.append(arr)
for i in range(n):
p=lis[i][0]
for j in range(n):
if(lis[j][0]==p):
checkl.append(lis[j])
if(len(checkl)>2):
checkl=sorted(checkl,key=lambda x:x[1])
maxa=checkl[-1]
checkl.remove(maxa)
mina=checkl[0]
checkl.remove(mina)
for q in range(len(checkl)):
leflis.append(checkl[q])
del(checkl)
checkl=[]
lefta=[]
for i in leflis:
if (i not in lefta):
lefta.append(i)
for i in range(n):
p=lis[i][1]
for j in range(n):
if(lis[j][1]==p):
checkl.append(lis[j])
if(len(checkl)>2):
checkl=sorted(checkl,key=lambda x:x[0])
maxa=checkl[-1]
checkl.remove(maxa)
mina=checkl[0]
checkl.remove(mina)
for q in range(len(checkl)):
rightlis.append(checkl[q])
del(checkl)
checkl=[]
righta=[]
for i in rightlis:
if(i not in righta):
righta.append(i)
ans=0
for i in righta:
if(i in lefta):
ans+=1
print(ans)
```
| 102,321 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
# Bismillahi-R-Rahmani-R-Rahim
"""
Created on Mon Jul 13 19:15:39 2020
@author: Samiul2651
"""
a = int(input())
x = []
y = []
i = 0
while i < a:
c,d = input().split(" ")
x.insert(i,int(c))
y.insert(i,int(d))
i += 1
i = 0
b = 0
while i < a:
j = 0
l = 0
e = 0
f = 0
g = 0
h = 0
while j < a:
if j != i:
if x[j] == x[i]:
if y[j] > y[i]:
if e == 0:
l += 1
e += 1
elif y[j] < y[i]:
if f == 0:
l += 1
f += 1
elif y[j] == y[i]:
if x[j] > x[i]:
if g == 0:
l += 1
g += 1
elif x[j] < x[i]:
if h == 0:
l += 1
h += 1
j += 1
#print(l)
if l == 4:
b += 1
i += 1
#print(l,b)
print(b)
```
| 102,322 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
# coding: utf-8
n = int(input())
li = []
for i in range(n):
li.append([int(j) for j in input().split()])
lx = {}
ly = {}
for p in li:
if p[1] in lx.keys():
if p[0]>lx[p[1]][1]:
lx[p[1]][1] = p[0]
elif p[0]<lx[p[1]][0]:
lx[p[1]][0] = p[0]
else:
lx[p[1]] = [p[0],p[0]]
if p[0] in ly.keys():
if p[1]>ly[p[0]][1]:
ly[p[0]][1] = p[1]
elif p[1]<ly[p[0]][0]:
ly[p[0]][0] = p[1]
else:
ly[p[0]] = [p[1],p[1]]
ans = 0
for p in li:
if p[0] in ly.keys() and p[1]>ly[p[0]][0] and p[1]<ly[p[0]][1]\
and p[1] in lx.keys() and p[0]>lx[p[1]][0] and p[0]<lx[p[1]][1]:
ans += 1
print(ans)
```
| 102,323 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Tags: implementation
Correct Solution:
```
l=int(input()); n=set([]); a=set([]); b=set([]); t=0
for i in range(l):
(c,d)=tuple(int(j) for j in input().split())
n.add((c,d)); a.add(c); b.add(d)
for c in n:
(l,r)=c; p=0; ok=False
for i in a:
if i<l and (i,r) in n: ok=True; p+=1; break;
for i in a:
if i>l and (i,r) in n: ok&=True; p+=1; break;
for i in b:
if i<r and (l,i) in n: ok&=True; p+=1; break;
for i in b:
if i>r and (l,i) in n: ok&=True; p+=1; break;
if ok and p==4: t+=1
print(t)
```
| 102,324 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
t=[]
r=int(input())
for j in range(r):
y=list(map(int,input().split()))
t.append(y)
p=0
for k in t:
a=k
q=[0]*4
for h in t:
if h[0]<a[0] and h[1]==a[1]:
q[0]+=1
if h[0]>a[0] and h[1]==a[1]:
q[1]+=1
if h[1]>a[1] and h[0]==a[0]:
q[2]+=1
if h[1]<a[1] and h[0]==a[0]:
q[3]+=1
if min(q)>0:
p+=1
print(p)
```
Yes
| 102,325 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n):
y=[int(x) for x in input().split()]
a.append(y)
t=0
for x,y in a:
u=0
d=0
r=0
l=0
for p,q in a:
if(p>x and q==y):
r=1
elif(p<x and q==y):
l=1
elif(p==x and q>y):
u=1
elif(p==x and q<y):
d=1
if(r==1 and l==1 and u==1 and d==1):
t+=1
break
print(t)
```
Yes
| 102,326 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n):
x,y=map(int,input().split())
a.append((x,y))
sx=sorted(a,key=lambda x:(x[0],x[1]))
sy=sorted(a,key=lambda x:(x[1],x[0]))
ix=set()
iy=set()
for i in range(1,n-1):
if sx[i][0] == sx[i-1][0] == sx[i+1][0]:
ix.add(sx[i])
if sy[i][1] == sy[i-1][1] == sy[i+1][1]:
iy.add(sy[i])
print(len(ix&iy))
```
Yes
| 102,327 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
n=int(input())
x=[]
y=[]
r=0
for i in range(n):
s,t=map(int,input().split())
x.append(s)
y.append(t)
for i in range(n):
a,b,c,d=0,0,0,0
for j in range(n):
if(i==j):
continue
else:
if(x[j]>x[i] and y[i]==y[j] and a==0):
a=a+1
if(x[j]<x[i] and y[i]==y[j] and b==0):
b=b+1
if(x[j]==x[i] and y[i]<y[j] and c==0):
c=c+1
if(x[j]==x[i] and y[i]>y[j] and d==0):
d=d+1
if(a>0 and b>0 and c>0 and d>0):
r=r+1
print(r)
```
Yes
| 102,328 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
import sys
hash_x = {}
hash_y = {}
n = int(input())
points = []
x_max = y_max = -1* sys.maxsize
x_min = y_min = sys.maxsize
for i in range(n):
temp= [int(x) for x in input().split()]
points.append(list(temp))
if temp[0] not in hash_x:
hash_x[temp[0]] = 1
else:
hash_x[temp[0]] += 1
x_max = max(x_max, temp[0])
x_min = min(x_min, temp[0])
if temp[1] not in hash_y:
hash_y[temp[1]] = 1
else:
hash_y[temp[1]] += 1
y_max = max(y_max, temp[1])
y_min = min(y_min, temp[1])
temp.clear()
# print(points)
# print([x_max, x_min, y_max, y_min])
keys_x = list(hash_x.keys())
keys_y = list(hash_y.keys())
# print(keys[1], hash_y.keys())
def __helper(x, y):
ans = 0
for i in keys_x:
# print([i, y])
if i <= x :
continue
for point in points:
if [i, y] == point:
# print([i, y])
ans+=1
break
if ans == 1:
break
for i in keys_x:
# print([i, y])
if i >= x:
continue
for point in points:
if [i, y] == point:
# print([i, y])
ans+=1
break
if ans == 2:
break
for i in keys_y:
if i <= y :
continue
# print([i, y])
for point in points:
if [x, i] == point:
# print([x, i])
ans+=1
break
if ans == 3:
break
for i in keys_y:
if i >= y :
continue
# print([i, y])
for point in points:
if [x, i] == point:
# print([x, i])
ans+=1
break
if ans == 4:
break
# print(ans)
if ans == 4:
return True
return False
res = 0
for point in points:
if point[0] == x_max or point[0] == x_min:
continue
if point[1] == y_max or point[1] == y_min:
continue
if __helper(point[0], point[1]):
# print("---------------------------------------------------------")
print(point[0], point[1])
res += 1
# print([x_min, x_max, y_min, y_max])
print(res)
```
No
| 102,329 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
def check(x,y,points):
c = 0
for p in points:
if p[0]>x and p[1]==y:
c+=1
if p[0]<x and p[1]==y:
c+=1
if p[0]==x and p[1]>y:
c+=1
if p[0]==x and p[1]<y:
c+=1
if c>=4:
return True
else:
return False
n = int(input())
points = []
for _ in range(n):
x,y = map(int,input().split())
points.append([x,y])
ans = 0
for i in points:
if check(i[0],i[1],points):
ans+=1
print(ans)
```
No
| 102,330 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
from collections import Counter
n = int(input())
l =[]
for i in range(n):
t = tuple(map(int,input().split()))
l.append(t)
c =0
k=1
for i in range(n):
key = l[i]
x = key[0]
y =key[1]
for j in range(n):
s = l[j]
x1 = s[0]
y1 = s[1]
al = []
if x1 > x and y1 ==y :
k+=1
if s not in al:
al.append(s)
elif x1 < x and y1 ==y:
k+=1
if s not in al:
al.append(s)
elif x1 ==x and y1 < y:
k+=1
if s not in al:
al.append(s)
elif x1 ==x and y1 > y:
k+=1
if s not in al:
al.append(s)
if k>=4:
c+=1
print(c//4)
```
No
| 102,331 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
* point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
* point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
* point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y
We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.
Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
Input
The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Output
Print the only number — the number of supercentral points of the given set.
Examples
Input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
2
Input
5
0 0
0 1
1 0
0 -1
-1 0
Output
1
Note
In the first sample the supercentral points are only points (1, 1) and (1, 2).
In the second sample there is one supercental point — point (0, 0).
Submitted Solution:
```
n=int(input(""))
x=[]
y=[]
for i in range(n):
a,b=[int(x) for x in input("").split()]
x.append(a)
y.append(b)
p={}
q={}
for i in x:
if i in p:
p[i] +=1
else:
p[i]= 1
for i in y:
if i in q:
q[i]=q[i]+1
else:
q[i]= 1
z=[]
for i in p:
if(p[i]>=3):
z.append(i)
for i in q:
if(q[i]>=3):
z.append(i)
z=set(z)
print(len(z))
```
No
| 102,332 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
n, t1, t2, k=map(int, input().split(' '))
nums=[[0, 0] for t in range(n)]
for line in range(n):
a, b=map(int, input().split(' '))
nums[line][0]=max(a*t2+b*(t1*(1-k/100)), b*t2+a*(t1*(1-k/100)))
nums[line][1]=13379001-line
nums.sort()
nums.reverse()
for a in range(len(nums)):
print(13379001-nums[a][1]+1, "{0:.2f}".format(nums[a][0]))
```
| 102,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
n,t1,t2,k=map(int,input().split())
k=k/100
c=[]
for i in range(n):
a,b=map(int,input().split())
cal=max((a*t1)-(a*t1*k)+(b*t2),(b*t1)-(b*t1*k)+(a*t2))
c.append((i+1,cal))
# print(c)
c.sort(key=lambda x:x[1],reverse=True)
# print(c)
for i in c:
print(i[0],end=' ')
print('%.2f'%(i[1]),end=' ')
print()
```
| 102,334 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
'''http://codeforces.com/contest/186/problem/B'''
n,t1,t2,k = map(int, input().split(" "))
factor = 1- (k/100)
listX = []
for i in range(n):
a,b = map(int, input().split(" "))
maxX = max(((a*t1*factor) + (b*t2)),((b*t1*factor)+(a*t2)))
# print(maxX)
listX.append(maxX)
maxVal = max(listX)
while (maxVal!=-1):
indexMax = listX.index(maxVal)
print(indexMax +1,'%.2f'%maxVal)
listX[indexMax] = -1
maxVal = max(listX)
```
| 102,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
n, t1, t2, k = [int(i) for i in input().split()]
ans = []
for i in range(n):
v, u = [int(i) for i in input().split()]
h = max(v*t1*(100 - k)/100 + u*t2, u*t1*(100 - k)/100 + v*t2)
ans.append((i, h))
ans.sort(key = lambda x : x[1] , reverse = True)
for i, h in ans:
print(i+1, "{0:.2f}".format(h))
```
| 102,336 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
n, t1, t2, k = list(map(int, input().split()))
rank = []
for seed_grower in range(n):
speed1, speed2 = list(map(int, input().split()))
var1 = speed1 * t1 * (1-(k/100)) + speed2 * t2
var2 = speed2 * t1 * (1-(k/100)) + speed1 * t2
total = max(var1, var2)
rank.append((seed_grower+1, total))
for seed_grower, plant_height in sorted(sorted(rank, key = lambda x : x[0]), key = lambda x : x[1], reverse = True):
print(seed_grower, "{:.2f}".format(plant_height))
```
| 102,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
n,t1,t2,k=map(int,input().split())
lst=[]
for i in range(n):
a,b=map(int,input().split())
lst.append((-max((a*t1*((100-k)/100)+b*t2),(b*t1*((100-k)/100)+a*t2)),i+1))
lst.sort()
for i in range(n):
print('%d %.2f'%(lst[i][1],-lst[i][0]))
```
| 102,338 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
# ip = open("testdata.txt", "r")
# def input():
# return ip.readline().strip()
n, t1, t2, k = map(int, input().split())
arr = [0]*n
redn = (100-k)/100
for i in range(n):
a, b = map(int, input().split())
res = max(t1*a*redn + t2*b, t1*b*redn + t2*a)
arr[i] = [i+1, res]
arr.sort(key=lambda x: (-x[1], x[0]))
for ele in arr:
print(ele[0], '%.2f'%ele[1])
```
| 102,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Tags: greedy, sortings
Correct Solution:
```
"""
Problem link:
Solution By Keshav Mishra
"""
from sys import stdin,stdout
from collections import Counter , deque
from queue import PriorityQueue
import math
helperConstants = True
helperUtilityFunctions = True
def input(): return stdin.readline().strip()
# def print(s): stdout.write(str(s)+'\n')
if helperConstants:
YES = 'YES'
NO = 'NO'
yes = 'yes'
no = 'no'
true = 'true'
false = 'false'
FALSE = 'FALSE'
TRUE = 'TRUE'
IMPOSSIBLE = 'IMPOSSIBLE'
POSSIBLE = 'POSSIBLE'
INF = float('inf')
if helperUtilityFunctions:
# Input utility functions
def getInputArray():
return list(map(int, input().split()))
def getIntegerInputs():
return map(int, input().split())
def getInputIntegerMatrix(n):
matrix = []
for i in range(n):
matrix.append(list(map(int,input().split())))
return matrix
def getInputStringMatrix(n):
matrix = []
for i in range(n):
matrix.append(input())
return matrix
# Output Utility functions
def outputIntegerMatrix(matrix):
for i in range(len(matrix)):
print(*matrix[i])
def outputStringMatrix(matrix):
for i in range(len(matrix)):
print(matrix[i])
def kickstartoutput(testcase,*outputs):
print('Case #%d:'%(testcase), *outputs)
def solve():
n, t1, t2, k = getIntegerInputs()
participants = []
k = 1 - k*0.01
for i in range(n):
a, b = getIntegerInputs()
ans1 = 0
ans2 = 0
ans1 += a*t1
ans1 = ans1*k
ans1 += b*t2
ans2 += b*t1
ans2 = ans2*k
ans2 += a*t2
ans = max(ans1,ans2)
participants.append({'index':i + 1, 'value':ans})
participants.sort(reverse = True, key = lambda x : x['value'])
for participant in participants:
print('%d %.2f'%(participant['index'], participant['value']))
if __name__ == '__main__':
solve()
```
| 102,340 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
#!/usr/bin/env python
import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math import (
acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits
def inp():
return(int(input()))
def inlist():
return(list(map(int, input().split())))
def instr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int, input().split()))
# region fastio
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)
def input(): return sys.stdin.readline().rstrip("\r\n")
# endregion
def valid(x, y, n, m):
if x <= n and x >= 1 and y <= m and y >= 1:
return True
return False
def findValidSteps(x, y, dx, dy, n, m):
l = 0
r = max(n, m)
res = 0
while l <= r:
mid = l + (r - l) // 2
tx, ty = x + dx*mid, y + dy*mid
if valid(tx, ty, n, m):
res = mid
l = mid + 1
else:
r = mid - 1
return res
n, t1, t2, k = invr()
k /= 100
res = []
for i in range(1, n+1):
a, b = invr()
res.append([i, max((t1*a - t1*a*k) + t2*b, (t1*b - t1*b*k)+t2*a)])
res = sorted(res, key=lambda d: d[1], reverse=True)
for r in res:
print(r[0], end=" ")
print("%.2f" % (r[1]))
```
Yes
| 102,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
I = lambda: map(int, input().split())
n, t1, t2, k = I()
res = []
for i in range(n):
a, b = I()
res.append((i, max((1-k/100)*a*t1+b*t2, (1-k/100)*b*t1+a*t2)))
for i,h in sorted(res, key=lambda x: (-x[1], x[0])):
print(i+1, f'{h:.2f}')
```
Yes
| 102,342 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
"""
██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗
██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗
██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║
██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║
██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝
"""
def sort(lst):
for i in range(len(lst)):
for j in range(len(lst)):
if lst[i][0] > lst[j][0]:
lst[i], lst[j] = lst[j], lst[i]
if lst[i][0] == lst[j][0]:
if lst[i][1] < lst[j][1]:
lst[i], lst[j] = lst[j], lst[i]
n, t1, t2, k = map(int, input().split())
table = []
for i in range(n):
a, b = map(int, input().split())
table += [[max(t1 * a * (100 - k) / 100 + t2 * b, t1 * b * (100 - k) / 100 + t2 * a), i + 1]]
sort(table)
for i in table:
print(i[1], "%.2f" %i[0])
```
Yes
| 102,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
from decimal import Decimal
n, t1, t2, k = map(int, input().strip().split())
l = []
i = 1
while n != 0:
x, y = map(int, input().strip().split())
p1 = x * t1 - (((x * t1) / 100) * k) + y * t2
p2 = y * t1 - (((y * t1) / 100) * k) + x * t2
g = max(p1, p2)
l.append([i,g])
i += 1
n -= 1
l.sort(key=lambda el: el[1], reverse=True)
for i in range(0, len(l)):
print('%d %.2f' %(l[i][0], l[i][1]))
```
Yes
| 102,344 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
import sys
def input(): return sys.stdin.readline().strip()
n, t1, t2, k = map(int, input().split())
speed = []
for i in range(n):
speed.append([int(i) for i in input().split()])
h = []
for i in range(n):
h.append([(t1*min(speed[i]))*(1-k/100)+t2*max(speed[i]), i+1])
h.sort(reverse=True)
i = 0
while i < n-1:
j = i+1
ind = [h[i][1]]
while j < n and h[i][0] == h[j][0]:
ind.append(h[j][1])
j += 1
ind.sort()
for k in range(i, j):
h[k][1] = ind[k-i]
i = j
for i in range(n):
print(h[i][1], "%.2f"%h[i][0])
```
No
| 102,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
from operator import itemgetter
n, t1, t2, k = [int(s) for s in input().split()]
a = []
b = []
for _ in range(n):
x, y = [int(s) for s in input().split()]
a.append(x)
b.append(y)
t_min = t1 if t1 * (100 - k) < 100 * t2 else t2
t_max = t1 + t2 - t_min
h = []
for i in range(n):
h.append((i, t_min * min(a[i], b[i]) * (100 - k) + 100 * t_max * max(a[i], b[i])))
h.sort(key=itemgetter(0), reverse=True)
h.sort(key=itemgetter(1))
for idx, height in reversed(h):
print(idx+1, "%.2f" % (height/100))
```
No
| 102,346 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
n,t1,t2,k=map(int,input().split())
arr=[]
for i in range(n):
curr=list(map(int,input().split()))
curr.sort()
a=curr[0]
b=curr[1]
arr.append([a,b])
ans = []
y=1
for i in arr:
a=i[0]
b=i[1]
curr= (a*(t1-(t1*(k/100)))+(b*t2))
x= "{:.2f}".format(curr)
ans.append([x,y])
y+=1
ans.sort(reverse=True,key= lambda arr:float(arr[0]))
for i in ans:
print (i[1] ,i[0])
```
No
| 102,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.
Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.
After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.
Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.
Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.
The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).
Input
The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.
Output
Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.
Examples
Input
2 3 3 50
2 4
4 2
Output
1 15.00
2 15.00
Input
4 1 1 1
544 397
280 101
280 101
693 970
Output
4 1656.07
1 937.03
2 379.99
3 379.99
Note
* First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.
Submitted Solution:
```
n, t1, t2, k = map(int, input().split())
t1 *= (100 - k) / 100
p = [map(int, input().split()) for i in range(n)]
if t1 < t2: l = [(t1 * a + t2 * b if a < b else t1 * b + t2 * a, - i) for i, (a, b) in enumerate(p, 1)]
else: l = [(t1 * a + t2 * b if a < b else t1 * b + t2 * a, - i) for i, (a, b) in enumerate(p, 1)]
l.sort(reverse = True)
print('\n'.join(str(- k) + ' ' + str(int(r)) + '.' + str(int(100 * (1 + r)) % 100) for r, k in l))
```
No
| 102,348 |
Provide a correct Python 3 solution for this coding contest problem.
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got some training set of documents. For each document you know its subject. The subject in this problem is an integer from 1 to 3. Each of these numbers has a physical meaning. For instance, all documents with subject 3 are about trade.
You can download the training set of documents at the following link: http://download4.abbyy.com/a2/X2RZ2ZWXBG5VYWAL61H76ZQM/train.zip. The archive contains three directories with names "1", "2", "3". Directory named "1" contains documents on the 1-st subject, directory "2" contains documents on the 2-nd subject, and directory "3" contains documents on the 3-rd subject. Each document corresponds to exactly one file from some directory.
All documents have the following format: the first line contains the document identifier, the second line contains the name of the document, all subsequent lines contain the text of the document. The document identifier is used to make installing the problem more convenient and has no useful information for the participants.
You need to write a program that should indicate the subject for a given document. It is guaranteed that all documents given as input to your program correspond to one of the three subjects of the training set.
Input
The first line contains integer id (0 ≤ id ≤ 106) — the document identifier. The second line contains the name of the document. The third and the subsequent lines contain the text of the document. It is guaranteed that the size of any given document will not exceed 10 kilobytes.
The tests for this problem are divided into 10 groups. Documents of groups 1 and 2 are taken from the training set, but their identifiers will not match the identifiers specified in the training set. Groups from the 3-rd to the 10-th are roughly sorted by the author in ascending order of difficulty (these groups contain documents which aren't present in the training set).
Output
Print an integer from 1 to 3, inclusive — the number of the subject the given document corresponds to.
Examples
"Correct Solution:
```
print('1')
```
| 102,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There have recently been elections in the zoo. Overall there were 7 main political parties: one of them is the Little Elephant Political Party, 6 other parties have less catchy names.
Political parties find their number in the ballot highly important. Overall there are m possible numbers: 1, 2, ..., m. Each of these 7 parties is going to be assigned in some way to exactly one number, at that, two distinct parties cannot receive the same number.
The Little Elephant Political Party members believe in the lucky digits 4 and 7. They want to evaluate their chances in the elections. For that, they need to find out, how many correct assignments are there, such that the number of lucky digits in the Little Elephant Political Party ballot number is strictly larger than the total number of lucky digits in the ballot numbers of 6 other parties.
Help the Little Elephant Political Party, calculate this number. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109 + 7).
Input
A single line contains a single positive integer m (7 ≤ m ≤ 109) — the number of possible numbers in the ballot.
Output
In a single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Examples
Input
7
Output
0
Input
8
Output
1440
Submitted Solution:
```
def fact(n):
if n==0:return 1
return n*fact(n-1)
n = int(input())
print((2*fact(n-2))%1000000007 if n>7 else 0)
```
No
| 102,350 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
"""
Author - Satwik Tiwari .
19th Jan , 2021 - Tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
# from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil,sqrt,log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O 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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def testcase(t):
for pp in range(t):
solve(pp)
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
y%=(p-1) #not so sure about this. used when y>p-1. if p is prime.
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
inf = pow(10,21)
mod = 10**9+7
#===============================================================================================
# code here ;))
def bucketsort(order, seq):
buckets = [0] * (max(seq) + 1)
for x in seq:
buckets[x] += 1
for i in range(len(buckets) - 1):
buckets[i + 1] += buckets[i]
new_order = [-1] * len(seq)
for i in reversed(order):
x = seq[i]
idx = buckets[x] = buckets[x] - 1
new_order[idx] = i
return new_order
def ordersort(order, seq, reverse=False):
bit = max(seq).bit_length() >> 1
mask = (1 << bit) - 1
order = bucketsort(order, [x & mask for x in seq])
order = bucketsort(order, [x >> bit for x in seq])
if reverse:
order.reverse()
return order
def long_ordersort(order, seq):
order = ordersort(order, [int(i & 0x7fffffff) for i in seq])
return ordersort(order, [int(i >> 31) for i in seq])
def multikey_ordersort(order, *seqs, sort=ordersort):
for i in reversed(range(len(seqs))):
order = sort(order, seqs[i])
return order
def solve(case):
x,y,n = sep()
mn = inf
for i in range(1,n+1):
temp = int((i*x)/y)
l = lcm(i,y)
# print(temp,i,y,l)
# if(temp > 0):
mn = min(mn,round(abs(x*(l//y) - temp*(l//i))/l,18))
# print(abs(x*(l//y) - temp*(l//i)),'==')
mn = min(mn,round(abs(x*(l//y) - (temp+1)*(l//i))/l,18))
# print(abs(x*(l//y) - (temp+1)*(l//i)))
# print(i,round(abs(x*(l//y) - temp*(l//i))/l,18),round(abs(x*(l//y) - (temp+1)*(l//i)),18))
ll = []
rr = []
for i in range(1,n+1):
temp = ((i*x)//y)
l = lcm(i,y)
if(round(abs(x*(l//y) - temp*(l//i))/l,18) == mn):
ll.append(i); rr.append(temp)
if(round(abs(x*(l//y) - (temp+1)*(l//i))/l,18) == mn):
ll.append(i); rr.append(temp+1)
order = multikey_ordersort(range(len(ll)),ll,rr)
# print(ll)
# print(rr)
print(rr[order[0]],end='/')
print(ll[order[0]])
testcase(1)
# testcase(int(inp()))
```
| 102,351 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
from fractions import Fraction
x,y,n=map(int,input().split())
ans=Fraction(x,y).limit_denominator(n)
num=ans.numerator
denom=ans.denominator
print (str(num) + '/' + str(denom))
```
| 102,352 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
from fractions import Fraction
x, y, n = input().split()
x = int(x)
y = int(y)
n = int(n)
if Fraction(x / y).limit_denominator(n) == 0:
print('0/1')
elif Fraction(x / y).limit_denominator(n) == int(Fraction(x, y).limit_denominator(n)):
print(str(Fraction(x, y).limit_denominator(n)) + '/1')
else:
if (2 * Fraction(x, y) - Fraction(x / y).limit_denominator(n)).denominator > y:
print(Fraction(x / y).limit_denominator(n))
else:
a= 2 * Fraction(x, y) - Fraction(x / y).limit_denominator(n)
print(str(a.numerator)+"/"+str(a.denominator))
```
| 102,353 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
class Fraction:
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, a):
return Fraction(self.x * a.y - a.x * self.y, self.y * a.y)
def __lt__(self, a):
return self.x * a.y < self.y * a.x
def __abs__(self):
if self.x < 0:
return Fraction(-self.x, self.y)
return self
def __str__(self):
return str(self.x) + '/' + str(self.y)
x, y, n = map(int, input().split())
f = Fraction(x, y)
dif = None
for i in range(1, n + 1):
m = x * i // y
for d in [m, m + 1]:
g = Fraction(d, i)
if dif is None or abs(f - g) < dif:
dif = abs(f - g)
ans = g
print(ans)
```
| 102,354 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
from fractions import Fraction as frac
a, b, n = map(int, input().split())
f = frac(a, b).limit_denominator(n)
print(str(f.numerator)+'/'+str(f.denominator))
```
| 102,355 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
"""
Author : co_devil Chirag Garg
Institute : JIIT
"""
from __future__ import division, print_function
from sys import stdin,stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
from fractions import Fraction
"""from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
else:
from builtins import str as __str__
str = lambda x=b'': x if type(x) is bytes else __str__(x).encode()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._buffer = BytesIO()
self._fd = file.fileno()
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):
return self._buffer.read() if self._buffer.tell() else os.read(self._fd, os.fstat(self._fd).st_size)
def readline(self):
while self.newlines == 0:
b, ptr = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)), self._buffer.tell()
self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
self.newlines += b.count(b'\n') + (not b)
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)
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b'\r\n')
def print(*args, **kwargs):
sep, file = kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop('end', b'\n'))
if kwargs.pop('flush', False):
file.flush()
"""
def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int,input().split())
def li(): return list(mi())
def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int,stdin.readline().split())
def fli(): return list(fmi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
'z': 25}
mod = 1000000007
dx, dy = [-1, 1, 0, 0], [0, 0, 1, -1]
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
res = 1
x %= p
while y > 0:
if y & 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
def gcd(x, y):
while y:
x, y = y, x % y
return x
# For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')
# Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def dfs(v, c):
if visited[v]:
if col[v] != c:
print('-1')
exit()
return
col[v] = c
visited[v] = 1
for i in graph[v]:
dfs(i, c ^ 1)
def bfs(d,v):
q=[]
q.append(v)
visited[v]=1
while len(q)!=0:
x=q[0]
q.pop(0)
for i in d[x]:
if visited[i]!=1:
visited[i]=1
q.append(i)
print(x)
def make_graph(e):
d={}
for i in range(e):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
if y not in d.keys():
d[y] = [x]
else:
d[y].append(x)
return d
def gr2(n):
d={}
for i in range(n):
x,y=mi()
if x not in d.keys():
d[x]=[y]
else:
d[x].append(y)
return d
def connected_components(graph):
seen = set()
def dfs(v):
vs = set([v])
component=[]
while vs:
v = vs.pop()
seen.add(v)
vs |= set(graph[v]) - seen
component.append(v)
return component
ans=[]
for v in graph:
if v not in seen:
d=dfs(v)
ans.append(d)
return ans
def primeFactors(n):
s=set()
while n % 2 == 0:
s.add(2)
n = n // 2
for i in range(3, int(sqrt(n)) + 1, 2):
while n % i == 0:
s.add(i)
n = n // i
if n > 2:
s.add(n)
return s
a,b,n=mi()
a=Fraction(a, b).limit_denominator(n)
print(a.numerator,a.denominator,sep='/')
```
| 102,356 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
import sys
s = input()
all = s.split()
ans = "lol"
n = int(all[2])
x = float(all[0])
y = float(all[1])
a = 0
b = 1
dif = x / y
for i in range(1, n + 1):
#print(str(a) + " : " + str(b) + " : " + str(dif))
na = int((x * i) / y)
if (dif > (abs(x * i - na * y) / (y * i))):
a = na
b = i
dif = abs(x * i - na * y) / (y * i)
na = na + 1
if (dif > (abs(x * i - na * y) / (y * i))):
a = na
b = i
dif = abs(x * i - na * y) / (y * i)
#print(str(a) + " : " + str(b) + " : " + str(dif))
ans = str(a) + "/" + str(b)
#print (a / b)
print(ans)
```
| 102,357 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Tags: brute force, implementation, two pointers
Correct Solution:
```
def gcd(a, b):
return gcd(b % a, a) if a else b
x, y, n = map(int, input().split())
d = gcd(x, y)
x, y = x // d, y // d
if n < y:
d = [min(i, y - i) for i in ((x * i) % y for i in range(0, n + 1))]
for i in range(n - 1, 0, -1):
if d[i] < d[n] and n * d[i] <= i * d[n]: n = i
print(str((x * n) // y + int(2 * ((x * n) % y) > y)) + '/' + str(n))
else: print(str(x) + '/' + str(y))
```
| 102,358 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x, y, n = map(int, input().split())
v = Fraction(x, y).limit_denominator(n)
print(v.numerator, '/', v.denominator, sep='')
```
Yes
| 102,359 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x,y,n=map(int,input().split())
f=Fraction(x,y).limit_denominator(n)
print(str(f.numerator)+'/'+str(f.denominator))
```
Yes
| 102,360 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
import math
x, y, n = map(int, input().split())
best = 0, 0
mingap = 10**9
eps = 1e-15
for i in range(1, n+1):
m = (i*x)/y
m1 = math.floor(m)
m2 = math.ceil(m)
gap1 = abs(x/y - m1/i)
gap2 = abs(x/y - m2/i)
if gap1<mingap-eps:
mingap = gap1
best = m1, i
if gap2<mingap-eps:
mingap = gap2
best = m2, i
print(*best, sep='/')
```
Yes
| 102,361 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x,y,n=map(int,input().split())
f=Fraction(x,y).limit_denominator(n)
if("/" not in str(f)):
print(str(f)+"/1")
else:
print(f)
```
Yes
| 102,362 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
def main():
pass
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")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l=[]
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
x,y,n=map(int,input().split())
v=x/y
ans=[100000000000,1]
ansv=1000000000
for b in range(1,n):
a1=int(v*b)
a2=a1+1
if(abs(a1/b-v)<ansv):
ansv=abs(a1/b-v)
ans[0],ans[1]=a1,b
elif(abs(a2/b)<ansv):
ansv=abs(a2/b-v)
ans[0],ans[1]=a2,b
print(str(ans[0])+"/"+str(ans[1]))
```
No
| 102,363 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x,y,n = map(int,input().split())
if y<=n:
b=Fraction(x,y)
print('{}/{}'.format(b.numerator,b.denominator))
else:
a=x/y
b=Fraction(a).limit_denominator(n)
print('{}/{}'.format(b.numerator,b.denominator))
```
No
| 102,364 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x, y, n = input().split()
x = int(x)
y = int(y)
n = int(n)
if Fraction(x, y) == int(Fraction(x, y)):
print(str(Fraction(x, y)) + '/1')
else:
print(Fraction(x/y).limit_denominator(n))
```
No
| 102,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction <image> whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value <image> is as minimal as possible.
If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.
Input
A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).
Output
Print the required fraction in the format "a/b" (without quotes).
Examples
Input
3 7 6
Output
2/5
Input
7 2 4
Output
7/2
Submitted Solution:
```
from fractions import Fraction
x, y, n = input().split()
x = int(x)
y = int(y)
n = int(n)
if Fraction(x / y).limit_denominator(n) ==0:
print('0/1')
elif Fraction(x / y).limit_denominator(n) == int(Fraction(x, y).limit_denominator(n)):
print(str(Fraction(x, y).limit_denominator(n)) + '/1')
else:
print(Fraction(x / y).limit_denominator(n))== int(Fraction(x, y))
```
No
| 102,366 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
import timeit
from math import floor,sqrt, gcd
def checkFloat(x):
check = x - floor(x)
if check == 0:
return True
return False
limit = int(input())
count = 0
# start = timeit.default_timer()
for n in range(1, int(sqrt(limit)) + 1):
for m in range(n + 1, int(sqrt(limit)) + 1):
if gcd(m,n) == 1 and not(m%2!=0 and n%2!=0):
k = 1
while (k * (m ** 2 + n ** 2)) <= limit:
count += 1
k += 1
# stop = timeit.default_timer()
# print("Time: ", (stop - start))
print(count)
```
| 102,367 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
from math import sqrt
n=int(input())
count=0
for i in range(1,n+1):
for j in range(i,n+1):
c = sqrt(i**2 + j**2)
if c == int(c) and c<=n:
count+=1
print(count)
```
| 102,368 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
import math
l = int(input())
ans = 0
for n in range(1, 10000):
for m in range(n + 1, 10000):
if m > l:
break
if math.gcd(n, m) != 1 or (n%2 and m%2):
continue
a = m**2 - n**2
b = 2 * m * n
c = m**2 + n**2
if c > l or b > l:
break
for k in range(1, 10000):
y = k * b
z = k * c
if y > l or z > l:
break
ans += 1
print(ans)
```
| 102,369 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
# https://codeforces.com/problemset/problem/304/A
"""
Count how many right angled triangles with side length a, b, c satisfies
1 <= a <= b <= c <= n
Researching Primitive PTs (PPT) we deduce that we just need to construct PPTs and count how far we can extend them.
Euclid's parametrisation:
a = p**2 - q**2, b = 2pq, c = p**2 + q**2
produces a PPT if m and n are coprime and both aren't odd
And we know that 1 <= c <=n so we need to check p from 1 to sqrt(n)
Also for a to be positive we require that p > q
"""
from math import sqrt, gcd
n = int(input())
count = 0
for p in range(1, int(sqrt(n))+1):
for q in range(1, p+1):
if gcd(p, q) != 1 or (p % 2 == 1 and q % 2 == 1):
continue
a, b, c = p**2 - q**2, 2*p*q, p**2 + q**2
if c <= n:
count += n//c
print(count)
```
| 102,370 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
n=int(input())
dic={}
for i in range(1,n+1):
dic[i*i]=0
ans=0
for i in range(1,n+1):
for j in range(i,n+1):
if (i*i)+(j*j) in dic:
ans+=1
print(ans)
```
| 102,371 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
from math import *
n = int(input())
s = 0
for i in range(5,n+1):
for j in range(1,i):
u = i*i - j*j
if(sqrt(u) == int(sqrt(u))):
s += 1
print(s//2)
```
| 102,372 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
# A. Pythagorean Theorem II
import math
n = int(input())
def solve(n):
pairs = 0
for i in range(1, n):
for j in range(i+1, n):
sm = math.sqrt(i ** 2 + j ** 2)
if sm == int(sm) and n >= sm:
pairs += 1
return pairs
print(solve(n))
```
| 102,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Tags: brute force, math
Correct Solution:
```
import sys
input = lambda: sys.stdin.readline().strip("\r\n")
import math
n = int(input())
ls = [i+1 for i in range(n)]
for i in range(n):
ls[i] = ls[i] ** 2
alpha = set(ls)
ans = 0
for i in range(n):
for j in range(i+1, n):
if ls[i] + ls[j] in alpha:
ans += 1
print(ans)
# def triplet(ls, n):
# for i in range(n):
# ls[i] = ls[i]**2
#
# cnt = 0
# for i in range(n-1, 1, -1):
# j = 0
# k = i - 1
# while j < k:
# if ls[j] + ls[k] == ls[i]:
# cnt += 1
# break
# else:
# if ls[j] + ls[k] < ls[i]:
# j += 1
# else:
# k -= 1
# return cnt
#
# print(triplet(ls, n))
```
| 102,374 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
from math import sqrt as sq
from math import gcd
ans = 0
n = int(input())
N = n * n
for i in range(2, int(sq(n + 1)) + 2):
for j in range(1 + i & 1, i, 2):
if i * i + j * j > N:
break
if gcd(i , j) == 1:
ans += int(n / (i * i + j * j))
print(ans)
```
Yes
| 102,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
import math
n=int(input())
ns=0
for c in range(1, n+1):
for a in range(1, c):
x=c*c
y=a*a
z=x-y
if int(math.sqrt(z))*int(math.sqrt(z))==z and int(math.sqrt(z))<=a:
ns+=1
print(ns)
```
Yes
| 102,376 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
from math import sqrt
n = int(input())
count = 0
for a in range(1, n+1):
for b in range(a, int(sqrt(n*n - a*a))+1):
c = sqrt(a*a + b*b)
if int(c) == c:
count += 1
print(count)
```
Yes
| 102,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
from math import sqrt
n = int(input())
ans = 0
for i in range(1, n):
for j in range(i, n):
k = int(sqrt(i * i + j * j))
if k > n:
break
if k * k == i * i + j * j:
ans += 1
print(ans)
```
Yes
| 102,378 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
i=int(input(""))
m=1
b=0
if i==10000:
print(12471)
elif i==9999:
print(12471)
else:
while m<i :
j=m+1
while j<i:
if pow(m**2+j**2,0.5).is_integer() and pow(m**2+j**2,0.5)<=i:
b+=1
elif pow(m**2+j**2,0.5)>i:
j=i
j+=1
m+=1
print(b)
```
No
| 102,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
import math
n = int(input())
ans = 0
map1 = {}
n2 = n*n
for i in range(3,n):
h = int(math.sqrt(n2-i*i))
for j in range(i+1,h+1):
c2 = i*i+j*j
if c2> n2:
break
c = int(math.sqrt(c2))
if c*c == c2:
ans+=1
if c in map1:
print(map1[c], i,j)
map1[c] = (i,j)
print(ans)
```
No
| 102,380 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
from math import sqrt
n = int(input())
a = 1
b = 1
count = 0
for a in range(1, n+1):
for b in range(1, n+1):
c = sqrt(a**2 + b**2)
cint = int(c)
if c==cint:
count += 1
print(int(count/2))
```
No
| 102,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
a2 + b2 = c2
where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides.
<image>
Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n.
Input
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Output
Print a single integer — the answer to the problem.
Examples
Input
5
Output
1
Input
74
Output
35
Submitted Solution:
```
from fractions import gcd
def coprime(a, b):
return gcd(a, b) == 1
l = int(input())
MAX = 999
s = set()
r = 0
for n in range(1, MAX):
for m in range(n, MAX):
if n % 2 == 1 and m % 2 == 1:
continue
if not coprime(n, m):
continue
for k in range(1, MAX):
c = k * (m * m + n * n)
if c > l:
break
else:
r += 1
s.add(c)
print(r)
```
No
| 102,382 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
n,m = map(int,input().split())
c=[]
for i in range(1,n+1):
c.append(i)
x=[]
for i in range(m):
a,b=map(int,input().split())
x.append(a)
x.append(b)
for i in c:
if i not in set(x):
break
ans=i
a=[]
for i in range(len(c)):
if c[i]!=ans:
temp=[]
temp.append(ans)
temp.append(c[i])
a.append(temp)
print(len(a))
for i in range(len(a)):
print(a[i][0],a[i][1])
```
| 102,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
import sys
sys.setrecursionlimit(10000)
n, m = [int(x) for x in sys.stdin.readline().strip().split()]
index = 1
s = set(range(1,n+1))
for i in range(m):
k = {int(x) for x in sys.stdin.readline().strip().split()}
s=s-k
l=list(s)[0]
print(n-1)
for i in range(1,n+1):
if i!=l:
print(l,i)
```
| 102,384 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
n, m = map(int, input().split())
t = []
for i in range(m):
t += input().split()
t = set(t)
i = 1
while str(i) in t:
i += 1
print(n-1)
j = 1
while j < i:
print(i, j)
j+=1
j = i+1
while j < n + 1:
print(i, j)
j+=1
```
| 102,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
n,m = map(int,input().split())
arr = [0] * 1005
i = 1
for k in range(m):
a,b = map(int,input().split())
arr[a] = 1
arr[b] = 1
for i in range(1,n+1):
if arr[i] == 0:
break
print(n-1)
for j in range(1,n+1):
if i != j:
print(i,j)
```
| 102,386 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
n,m=map(int,input().split())
l=[]
for i in range(n):
l.append(0)
for t in range(m):
a,b=map(int,input().split())
l[a-1]=-1
l[b-1]=-1
for y in range(len(l)):
if l[y]!=-1:
o=y
break
print(n-1)
for t in range(n):
if t!=o:
print (t+1,o+1)
```
| 102,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
n,m=[int(x) for x in input().split()]
forbidden=set()
for i in range(m):
a,b=[int(x) for x in input().split()]
forbidden.add(a)
forbidden.add(b)
for i in range(1,n+1):
if i not in forbidden:
print(n-1)
for j in range(1,n+1):
if j!=i:
print(j,i)
exit()
```
| 102,388 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
def roadConstruction():
n,m=map(int,input().split())
lst=[[0 for i in range(n)] for j in range(n)]
for i in range(m):
u,v=map(int,input().split())
lst[u-1][v-1]=-1
lst[v-1][u-1]=-1
flag=False
# The idea is very simple as m < n/2(given) then there is atleast one node
#which will not be incident on any edge
# So the idea is to make a star graph
#Link : https://en.wikipedia.org/wiki/Star_(graph_theory)
#Find the city from which we can build a road and let's make it as a central (node)city
#then connect it to all other cities(nodes)
for i in range(n):
if(sum(lst[i])==0):
flag=True
centralNode=i
if(flag):
print(n-1)
for i in range(n):
if(centralNode!=i):print(i+1,centralNode+1)
roadConstruction()
```
| 102,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Tags: constructive algorithms, graphs
Correct Solution:
```
from sys import stdin,stdout
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, m = iia()
d1 = set()
for i in range(m):
a, b = iia()
d1.add(a)
d1.add(b)
cur = (set(list(range(1, n + 1))) - d1).pop()
print(n-1)
for i in range(1, n + 1):
if i != cur:
print(cur,i)
```
| 102,390 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
n,m=map(int,input().split())
ls=[[0 for i in range(n)] for j in range(n)]
for i in range(m):
a,b=map(int,input().split())
ls[a-1][b-1]=-1
ls[b-1][a-1]=-1
flag=False
for i in range(n):
if(sum(ls[i])==0):
flag=True
k=i
if(flag):
print(n-1)
for i in range(n):
if(k!=i):print(i+1,k+1)
```
Yes
| 102,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
n,m = map(int,input().split())
lis=[]
con=[0]*(1001)
ans=0
for i in range(m):
a,b = map(int,input().split())
lis.append([a,b])
con[a]+=1
con[b]+=1
for i in range(1,n+1):
if con[i]==0:
ans=i
break
print(n-1)
for i in range(1,n+1):
if i!=ans:
print(ans,i)
```
Yes
| 102,392 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
n,m=map(int,input().split())
l=[0]*n
for i in range(m):
a,b=map(int,input().split())
l[a-1]=1
l[b-1]=1
for i in range(n):
if l[i]==0:
k=i
break
print(n-1)
for i in range(n):
if i!=k:
print(k+1,i+1)
```
Yes
| 102,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
# Dejwo to ziomal
n,m = map(int,input().split())
bad_roads = []
for i in range(m):
a,b = map(int,input().split())
bad_roads.append(a)
bad_roads.append(b)
tmp = [ i not in bad_roads for i in range(1,n+1)]
root = tmp.index(True) + 1
print(n-1)
for i in range(1,n+1):
if i != root:
print(root,i)
```
Yes
| 102,394 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
n,m = map(int,input().split())
visited = [False] * n #0 based indexing
for _ in range(m):
a,b = map(int,input().split())
visited[a-1] = True
visited[b-1] = True
for i in range(n):
if(visited[i]==False):
Ans = [i+1]
break
List = list(set([x for x in range(1,n+1)]) - set(Ans))
for i in List:
print(i,Ans[0])
```
No
| 102,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
n,m = map(int,input().split())
roads = [False] * (n+1)
for i in range(m):
a,b = map(int,input().split())
roads[a] = True
roads[b] = True
center = 0
for i in range(1,n+1):
if(roads[i] == False):
center = i
break
for i in range(1, n+1):
if (i != center):
print("%d %d" %(center, i))
```
No
| 102,396 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
n,m = map(int,input().split())
if m==0:
print(n-1)
for i in range(1,1000):
print(1000,i)
else:
cond = []
for i in range(m):
ai,bi = map(int,input().split())
cond.append(ai)
cond.append(bi)
for j in range(1,n+1):
if j not in set(cond):
break
a=j
print(n-1)
for j in range(1,n+1):
if j!=a:
print(a,j)
```
No
| 102,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities.
Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible.
Input
The first line consists of two integers n and m <image>.
Then m lines follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that it is not possible to construct a road connecting cities ai and bi. Consider the cities are numbered from 1 to n.
It is guaranteed that every pair of cities will appear at most once in the input.
Output
You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that a road should be constructed between cities ai and bi.
If there are several solutions, you may print any of them.
Examples
Input
4 1
1 3
Output
3
1 2
4 2
2 3
Note
This is one possible solution of the example:
<image>
These are examples of wrong solutions:
<image> The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. <image> The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. <image> Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 3.
Submitted Solution:
```
from collections import defaultdict
n, m = map(int, input().split())
banned_edges = defaultdict(list)
for _ in range(m):
road = input().split()
a, b = int(road[0]), int(road[1])
banned_edges[a].append(b)
banned_edges[b].append(a)
center = 1
result = []
for v in range(2, n+1):
if center in banned_edges[v]:
for u in range(2, n+1):
if u == v:
continue
if v not in banned_edges[u] and u not in banned_edges[center]:
result.append('{} {}'.format(v, center))
break
else:
result.append('{} {}'.format(v, center))
print(len(result))
print('\n'.join(result))
```
No
| 102,398 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday.
Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds.
Jeff can multiply some numbers of the sequence p by -1. At that, he wants the number of inversions in the sequence to be minimum. Help Jeff and find the minimum number of inversions he manages to get.
Input
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
Output
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
Examples
Input
2
2 1
Output
0
Input
9
-2 0 -1 0 -1 2 1 0 -1
Output
6
Tags: greedy
Correct Solution:
```
n = int(input())
inp = input()
seq = inp.split(' ')
seq = [ abs(int(x)) for x in seq ]
Max = max(seq)
nxt = [0] * n
cnt = [0] * n
pos = [n] * (Max+1)
for i in range(n-1, -1, -1):
nxt[i] = pos[seq[i]]
pos[seq[i]] = i
for i in range(0, Max+1):
j = pos[i]
while(j<n):
front = sum(cnt[0:j])
back = sum(cnt[j+1:n])
if(front < back):
seq[j] = 0 - seq[j]
j = nxt[j]
j = pos[i]
while(j < n):
cnt[j] = 1
j = nxt[j]
#for i in range(0, n-1):
# print(seq[i], sep=' ')
#print(seq[n-1])
inv = 0
for i in range(len(seq)):
for j in range(i+1, len(seq)):
if(seq[i] > seq[j]):
inv += 1
print(inv)
```
| 102,399 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.