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. Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not less than L coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. Input The only line of input contains 4 integers N, M, K, L (1 ≀ K ≀ N ≀ 10^{18}; 1 ≀ M, L ≀ 10^{18}) β€” quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. Output Print one number β€” minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). Examples Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 Note In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. Submitted Solution: ``` n,m,k,l=map(int,input().split()) a=(l+k)//m + ((l+k)%m!=0) if(n>=(l+k)and n>=m and n>=(a*m)): print((l+k)//m + ((l+k)%m!=0)) else: print(-1) ``` Yes
95,300
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not less than L coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. Input The only line of input contains 4 integers N, M, K, L (1 ≀ K ≀ N ≀ 10^{18}; 1 ≀ M, L ≀ 10^{18}) β€” quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. Output Print one number β€” minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). Examples Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 Note In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. Submitted Solution: ``` n, m, k, L = map(int, input().split()) l = 0 r = n // m + 1 while r - l > 1: med = (r + l) // 2 if med*m - k >= L: r = med else: l = med if l != n // m: print(r) else: print("-1") ``` Yes
95,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not less than L coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. Input The only line of input contains 4 integers N, M, K, L (1 ≀ K ≀ N ≀ 10^{18}; 1 ≀ M, L ≀ 10^{18}) β€” quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. Output Print one number β€” minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). Examples Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 Note In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. Submitted Solution: ``` def r(a: int): if a % 1 > 0.000000000000000001: a += 1 return int(a) n, m, k, L = map(int, input().split()) if L + k > n or m * r((L + k) / m) > n or m > n: print(-1) exit() print(r((L + k) / m)) ``` No
95,302
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not less than L coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. Input The only line of input contains 4 integers N, M, K, L (1 ≀ K ≀ N ≀ 10^{18}; 1 ≀ M, L ≀ 10^{18}) β€” quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. Output Print one number β€” minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). Examples Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 Note In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. Submitted Solution: ``` n, m, k, l = (int(x) for x in input().split()) if l+k > n or m > n or m<1 or n<1 or k<1 or l<1: print(-1) else: print((l+k+m-1)//m) ``` No
95,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not less than L coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. Input The only line of input contains 4 integers N, M, K, L (1 ≀ K ≀ N ≀ 10^{18}; 1 ≀ M, L ≀ 10^{18}) β€” quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. Output Print one number β€” minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). Examples Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 Note In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. Submitted Solution: ``` from math import * # t=int(input()) n,m,k,l=map(int,input().split(" ")) diff=n-m if(diff<0): print(-1) exit() diff=m diff-=k if(diff<l): print(-1) exit() print(int(ceil(l/diff))) ``` No
95,304
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan is collecting coins. There are only N different collectible coins, Ivan has K of them. He will be celebrating his birthday soon, so all his M freinds decided to gift him coins. They all agreed to three terms: * Everyone must gift as many coins as others. * All coins given to Ivan must be different. * Not less than L coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. Input The only line of input contains 4 integers N, M, K, L (1 ≀ K ≀ N ≀ 10^{18}; 1 ≀ M, L ≀ 10^{18}) β€” quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. Output Print one number β€” minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). Examples Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 Note In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. Submitted Solution: ``` import math n,m,k,l=map(int,input().split()) if m>n: print(-1) else: new=math.ceil((l+k)/m) if new*m >n: print(-1) else: print(new) ``` No
95,305
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Tags: combinatorics, dp, math, probabilities Correct Solution: ``` n,m,h=map(int,input().split()) s=list(map(int,input().split())) a=1 S=sum(s) for i in range(S-s[h-1]+1,S): a*=(i-n+1)/i print(-1 if S<n else 1-a) # Made By Mostafa_Khaled ```
95,306
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Tags: combinatorics, dp, math, probabilities Correct Solution: ``` """ atleast 1 =1- zero of them (only wafa) """ n,m,h=map(int,input().split()) M=[int(x) for x in input().split()] M=[0]+M tot=sum(M) if tot<n: print(-1) else: tot-=1 M[h]-=1 ans=1.0 others=tot-M[h] for i in range(0,n-1): ans*=(others-i)/(tot-i)#if i is in ..wt abt others print(1.0-ans) ```
95,307
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Tags: combinatorics, dp, math, probabilities Correct Solution: ``` n,m,h = map(int,input().split()) lis = list(map(int,input().split())) if sum(lis)<n: print(-1) else: s=sum(lis) ans=1 for i in range(n-1): ans*=(s-lis[h-1]-i) ans/=(s-i-1) print(1-ans) ```
95,308
Provide tags and a correct Python 3 solution for this coding contest problem. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Tags: combinatorics, dp, math, probabilities Correct Solution: ``` import sys import math n,m,h = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] total = sum(arr) if (total < n): print ("-1") sys.exit() total1 = total - arr[h-1] rem = total - total1-1 total = total - 1 ans = 1 ''' #start = total - (n-1) #print (start) x = start #print (rem) for i in range(rem-1): start = float(float(start) * float(x-(i+1))) print (start) ''' for i in range(n-1): x = float(total1 - i) y = float(total - i) #print (i,x,y) ans = float(ans * float(x/y)) #print (ans) ans = float(ans) print("{0:.10f}".format(round(1-ans,10))) ```
95,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` def ncr(nn,rr): ans=1 if rr>nn: return 0 for i in range(rr): p=nn-i q=i+1 ans *=(p/q) return ans n,m,h = map(int,input().split()) lis = list(map(int,input().split())) if sum(lis)<n: print(-1) else: s=sum(lis) a=ncr(s-1,n-1) b=ncr(s-lis[h-1],n-1) print(1-b/a) ``` No
95,310
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` def ncr(nn,rr): ans=1 if rr>nn: return 0 for i in range(rr): p=nn-i q=i+1 ans *=(p/q) return ans n,m,h = map(int,input().split()) lis = list(map(int,input().split())) if sum(lis)<n: print(-1) else: s=sum(lis) if h==766: print("0.128032") else: a=ncr(s-1,n-1) b=ncr(s-lis[h-1],n-1) print(1-b/a) ``` No
95,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of n players, all of which are GUC students. However, the team might have players belonging to different departments. There are m departments in GUC, numbered from 1 to m. Herr Wafa's department has number h. For each department i, Herr Wafa knows number si β€” how many students who play basketball belong to this department. Herr Wafa was also able to guarantee a spot on the team, using his special powers. But since he hates floating-point numbers, he needs your help at finding the probability that he will have at least one teammate belonging to his department. Note that every possible team containing Herr Wafa is equally probable. Consider all the students different from each other. Input The first line contains three integers n, m and h (1 ≀ n ≀ 100, 1 ≀ m ≀ 1000, 1 ≀ h ≀ m) β€” the number of players on the team, the number of departments in GUC and Herr Wafa's department, correspondingly. The second line contains a single-space-separated list of m integers si (1 ≀ si ≀ 100), denoting the number of students in the i-th department. Note that sh includes Herr Wafa. Output Print the probability that Herr Wafa will have at least one teammate from his department. If there is not enough basketball players in GUC to participate in ABC, print -1. The answer will be accepted if it has absolute or relative error not exceeding 10 - 6. Examples Input 3 2 1 2 1 Output 1 Input 3 2 1 1 1 Output -1 Input 3 2 1 2 2 Output 0.666667 Note In the first example all 3 players (2 from department 1 and 1 from department 2) must be chosen for the team. Both players from Wafa's departments will be chosen, so he's guaranteed to have a teammate from his department. In the second example, there are not enough players. In the third example, there are three possibilities to compose the team containing Herr Wafa. In two of them the other player from Herr Wafa's department is part of the team. Submitted Solution: ``` import sys import operator as op from functools import reduce import math def ncr(n,r): if (n < r): return 0 if (r > n /2): r = n- r ans = 1 for x in range(1,r+1): ans = (ans * (n-r+x)) ans = (ans/x) return ans n,m,h = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] total = sum(arr) if (total < n): print ("-1") sys.exit() total1 = total - arr[h-1] ans1 = float(ncr(total1,n-1)) ans2 = float(ncr(total-1,n-1)) #print (total1,ans1,ans2) ans = float(1 - (ans1/ans2)) print("{0:.10f}".format(round(ans,10))) ``` No
95,312
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fedya and Sasha are friends, that's why Sasha knows everything about Fedya. Fedya keeps his patience in an infinitely large bowl. But, unlike the bowl, Fedya's patience isn't infinite, that is why let v be the number of liters of Fedya's patience, and, as soon as v becomes equal to 0, the bowl will burst immediately. There is one tap in the bowl which pumps s liters of patience per second. Notice that s can be negative, in that case, the tap pumps out the patience. Sasha can do different things, so he is able to change the tap's speed. All actions that Sasha does can be represented as q queries. There are three types of queries: 1. "1 t s" β€” add a new event, means that starting from the t-th second the tap's speed will be equal to s. 2. "2 t" β€” delete the event which happens at the t-th second. It is guaranteed that such event exists. 3. "3 l r v" β€” Sasha wonders: if you take all the events for which l ≀ t ≀ r and simulate changes of Fedya's patience from the very beginning of the l-th second till the very beginning of the r-th second inclusive (the initial volume of patience, at the beginning of the l-th second, equals to v liters) then when will be the moment when the bowl will burst. If that does not happen, then the answer will be -1. Since Sasha does not want to check what will happen when Fedya's patience ends, and he has already come up with the queries, he is asking you to help him and find the answer for each query of the 3-rd type. It is guaranteed that at any moment of time, there won't be two events which happen at the same second. Input The first line contans one integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the next q lines have one of the following formats: * 1 t s (1 ≀ t ≀ 10^9, -10^9 ≀ s ≀ 10^9), means that a new event is added, which means that starting from the t-th second the tap's speed will be equal to s. * 2 t (1 ≀ t ≀ 10^9), means that the event which happens at the t-th second must be deleted. Guaranteed that such exists. * 3 l r v (1 ≀ l ≀ r ≀ 10^9, 0 ≀ v ≀ 10^9), means that you should simulate the process from the very beginning of the l-th second till the very beginning of the r-th second inclusive, and to say when will the bowl burst. It is guaranteed that t, s, l, r, v in all the queries are integers. Also, it is guaranteed that there is at least one query of the 3-rd type, and there won't be a query of the 1-st type with such t, that there already exists an event which happens at that second t. Output For each query of the 3-rd type, print in a new line the moment when the bowl will burst or print -1 if it won't happen. Your answer will be considered correct if it's absolute or relative error does not exceed 10^{-6}. Formally, let your answer be a, and the jury's answer be b. Your answer is accepted if and only if \frac{|a - b|}{max{(1, |b|)}} ≀ 10^{-6}. Examples Input 6 1 2 1 1 4 -3 3 1 6 1 3 1 6 3 3 1 6 4 3 1 6 5 Output 5 5.666667 6 -1 Input 10 1 2 2 1 4 4 1 7 -10 3 2 4 1 3 5 6 0 3 1 15 1 2 4 3 1 15 1 1 8 1 3 1 15 1 Output -1 5 8.7 8.1 -1 Input 5 1 1000 9999999 1 2000 -9999 3 1000 2000 0 2 1000 3 1000 2002 1 Output 1000 2000.0001 Note In the first example all the queries of the 3-rd type cover all the events, it's simulation is following: <image> Submitted Solution: ``` from math import fabs q = int(input()) speed_change = [] def add(t, s): global speed_change speed_change.append((t, s)) def remove(t): global speed_change for speed in speed_change: if speed[0] == t: speed_change.remove(speed) def check(l, r, v): global speed_change speed = 0 for time in range(l, r): counter = 0 for s in speed_change: if s[0] == time: speed = s[1] break for j in range(int(fabs(speed))): if speed < 0: v -= 1 else: v += 1 counter += 1/fabs(speed) if v == 0: return time + counter else: return -1 for i in range(q): command = [int(i) for i in input().split()] if command[0] == 1: add(command[1], command[2]) elif command[0] == 2: for j in speed_change: if j[0] == command[1]: speed_change.remove(j) elif command[0] == 3: number = check(command[1], command[2], command[3]) print(int(number) if number%1 == 0 else number) ``` No
95,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come up with a field for the upcoming game. The field for this game is a directed graph consisting of two parts. The first part is a road along the coast of the lake which is a cycle of c vertices. The second part is a path from home to the lake which is a chain of t vertices, and there is an edge from the last vertex of this chain to the vertex of the road along the coast which has the most beautiful view of the lake, also known as the finish vertex. Misha decided to keep the field secret, so nobody knows neither t nor c. <image> Note that each vertex of the field has exactly one outgoing edge and all the vertices except the home vertex and the finish vertex have exactly one ingoing edge. The home vertex has no incoming edges, the finish vertex has two incoming edges. At the beginning of the game pieces of all the ten players, indexed with consecutive integers from 0 to 9, are at the home vertex. After that on each turn some of the players can ask Misha to simultaneously move their pieces along the corresponding edges. Misha will not answer more than q such queries. After each move Misha will tell players whose pieces are at the same vertices and whose pieces are at different vertices. The goal of the game is to move all the pieces to the finish vertex. Misha's friends have no idea how to win in such a game without knowledge of c, t and q, but luckily they are your friends. Help them: coordinate their actions to win the game. Misha has drawn such a field that 1 ≀ t, c, (t+c) ≀ 1000 and q = 3 β‹… (t+c). Input There is no input β€” go to the interaction part straight away. Output After all friends gather at the finish vertex, print "done" and terminate your program. Interaction To give a command to move the friends, print "next" and then space-separated indices of the friends you want to move. For example, to give the command to move the friends with indices 0, 2, 5 and 9 print "next 0 2 5 9". At each turn, you must move at least one of your friends. As an answer, first read an integer k, and then 10 digits divided into k space-separated groups. The friends that correspond to the indices in the same group are in the same vertex. The friends that correspond to indices in different groups are in different vertices. The indices in each group follow in ascending order. For example, the answer "2 05 12346789" means that the friends with indices 0 and 5 are in one vertex, and all other friends are in the same but different vertex. The answer "4 01 567 234 89" means that Misha's friends are in four different vertices: the friends with indices 0 and 1 are in the first, the friends with indices 5, 6 and 7 are in the second, the friends with indices 2, 3 and 4 are in the third, and the friends with indices 8 and 9 are in the fourth. After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Answer "stop" instead of a valid one means that you made an invalid query. Exit immediately after receiving "stop" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream. Hacks In order to hack, print two integers t and c in a single line (1 ≀ t, c, (t+c) ≀ 1000). Example Input 2 05 12346789 3 246789 135 0 3 246789 0 135 3 246789 0 135 2 135 0246789 1 0123456789 Output next 0 5 next 0 1 3 next 2 3 0 1 4 5 6 7 8 9 next 9 8 7 6 5 4 3 2 1 0 next 0 1 3 5 next 1 3 5 done Note In the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear. In the example, the friends move as follows: <image> Submitted Solution: ``` # Codeforces 1137D # Credits: https://codeforces.com/contest/1137/submission/51156338 FAST = 0 SLOW = 1 def move(who): print('next ' + ' '.join(map(str, who)), flush=True) p = input().split()[1:] r = [0 for _ in range(10)] for x in range(len(p)): for z in p[x]: r[int(z)] = x return r for x in range(0, 1000000): if x % 2 == 0: r = move([FAST, SLOW]) else: r = move([FAST]) if x > 0 and r[FAST] == r[SLOW]: break while not all(x == r[0] for x in r): r = move(range(0, 10)) print('done') ``` No
95,314
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come up with a field for the upcoming game. The field for this game is a directed graph consisting of two parts. The first part is a road along the coast of the lake which is a cycle of c vertices. The second part is a path from home to the lake which is a chain of t vertices, and there is an edge from the last vertex of this chain to the vertex of the road along the coast which has the most beautiful view of the lake, also known as the finish vertex. Misha decided to keep the field secret, so nobody knows neither t nor c. <image> Note that each vertex of the field has exactly one outgoing edge and all the vertices except the home vertex and the finish vertex have exactly one ingoing edge. The home vertex has no incoming edges, the finish vertex has two incoming edges. At the beginning of the game pieces of all the ten players, indexed with consecutive integers from 0 to 9, are at the home vertex. After that on each turn some of the players can ask Misha to simultaneously move their pieces along the corresponding edges. Misha will not answer more than q such queries. After each move Misha will tell players whose pieces are at the same vertices and whose pieces are at different vertices. The goal of the game is to move all the pieces to the finish vertex. Misha's friends have no idea how to win in such a game without knowledge of c, t and q, but luckily they are your friends. Help them: coordinate their actions to win the game. Misha has drawn such a field that 1 ≀ t, c, (t+c) ≀ 1000 and q = 3 β‹… (t+c). Input There is no input β€” go to the interaction part straight away. Output After all friends gather at the finish vertex, print "done" and terminate your program. Interaction To give a command to move the friends, print "next" and then space-separated indices of the friends you want to move. For example, to give the command to move the friends with indices 0, 2, 5 and 9 print "next 0 2 5 9". At each turn, you must move at least one of your friends. As an answer, first read an integer k, and then 10 digits divided into k space-separated groups. The friends that correspond to the indices in the same group are in the same vertex. The friends that correspond to indices in different groups are in different vertices. The indices in each group follow in ascending order. For example, the answer "2 05 12346789" means that the friends with indices 0 and 5 are in one vertex, and all other friends are in the same but different vertex. The answer "4 01 567 234 89" means that Misha's friends are in four different vertices: the friends with indices 0 and 1 are in the first, the friends with indices 5, 6 and 7 are in the second, the friends with indices 2, 3 and 4 are in the third, and the friends with indices 8 and 9 are in the fourth. After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Answer "stop" instead of a valid one means that you made an invalid query. Exit immediately after receiving "stop" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream. Hacks In order to hack, print two integers t and c in a single line (1 ≀ t, c, (t+c) ≀ 1000). Example Input 2 05 12346789 3 246789 135 0 3 246789 0 135 3 246789 0 135 2 135 0246789 1 0123456789 Output next 0 5 next 0 1 3 next 2 3 0 1 4 5 6 7 8 9 next 9 8 7 6 5 4 3 2 1 0 next 0 1 3 5 next 1 3 5 done Note In the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear. In the example, the friends move as follows: <image> Submitted Solution: ``` def move(s): print('next', s) return int(input().split())[0] while 1: move('0 1') if move('1') == 2: break while 1: if move('0 1 2 3 4 5 6 7 8 9') == 1: break print('done') ``` No
95,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come up with a field for the upcoming game. The field for this game is a directed graph consisting of two parts. The first part is a road along the coast of the lake which is a cycle of c vertices. The second part is a path from home to the lake which is a chain of t vertices, and there is an edge from the last vertex of this chain to the vertex of the road along the coast which has the most beautiful view of the lake, also known as the finish vertex. Misha decided to keep the field secret, so nobody knows neither t nor c. <image> Note that each vertex of the field has exactly one outgoing edge and all the vertices except the home vertex and the finish vertex have exactly one ingoing edge. The home vertex has no incoming edges, the finish vertex has two incoming edges. At the beginning of the game pieces of all the ten players, indexed with consecutive integers from 0 to 9, are at the home vertex. After that on each turn some of the players can ask Misha to simultaneously move their pieces along the corresponding edges. Misha will not answer more than q such queries. After each move Misha will tell players whose pieces are at the same vertices and whose pieces are at different vertices. The goal of the game is to move all the pieces to the finish vertex. Misha's friends have no idea how to win in such a game without knowledge of c, t and q, but luckily they are your friends. Help them: coordinate their actions to win the game. Misha has drawn such a field that 1 ≀ t, c, (t+c) ≀ 1000 and q = 3 β‹… (t+c). Input There is no input β€” go to the interaction part straight away. Output After all friends gather at the finish vertex, print "done" and terminate your program. Interaction To give a command to move the friends, print "next" and then space-separated indices of the friends you want to move. For example, to give the command to move the friends with indices 0, 2, 5 and 9 print "next 0 2 5 9". At each turn, you must move at least one of your friends. As an answer, first read an integer k, and then 10 digits divided into k space-separated groups. The friends that correspond to the indices in the same group are in the same vertex. The friends that correspond to indices in different groups are in different vertices. The indices in each group follow in ascending order. For example, the answer "2 05 12346789" means that the friends with indices 0 and 5 are in one vertex, and all other friends are in the same but different vertex. The answer "4 01 567 234 89" means that Misha's friends are in four different vertices: the friends with indices 0 and 1 are in the first, the friends with indices 5, 6 and 7 are in the second, the friends with indices 2, 3 and 4 are in the third, and the friends with indices 8 and 9 are in the fourth. After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Answer "stop" instead of a valid one means that you made an invalid query. Exit immediately after receiving "stop" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream. Hacks In order to hack, print two integers t and c in a single line (1 ≀ t, c, (t+c) ≀ 1000). Example Input 2 05 12346789 3 246789 135 0 3 246789 0 135 3 246789 0 135 2 135 0246789 1 0123456789 Output next 0 5 next 0 1 3 next 2 3 0 1 4 5 6 7 8 9 next 9 8 7 6 5 4 3 2 1 0 next 0 1 3 5 next 1 3 5 done Note In the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear. In the example, the friends move as follows: <image> Submitted Solution: ``` import sys def step(l): print("next", end = '') for n in l: print(' ', n, end = '') print('') sys.stdout.flush() if __name__== "__main__": l1 = [0, 1] l2 = [1] l3 = [2, 3, 4, 5, 6, 7, 8, 9] seEncontrou = False while not seEncontrou: step(l1) step(l2) ent = [] while(len(ent) == 0): ent = input().split() for lx in ent[1:]: zero = False one = False for num in lx: if num == '0': zero = True if num == '1': one = True if zero and one: seEncontrou = True seEncontrou = False while not seEncontrou: step(l1) step(l3) ent = [] while(len(ent) == 0): ent = input().split() for lx in ent[1:]: zero = False two = False for num in lx: if num == '0': zero = True if num == '2': two = True if zero and two: seEncontrou = True print("done") sys.stdout.flush() ``` No
95,316
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come up with a field for the upcoming game. The field for this game is a directed graph consisting of two parts. The first part is a road along the coast of the lake which is a cycle of c vertices. The second part is a path from home to the lake which is a chain of t vertices, and there is an edge from the last vertex of this chain to the vertex of the road along the coast which has the most beautiful view of the lake, also known as the finish vertex. Misha decided to keep the field secret, so nobody knows neither t nor c. <image> Note that each vertex of the field has exactly one outgoing edge and all the vertices except the home vertex and the finish vertex have exactly one ingoing edge. The home vertex has no incoming edges, the finish vertex has two incoming edges. At the beginning of the game pieces of all the ten players, indexed with consecutive integers from 0 to 9, are at the home vertex. After that on each turn some of the players can ask Misha to simultaneously move their pieces along the corresponding edges. Misha will not answer more than q such queries. After each move Misha will tell players whose pieces are at the same vertices and whose pieces are at different vertices. The goal of the game is to move all the pieces to the finish vertex. Misha's friends have no idea how to win in such a game without knowledge of c, t and q, but luckily they are your friends. Help them: coordinate their actions to win the game. Misha has drawn such a field that 1 ≀ t, c, (t+c) ≀ 1000 and q = 3 β‹… (t+c). Input There is no input β€” go to the interaction part straight away. Output After all friends gather at the finish vertex, print "done" and terminate your program. Interaction To give a command to move the friends, print "next" and then space-separated indices of the friends you want to move. For example, to give the command to move the friends with indices 0, 2, 5 and 9 print "next 0 2 5 9". At each turn, you must move at least one of your friends. As an answer, first read an integer k, and then 10 digits divided into k space-separated groups. The friends that correspond to the indices in the same group are in the same vertex. The friends that correspond to indices in different groups are in different vertices. The indices in each group follow in ascending order. For example, the answer "2 05 12346789" means that the friends with indices 0 and 5 are in one vertex, and all other friends are in the same but different vertex. The answer "4 01 567 234 89" means that Misha's friends are in four different vertices: the friends with indices 0 and 1 are in the first, the friends with indices 5, 6 and 7 are in the second, the friends with indices 2, 3 and 4 are in the third, and the friends with indices 8 and 9 are in the fourth. After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Answer "stop" instead of a valid one means that you made an invalid query. Exit immediately after receiving "stop" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream. Hacks In order to hack, print two integers t and c in a single line (1 ≀ t, c, (t+c) ≀ 1000). Example Input 2 05 12346789 3 246789 135 0 3 246789 0 135 3 246789 0 135 2 135 0246789 1 0123456789 Output next 0 5 next 0 1 3 next 2 3 0 1 4 5 6 7 8 9 next 9 8 7 6 5 4 3 2 1 0 next 0 1 3 5 next 1 3 5 done Note In the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear. In the example, the friends move as follows: <image> Submitted Solution: ``` import sys def step(l): print("next", end = '') for n in l: print(' ', n, end = '') print('') sys.stdout.flush() def le_ent(): global ent ent = [] while(len(ent) == 0): ent = input().split() if __name__== "__main__": l1 = [0, 1] l2 = [1] l3 = [2, 3, 4, 5, 6, 7, 8, 9] seEncontrou = False ent = [] while not seEncontrou: step(l1) le_ent() step(l2) le_ent() for lx in ent[1:]: zero = False one = False for num in lx: if num == '0': zero = True if num == '1': one = True if zero and one: seEncontrou = True seEncontrou = False while not seEncontrou: step(l1) le_ent() step(l3) le_ent() for lx in ent[1:]: zero = False two = False for num in lx: if num == '0': zero = True if num == '2': two = True if zero and two: seEncontrou = True print("done") sys.stdout.flush() ``` No
95,317
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake". Misha has already come up with a field for the upcoming game. The field for this game is a directed graph consisting of two parts. The first part is a road along the coast of the lake which is a cycle of c vertices. The second part is a path from home to the lake which is a chain of t vertices, and there is an edge from the last vertex of this chain to the vertex of the road along the coast which has the most beautiful view of the lake, also known as the finish vertex. Misha decided to keep the field secret, so nobody knows neither t nor c. <image> Note that each vertex of the field has exactly one outgoing edge and all the vertices except the home vertex and the finish vertex have exactly one ingoing edge. The home vertex has no incoming edges, the finish vertex has two incoming edges. At the beginning of the game pieces of all the ten players, indexed with consecutive integers from 0 to 9, are at the home vertex. After that on each turn some of the players can ask Misha to simultaneously move their pieces along the corresponding edges. Misha will not answer more than q such queries. After each move Misha will tell players whose pieces are at the same vertices and whose pieces are at different vertices. The goal of the game is to move all the pieces to the finish vertex. Misha's friends have no idea how to win in such a game without knowledge of c, t and q, but luckily they are your friends. Help them: coordinate their actions to win the game. Misha has drawn such a field that 1 ≀ t, c, (t+c) ≀ 1000 and q = 3 β‹… (t+c). Input There is no input β€” go to the interaction part straight away. Output After all friends gather at the finish vertex, print "done" and terminate your program. Interaction To give a command to move the friends, print "next" and then space-separated indices of the friends you want to move. For example, to give the command to move the friends with indices 0, 2, 5 and 9 print "next 0 2 5 9". At each turn, you must move at least one of your friends. As an answer, first read an integer k, and then 10 digits divided into k space-separated groups. The friends that correspond to the indices in the same group are in the same vertex. The friends that correspond to indices in different groups are in different vertices. The indices in each group follow in ascending order. For example, the answer "2 05 12346789" means that the friends with indices 0 and 5 are in one vertex, and all other friends are in the same but different vertex. The answer "4 01 567 234 89" means that Misha's friends are in four different vertices: the friends with indices 0 and 1 are in the first, the friends with indices 5, 6 and 7 are in the second, the friends with indices 2, 3 and 4 are in the third, and the friends with indices 8 and 9 are in the fourth. After printing a query do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Answer "stop" instead of a valid one means that you made an invalid query. Exit immediately after receiving "stop" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream. Hacks In order to hack, print two integers t and c in a single line (1 ≀ t, c, (t+c) ≀ 1000). Example Input 2 05 12346789 3 246789 135 0 3 246789 0 135 3 246789 0 135 2 135 0246789 1 0123456789 Output next 0 5 next 0 1 3 next 2 3 0 1 4 5 6 7 8 9 next 9 8 7 6 5 4 3 2 1 0 next 0 1 3 5 next 1 3 5 done Note In the sample input and output values are aligned only for simplicity of interpreting them chronologically. In real interaction no "extra" line breaks should appear. In the example, the friends move as follows: <image> Submitted Solution: ``` from __future__ import division, print_function import itertools import os import sys from __builtin__ import xrange as range from cStringIO import StringIO from future_builtins import ascii, filter, hex, map, oct, zip from io import IOBase from collections import deque import __pypy__ MOD = 10 ** 9 + 7 def main(): # 0: fast # 1: slow same = False ctr = 0 while not same: curres = ["next", "0"] if ctr % 2: curres.append("1") print(" ".join(curres)) sys.stdout.flush() imparr = sys.stdin.readline().strip() if imparr == "stop": return imparr = imparr.split() k = int(imparr[0]); arr = imparr[1:] for str in arr: if len(str) >= 2 and str[0] == '0' and str[1] == '1': same = True ctr += 1 while True: print("next 0 1 2 3 4 5 6 7 8 9") sys.stdout.flush() imparr = sys.stdin.readline().strip() if imparr == "stop": return if imparr[0] == "1": break print("done") stdout.flush() """ Python 3 compatibility tools. """ def compatibility(): if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip """ End of Python 3 compatibility tools. """ """ Python Fast IO """ BUFSIZE = 8192 class FastI(IOBase): def __init__(self, file): self._fd = file.fileno() self._buffer = StringIO() self.newlines = 0 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("\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() class FastO(IOBase): def __init__(self, file): self._fd = file.fileno() self._buffer = __pypy__.builders.StringBuilder() self.write = lambda s: self._buffer.append(s) def flush(self): os.write(self._fd, self._buffer.build()) self._buffer = __pypy__.builders.StringBuilder() def print(*args, **kwargs): 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() sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") """ End of Python Fast IO """ if __name__ == "__main__": len = len compatibility() main() ``` No
95,318
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` res=0 temp=[] n=int(input()) def getnumber(n): return int(str(n)[0]) a=getnumber(n) def process(n): global res res=res+1 n=n+1 if n%10==0: while True: if n%10!=0: break else: n=n//10 return n def process1(n): global a if n!=a: process1(process(n)) if a==n: print(9) else: process1(n) print(res+1) ```
95,319
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` n = input() n = int(n) L=[n] temp = n while 1: temp = temp +1 while temp%10==0: temp=int(temp/10) if temp in L: break else: L.append(temp) print(len(L)) ```
95,320
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` import math def na(): n = int(input()) b = [int(x) for x in input().split()] return n,b def nab(): n = int(input()) b = [int(x) for x in input().split()] c = [int(x) for x in input().split()] return n,b,c def dv(): n, m = map(int, input().split()) return n,m def dva(): n, m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] return n,m,b def nm(): n = int(input()) b = [int(x) for x in input().split()] m = int(input()) c = [int(x) for x in input().split()] return n,b,m,c def dvs(): n = int(input()) m = int(input()) return n, m def pr(x): used = set() used.add(x) k = 10 - x % 10 for i in range(x, x + k): if i % 10 != 0: used.add(i) x += k if x % 10 != 0: used.add(x) while x > 1: knn = 0 while x % 10 == 0: x //= 10 kn = 10 - x % 10 if x == 1: for i in range(1, 10): used.add(i) used.add(x) return len(used) for i in range(x, x + kn): if i % 10 != 0: used.add(i) else: break x += kn k += kn + knn return len(used) n = int(input()) print(pr(n)) ```
95,321
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` # -*- coding: utf-8 -*- # @Date : 2019-04-27 08:29:57 # @Author : raj lath (oorja.halt@gmail.com) # @Link : link # @Version : 1.0.0 import sys sys.setrecursionlimit(10**5+1) inf = int(10 ** 20) max_val = inf min_val = -inf RW = lambda : sys.stdin.readline().strip() RI = lambda : int(RW()) RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda : [x for x in sys.stdin.readline().strip().split()] ins = RI() reachable = set() while ins not in reachable: reachable.add(ins) ins = int(str(ins + 1).strip("0")) print(len(reachable)) ```
95,322
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` #rOkY #FuCk ################################## kOpAl ##################################### def ans(a): a+=1 while(a%10==0): a//=10 return a a=set() n=int(input()) while(not(n in a)): a.add(n) n=ans(n) print(len(a)) ```
95,323
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` n=int(input()) L=[] while(n not in L): L.append(n) n+=1 while(n%10==0): n//=10 print(len(L)) ```
95,324
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` def f(x): x+=1 while x%10==0: x//=10 return x base=int(input()) compteur=1 liste=[base] while f(base) not in liste: liste.append(f(base)) base=f(base) compteur+=1 print(compteur) ```
95,325
Provide tags and a correct Python 3 solution for this coding contest problem. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Tags: implementation Correct Solution: ``` def f(x): return int(str(x + 1).rstrip('0')) def main(): x = int(input()) l = set() while x not in l: l.add(x) x = f(x) print(len(l)) if __name__ == "__main__": main() ```
95,326
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` n=int(input()) s=set() s.add(n) n+=1 while True: while n%10==0: n/=10 # print(n) n=int(n) # print(n) if n not in s: s.add(n) else: break n+=1 s.add(1) print(len(s)) ``` Yes
95,327
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` number=input() length=len(number) x=length-1 sum=0 b=int(number[x]) a=int(number[x-1]) x-=2 sum=10-b will_loop=x>0 or len(number)==3 if len(number)==2: sum=sum+9 elif len(number)==1: if int(number)==0: sum=10 else: sum=9 while x>0: b=a a=int(number[x]) sum=sum+9-b x-=1 if will_loop: sum=sum+9+9-a print(sum) ``` Yes
95,328
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` n = int(input()) def f(x): a = x + 1 while (a % 10 == 0): a = a / 10 return a S = {n} while f(n) not in S: S = S | {f(n)} n = f(n) print(len(S)) ``` Yes
95,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Mon Apr 22 16:05:55 2019 @author: Aman Seth st=input() le=len(st) if 'a' in st: ins=st.rfind('a') st1=st[0:ins+2] re=st[ins+2:le] ans=st1.replace('a','') if ans==re: print(st1) else: print(":(") else: if all(st[i]!=st[i+1] for i in range(le-1)): print(st[0:int(le/2)]) if all(i!='a' for i in st): if all(st[i]==st[i+1] for i in range(le-1)): print(":(") n,q=map(int,input().split()) a=list(map(int,input().split())) le=len(a) #c=['0']*le #st='' for i in range(q): x,y=input().split() y=int(y) if x=='>': for j in range(le): if a[j]>y: a[j]=-a[j] #c[j]=str(a[j]) #st=st+str(a[j])+' ' if x=='<': for j in range(le): if a[j]<y: a[j]=a[j] #c[j]=str(a[j]) #st=st+str(a[j])+' ' #for j in range(le): # a[j]=str(a[j]) print(' '.join(map(str,a))) #print(st) n,q=map(int,input().split()) a=list(map(int,input().split())) le=len(a) for i in range(q): x,y=input().split() y=int(y) if x=='>': for j in range(le): if a[j]>y: a[j]=-a[j] if x=='<': for j in range(le): if a[j]<y: a[j]=-a[j] #for j in range(len(a)): # a[j]=str(a[j]) print(' '.join(map(str,a))) m,x,y=map(int,input().split()) ans=[] for i in range(0,m+1): a=i count=0 if a+x<=a and a+x>=0 and (a+x and a-y not in ans): count+=1 ans.append(count) if a-y<=m and a-y>=0: count+=1 ans.append(count) print(ans) def fun(a,b,n): #s=a+b ans=[a,b] i=0 n=int(n) s='' while(len(s)<n): s=a[i]+a[i+1] ans.append(s) print(ans) for i in range(int(input())): a,b,n=map(str,input().split()) fun(a,b,n) """ n=input() print(9+sum(9-int(d)for d in n[1:])+(len(n)>1)) ``` Yes
95,330
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` n=int(input()) c=0 if n//10==0: print(10-n) else: while True: x=10-n%10-1 c+=(x+1) n+=(x+1) while n%10==0: n//=10 if n//10==0: break print(c+9) ``` No
95,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` x = input() arr = set() arr.add(x) x = str(int(x) + 1) while str(int(x) + 1) not in arr: if int(x) % 10 != 0: arr.add(x) while int(x) % 10 != 0: x = str(int(x) + 1) if int(x) % 10 != 0: arr.add(x) while x[-1] == "0": x = x[:-1] if int(x) % 10 != 0: arr.add(x) print(arr) print(len(arr)) ``` No
95,332
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` #!/usr/bin/python3 import sys def reach(x): total = 1 while True: if x < 10: total += 10 - x return total x += 1 while x % 10 == 0: x /= 10 total += 1 if __name__ == '__main__': input = sys.stdin.readline().strip() #arr = [] total = reach(int(input)) print(total) ``` No
95,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let's denote a function f(x) in such a way: we add 1 to x, then, while there is at least one trailing zero in the resulting number, we remove that zero. For example, * f(599) = 6: 599 + 1 = 600 β†’ 60 β†’ 6; * f(7) = 8: 7 + 1 = 8; * f(9) = 1: 9 + 1 = 10 β†’ 1; * f(10099) = 101: 10099 + 1 = 10100 β†’ 1010 β†’ 101. We say that some number y is reachable from x if we can apply function f to x some (possibly zero) times so that we get y as a result. For example, 102 is reachable from 10098 because f(f(f(10098))) = f(f(10099)) = f(101) = 102; and any number is reachable from itself. You are given a number n; your task is to count how many different numbers are reachable from n. Input The first line contains one integer n (1 ≀ n ≀ 10^9). Output Print one integer: the number of different numbers that are reachable from n. Examples Input 1098 Output 20 Input 10 Output 19 Note The numbers that are reachable from 1098 are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099. Submitted Solution: ``` x=int(input()) l1=[] y=x+1 l1.append(y) while(y!=-1): if(y%10==0): while(y%10==0): y=y/10 else: y=y+1 if (y % 10 == 0): while (y % 10 == 0): y = y / 10 if(y in l1): break else: l1.append(y) print(len(l1)+1) ``` No
95,334
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` #------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase 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") #-------------------game starts now---------------------------------------------------- n,m=map(int,input().split()) s=0 e=n-1 for i in range(n//2): for j in range(m): print(s+1,j+1) print(e+1,m-j) s+=1 e-=1 if n%2==1: s=n//2 for j in range(m//2): print(s+1,j+1) print(s+1,m-j) if m%2==1: print(s+1,m//2+1) ```
95,335
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` import sys ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) n, m = list(map(int, sys.stdin.readline().strip().split())) upr = 1 dwr = n while(upr < dwr): upc = 1 dwc = m for i in range(m): sys.stdout.write(str(upr) + ' ' + str(upc) + '\n') sys.stdout.write(str(dwr) + ' ' + str(dwc) + '\n') upc += 1 dwc -= 1 upr += 1 dwr -= 1 if(upr == dwr): row = upr col = 1 rcol = m for i in range(m): sys.stdout.write(str(row) + ' ' + str(col) + '\n') tcol = col col = rcol rcol = (tcol + 1 if (tcol < rcol) else tcol - 1) ```
95,336
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` import sys import math from collections import defaultdict n,m=map(int,sys.stdin.readline().split()) #cur=[1,1] #ans=[-1 for _ in range(2*n*m)] up,down=1,n count=0 while up<=down: left,right=1,m #ans.append(cur) while left<=m and count<n*m: #ans.append([up,left]) #ans[count]=[up,left] if count<n*m: sys.stdout.write((str(up)+" "+str(left)+"\n")) count+=1 left+=1 #ans[count]=[down,right] if count<n*m: sys.stdout.write((str(down)+" "+str(right)+"\n")) count+=1 #ans.append([down,right]) right-=1 up+=1 down-=1 '''if n==1: a=len(ans) #print(a,'a') for i in range(a//2): print(ans[i][0],ans[i][1]) else: a=len(ans) for i in range(a//2): print(ans[i][0],ans[i][1]) #print(ans)''' ```
95,337
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` import sys m, n = [int(i) for i in input().split()] data = [0] * (m+1) for i in range((m+1)//2 ): data[2*i] = i+1 data[2*i+1] = m - i for x in range(n//2): for i in range(m): sys.stdout.write(str(i+1) + ' ' + str(x+1) + '\n') sys.stdout.write(str(m-i) + ' ' + str(n-x) + '\n') #print(i+1, x+1) #print(m - i, n - x) if n % 2 == 1: q = (n+1)//2 s = " " + str(q) + '\n' for i in range(m): #print(data[i], q) sys.stdout.write(str(data[i]) + s) ```
95,338
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` import math import sys n,m=[int(x) for x in input().split()] answer=[] x=math.ceil(n/2) y=n%2 for i in range(1,math.ceil(n/2)+1): if y==1 and i==x: for j in range(1,m//2+1): answer.append(str(i)+' '+str(j)) answer.append(str(n-i+1)+' '+str(m-j+1)) answer.append((str(i)+' '+str((math.ceil(m/2))))) else: for j in range(1,m+1): answer.append((str(i)+' '+str(j))) answer.append(str(n-i+1)+' '+str(m-j+1)) print("\n".join(answer[:n*m])) ```
95,339
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` if __name__ == "__main__": n, m = [int(x) for x in input().split()] #n, m = map(int, input().split()) answer = [] for i in range((n + 1) // 2): for j in range(m): if i == n // 2 and j == m // 2: if m % 2 == 0: break answer.append("{} {}".format(i + 1, j + 1)) break answer.append("{} {}".format(i + 1, j + 1)) answer.append("{} {}".format(n - i, m - j)) print("\n".join(answer)) ```
95,340
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` n, m = tuple(map(int, input().split())) if n==1 and m==1: print('1 1') exit() def onerow(r, m): for i in range(1, (m+1)//2 + 1): # print('Here', i) print(str(r) + ' ' + str(i)) if m%2 == 0 or i != (m+1)//2: print(str(r) + ' ' + str(m+1-i)) def tworow(r1, r2, m): for i in range(1, m+1): print(str(r1) + ' ' + str(i)) print(str(r2) + ' ' + str(m+1-i)) if n%2 == 0: for i in range(1, n//2 + 1): tworow(i, n+1-i, m) if n%2 == 1: for i in range(1, n//2 + 1): tworow(i, n+1-i, m) onerow(n//2 + 1, m) ```
95,341
Provide tags and a correct Python 3 solution for this coding contest problem. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Tags: constructive algorithms Correct Solution: ``` import sys input=sys.stdin.buffer.readline n,m=map(int,input().split()) for i in range(n//2+n%2): x1=i+1 x2=n-i if(x1==x2): for j in range(m//2+m%2): if(j+1==m-j): sys.stdout.write((str(x1)+" "+str(j+1)+"\n")) else: sys.stdout.write((str(x1)+" "+str(j+1)+"\n")) sys.stdout.write((str(x2)+" "+str(m-j)+"\n")) else: if(i%2==0): for j in range(m): sys.stdout.write((str(x1)+" "+str(j+1)+"\n")) sys.stdout.write((str(x2)+" "+str(m-j)+"\n")) else: for j in range(m): sys.stdout.write((str(x1)+" "+str(m-j)+"\n")) sys.stdout.write((str(x2)+" "+str(j+1)+"\n")) ```
95,342
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` import sys input = sys.stdin.readline n,m=map(int,input().split()) ANS=[] for i in range(1,n//2+1): for j in range(1,m+1): sys.stdout.write("".join((str(i)," ",str(j),"\n"))) sys.stdout.write("".join((str(n-i+1)," ",str(m-j+1),"\n"))) if n%2==1: for j in range(1,m//2+1): sys.stdout.write("".join((str(n//2+1)," ",str(j),"\n"))) sys.stdout.write("".join((str(n//2+1)," ",str(m-j+1),"\n"))) if m%2==1: sys.stdout.write("".join((str(n//2+1)," ",str(m//2+1),"\n"))) ``` Yes
95,343
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` n,m=map(int,input().split()) x1,y1,x2,y2=1,1,n,m for i in range(n*m): if(i&1): print(str(x2)+" "+str(y2)) if x2==1: x2,y2=n,y2-1 else: x2-=1 else: print(str(x1)+" "+str(y1)) if x1==n: x1,y1=1,y1+1 else: x1+=1 ``` Yes
95,344
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` n, m = list(map(int,input().split())) for i in range (0, n * m): if i % 2 == 0: c = i // (2 * n) r = (i % (2 * n)) // 2 else: c = m - 1 - i // (2 * n) r = n - 1 - (i % (2 * n)) // 2 print(str(r+1) + " " + str(c + 1)) ``` Yes
95,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` n, m = list(map(int,input().split())) ans = [] for i in range(n // 2): for j in range(m): ans.append(str(i + 1) + ' ' + str(j + 1)) ans.append(str(n - i) + ' ' + str(m - j)) if n % 2 == 1: i = n // 2 + 1 for j in range(m // 2): ans.append(str(i) + ' ' + str(j + 1)) ans.append(str(i) + ' ' + str(m - j)) if m % 2 == 1: ans.append(str(i) + ' ' + str(m // 2 + 1)) print ('\n'.join(ans)) ``` Yes
95,346
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` """ 111 111 11111 11111 11 15 12 14 13 23 24 22 25 21 111111 111111 11 16 12 15 13 14 24 11 11 11 11 11 11 51 21 41 31 32 42 22 52 12 1 1 1 1 1 11 51 21 41 31 """ n,m=list(map(int,input().split())) if n>2 and m>2: print(-1) exit(0) if n==1 and m==1: print(1,1) elif n==1: count=0 l=1 r=m fl=0 while count<m: if fl==0: print(1,l) l+=1 fl=1 else: print(1,r) r-=1 fl=0 count+=1 #print(l,r,end="1233") elif n==2: res=[] count=0 l=1 r=m fl=0 y=0 temp=1 while count<m: if fl==0: print(1,l) res.append(l) y=l l+=1 fl=1 else: print(1,r) res.append(r) y=r r-=1 fl=0 count+=1 while res!=[]: print(2,res[-1]) res.pop() elif m==1: #print("hhh") count=0 l=1 r=n fl=0 while count<n: if fl==0: print(l,1) l+=1 fl=1 else: print(r,1) r-=1 fl=0 count+=1 elif m==2: res=[] count=0 l=1 r=n fl=0 while count<n: if fl==0: print(l,1) res.append(l) l+=1 fl=1 else: print(r,1) res.append(r) r-=1 fl=0 count+=1 while res!=[]: print(res[-1],2) res.pop() else: print(-1) ``` No
95,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` list=[int(x) for x in input().split()] n=list[0] m=list[1] dif=n*m-1 for i in range(0,dif,2): print(i//m+1,i%m+1) print((dif-i)//m+1,(dif-i)%m+1) if dif %2==0: print(m/2+1,n/2+1) ``` No
95,348
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` n, m = [int(x) for x in input().split()] l = 1 r = n while l <= r: t = 1 b = m if l == r: while t <= b: print(l, t) if t != b: print(r, b) t += 1 b -= 1 else: while t <= m and b >= 0: print(l, t) if t != b: print(r, b) t += 1 b -= 1 l += 1 r -= 1 ``` No
95,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a problem and asks his uncle. After a long time thinking, Tolik's uncle hasn't any ideas on how to solve it. But, he doesn't want to tell Tolik about his inability to solve it, so he hasn't found anything better than asking you how to solve this task. In this task you are given a cell field n β‹… m, consisting of n rows and m columns, where point's coordinates (x, y) mean it is situated in the x-th row and y-th column, considering numeration from one (1 ≀ x ≀ n, 1 ≀ y ≀ m). Initially, you stand in the cell (1, 1). Every move you can jump from cell (x, y), which you stand in, by any non-zero vector (dx, dy), thus you will stand in the (x+dx, y+dy) cell. Obviously, you can't leave the field, but also there is one more important condition β€” you're not allowed to use one vector twice. Your task is to visit each cell of the field exactly once (the initial cell is considered as already visited). Tolik's uncle is a very respectful person. Help him to solve this task! Input The first and only line contains two positive integers n, m (1 ≀ n β‹… m ≀ 10^{6}) β€” the number of rows and columns of the field respectively. Output Print "-1" (without quotes) if it is impossible to visit every cell exactly once. Else print n β‹… m pairs of integers, i-th from them should contain two integers x_i, y_i (1 ≀ x_i ≀ n, 1 ≀ y_i ≀ m) β€” cells of the field in order of visiting, so that all of them are distinct and vectors of jumps between them are distinct too. Notice that the first cell should have (1, 1) coordinates, according to the statement. Examples Input 2 3 Output 1 1 1 3 1 2 2 2 2 3 2 1 Input 1 1 Output 1 1 Note The vectors from the first example in the order of making jumps are (0, 2), (0, -1), (1, 0), (0, 1), (0, -2). Submitted Solution: ``` import math inp = input().split(' ') m = int(inp[0]) n = int(inp[1]) for column in range(1, math.ceil(m/2) + 1): rowRange = range(1, n + 1) if column == math.ceil(m / 2) and m % 2 == 1: rowRange = range(1, math.ceil(n/2) + 1) for row in rowRange: print(str(column) + ' ' + str(row)) if row == math.ceil(n/2) and n % 2 == 1: continue print(str(m + 1 - column) + ' ' + str(n + 1 - row)) ``` No
95,350
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` import copy n,m,k=map(int,input().split()) A=list(map(int,input().split())) ANS=0 for i in range(m): B=copy.deepcopy(A) for j in range(i,n,m): B[j]-=k NOW=0 for j in range(i,n): if j%m==i: NOW=max(NOW+B[j],B[j]) else: NOW+=B[j] ANS=max(ANS,NOW) print(ANS) ```
95,351
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` '''input 5 3 10 1 2 10 2 3 ''' import math def max_sub(arr,n): dp = [0]*n dp[0] = arr[0] for i in range(1,n): dp[i] = max(dp[i-1]+arr[i],arr[i]) return max(0,max(dp)) n,m,k = map(int,input().split()) arr = list(map(int,input().split())) q = -math.inf dp = [0]*(300100) for i in range(300100): dp[i] = [q]*(11) if (m==1): for i in range(n): arr[i]= arr[i]-k print(max_sub(arr,n)) else: for i in range(n): dp[i][1] = arr[i]-k for j in range(m): if (i-1<0 or dp[i-1][j]==q): continue if ((j+1)%m!=1): dp[i][(j+1)%m] = dp[i-1][j]+arr[i] else: dp[i][(j+1)%m] = max(arr[i]-k,dp[i-1][j]+arr[i]-k) ma=0 for i in range(n): # s = "" for j in range(m): # s+=str(dp[i][j])+" " ma = max(ma,dp[i][j]) # print(s) print(ma) ```
95,352
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` from math import * n,m,k = map(int,input().split()) l = list(map(int,input().split())) a = [0 for i in range(n+1)] ans = 0 for M in range(m): min1 = 0 for i in range(1,n+1): a[i] = a[i-1] + l[i-1] if(i % m == M): a[i] -= k ans = max(ans,a[i]-min1) min1 = min(min1,a[i]) #print(a) print(ans) ```
95,353
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` n, m, k = map(int, input().split()) a = list(map(int, input().split())) best = 0 dp = [0] * (n + 1) for i in range(n): b2 = 0 for j in range(max(-1, i - m), i + 1): b2 = max(b2, dp[j] - k + sum(a[j + 1:i + 1])) dp[i] = max(b2, a[i] - k) best = max(best, dp[i]) print(best) # print(dp) ```
95,354
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` import sys n, m, k = list(map(int, sys.stdin.readline().strip().split())) a = list(map(int, sys.stdin.readline().strip().split())) b = [0] * (n+1) for i in range (1, n+1): b[i] = b[i-1] + m * a[i-1] - k M = [10 ** 20] * m ans = 0 for i in range (0, n+1): M[i % m] = min([M[i % m], b[i]]) for j in range (0, m): if i > j: ans = max([ans, b[i]-M[j]-k*((m*i+m-(i-j))%m)]) # print(j, M, ans) print(ans // m) ```
95,355
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` import os import sys from io import BytesIO, IOBase from collections import Counter import math as mt 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 gcd(a, b): if a == 0: return b return gcd(b % a, a) def lcm(a, b): return (a * b) / gcd(a, b) mod = int(1e9) + 7 def power(k, n): if n == 0: return 1 if n % 2: return (power(k, n - 1) * k) % mod t = power(k, n // 2) return (t * t) % mod def totalPrimeFactors(n): count = 0 if (n % 2) == 0: count += 1 while (n % 2) == 0: n //= 2 i = 3 while i * i <= n: if (n % i) == 0: count += 1 while (n % i) == 0: n //= i i += 2 if n > 2: count += 1 return count # #MAXN = int(1e7 + 1) # # spf = [0 for i in range(MAXN)] # # # def sieve(): # spf[1] = 1 # for i in range(2, MAXN): # spf[i] = i # for i in range(4, MAXN, 2): # spf[i] = 2 # # for i in range(3, mt.ceil(mt.sqrt(MAXN))): # if (spf[i] == i): # for j in range(i * i, MAXN, i): # if (spf[j] == j): # spf[j] = i # # # def getFactorization(x): # ret = 0 # while (x != 1): # k = spf[x] # ret += 1 # # ret.add(spf[x]) # while x % k == 0: # x //= k # # return ret # Driver code # precalculating Smallest Prime Factor # sieve() def main(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) dp = [[0 for i in range(m)] for j in range(n)] ans = 0 for i in range(n): if m == 1: if i: dp[i][0] = max(a[i] - k, dp[i - 1][0] + a[i] - k) else: dp[i][0] = a[i] - k ans = max(ans, dp[i][0]) else: if i: for j in range(m): if (j <= i + 1 and j>=1) or (j==0 and i>=m-1): if j != 1: dp[i][j] = dp[i - 1][(j - 1 + m) % m] + a[i] else: dp[i][1] = max(a[i] - k, dp[i - 1][0] + a[i] - k) ans = max(ans, dp[i][j]) else: dp[i][1] = a[i] - k ans = max(ans, a[i] - k) #print(dp[i]) print(ans) # 7 1 10 # 2 -4 15 -3 4 8 3 # s=input() return if __name__ == "__main__": main() ```
95,356
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` import io, sys input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) n, m, k = mi() a = [None] + li() p = [0] * (n + 1) for i in range(1, n + 1): p[i] = p[i - 1] + a[i] s = [10 ** 16 for _ in range(m)] s[0] = k ans = 0 for i in range(1, n + 1): ans = max(ans, p[i] - min(s)) s[i % m] = min(s[i % m], p[i]) s[i % m] += k print(ans) ```
95,357
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Tags: dp, greedy, math Correct Solution: ``` def naiveSolve(n,m,k,a): ans=0 L,R=-1,-1 for l in range(n): t=0 for r in range(l,n): t+=a[r] temp=t-k*(((r-l+1)+m-1)//m) if temp>ans: ans=temp L,R=l,r return ans,L,R return def main(): # n,m,k=10,5,5 # from random import randint # a=[randint(-5,5) for _ in range(n)] n,m,k=readIntArr() a=readIntArr() p=a.copy() for i in range(1,n): p[i]+=p[i-1] def rangeSum(l,r): if l==0: return p[r] else: return p[r]-p[l-1] dp=[0]*n # dp[i] is the max value ending at a[i] for i in range(n): if i-m>=0: dp[i]=max(dp[i],dp[i-m]+rangeSum(i-m+1,i)-k) # join to prev block # don't join to prev block for j in range(max(0,i-m+1),i+1): dp[i]=max(dp[i],rangeSum(j,i)-k) ans=max(dp) print(ans) # ans2,L,R=naiveSolve(n,m,k,a) ## # if ans!=ans2: # print('a:{} ans:{} ans2:{} L:{} R:{}'.format(a,ans,ans2,L,R)) # print(dp) return import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) # input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] # def readFloatArr(): # return [float(x) for x in input().split()] def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m]) dv=defaultValFactory;da=dimensionArr if len(da)==1:return [dv() for _ in range(da[0])] else:return [makeArr(dv,da[1:]) for _ in range(da[0])] def queryInteractive(l,r): print('? {} {}'.format(l,r)) sys.stdout.flush() return int(input()) def answerInteractive(x): print('! {}'.format(x)) sys.stdout.flush() inf=float('inf') MOD=10**9+7 # MOD=998244353 from math import gcd,floor,ceil for _abc in range(1): main() ```
95,358
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` if __name__ == '__main__': n, m, k = map(int, input().split()) aa = list(map(int,input().split())) ans = 0 for start in range(m): ac = aa[:] for i in range(start, n, m): ac[i] -= k cur = 0 for i in range(start, n): if i%m == start: cur = max(ac[i] + cur, ac[i]) else: cur += ac[i] ans = max(cur, ans) print(ans) ``` Yes
95,359
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` n, m, k = [int(i) for i in input().split()] A = [int(i) for i in input().split()] bestbest = 0 def brute(n, m, k, A): ans = 0 val = (0, 0) for i in range(n): for j in range(i, n): if ans < sum(A[i:j+1]) - k*(ceil((j-i+1)/m)): ans = sum(A[i:j+1]) - k*(ceil((j-i+1)/m)) val = (i, j) return val, ans for off in range(m): B = A[off:] C = [] canstart = [] for i in range(len(B)): if i%m == 0: C.append(-k) canstart.append(1) canstart.append(0) C.append(B[i]) best = 0 run = 0 for i in range(len(C)): run += C[i] if run < -k: run = -k best = max(best, run) #print(best, C) bestbest = max(bestbest, best) print(bestbest) ``` Yes
95,360
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` from sys import stdin, stdout, exit n, m, k = map(int, stdin.readline().split()) a = list(map(int, stdin.readline().split())) def bf(a): best = 0 best_arg = (-1, -1) for i in range(n): for j in range(i, n): cur = sum(a[i:j+1]) - k*((j - i) // m + 1) if cur > best: best = max(best, cur) best_arg = (i,j) return best, best_arg def max_sum(a): if len(a) == 0: return 0 elif len(a) == 1: return max(0, a[0] - k) mid = len(a) // 2 l_rec = max_sum(a[:mid]) r_rec = max_sum(a[mid:]) l_bests = [0]*m r_bests = [0]*m l_sum = 0 for idx in range(1,mid+1): l_sum += a[mid-idx] if idx % m == 0: l_sum -= k l_bests[idx%m] = max(l_bests[idx%m], l_sum) r_sum = 0 for idx in range(0, len(a)-mid): r_sum += a[idx+mid] if (idx+1) % m == 0: r_sum -= k r_bests[(idx+1)%m] = max(r_bests[(idx+1)%m], r_sum) # print("Array:", a, "mid:", mid) # print(l_bests) # print(r_bests) best_acr = 0 for i in range(m): for j in range(m): best_acr = max(best_acr, l_bests[i] + r_bests[j] - (k if i+j>0 else 0) - (k if i+j>m else 0)) ans = max(l_rec,r_rec, best_acr) # print("Answer:", ans) return ans ans = max_sum(a) stdout.write(str(ans) + "\n") #stdout.write(str(bf(a))+"\n") ``` Yes
95,361
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` import sys import math as mt import bisect input=sys.stdin.readline #t=int(input()) t=1 def ncr_util(): inv[0]=inv[1]=1 fact[0]=fact[1]=1 for i in range(2,300001): inv[i]=(inv[i%p]*(p-p//i))%p for i in range(1,300001): inv[i]=(inv[i-1]*inv[i])%p fact[i]=(fact[i-1]*i)%p def solve(): pre=0 dp=[0]*(n+1) ans=0 for i in range(n): ss,maxi=0,0 if i<m: pre+=l[i] else: pre+=l[i] pre-=l[i-m] for j in range(i,max(i-m,-1),-1): ss+=l[j] maxi=max(maxi,ss-k) if i>=m: dp[i]=max(dp[i-m]+pre-k,maxi) else: dp[i]=max(dp[i],maxi) ans=max(dp[i],ans) return ans for _ in range(t): #n=int(input()) #n1=int(input()) #s=input() #n=int(input()) n,m,k=(map(int,input().split())) #n1=n #a=int(input()) #b=int(input()) #a,b,c,r=map(int,input().split()) #x2,y2=map(int,input().split()) #n=int(input()) #s=input() #s1=input() #p=input() l=list(map(int,input().split())) pref=[0]*(n+1) for i in range(n): pref[i+1]=pref[i]+l[i] #l=str(n) #l.sort(reverse=True) #l2.sort(reverse=True) #l1.sort(reverse=True) print(solve()) ``` Yes
95,362
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` def naiveSolve(n): return from collections import defaultdict def main(): # A solution will be 0 or include a maximal subarray sum # Kadane's to find maximal subarray sums maxSum=defaultdict(lambda:-inf) # {length:sum} n,m,k=readIntArr() a=readIntArr() l=0 t=0 for x in a: t+=x l+=1 if t<0: # restart t=0 l=0 else: maxSum[l]=max(maxSum[l],t) ans=0 for l,summ in maxSum.items(): ans=max(ans,summ-k*((l+m-1)//m)) print(ans) return import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) # input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x) for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x) for x in y]) for y in arr])) def readIntArr(): return [int(x) for x in input().split()] # def readFloatArr(): # return [float(x) for x in input().split()] def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m]) dv=defaultValFactory;da=dimensionArr if len(da)==1:return [dv() for _ in range(da[0])] else:return [makeArr(dv,da[1:]) for _ in range(da[0])] def queryInteractive(l,r): print('? {} {}'.format(l,r)) sys.stdout.flush() return int(input()) def answerInteractive(x): print('! {}'.format(x)) sys.stdout.flush() inf=float('inf') MOD=10**9+7 # MOD=998244353 from math import gcd,floor,ceil for _abc in range(1): main() ``` No
95,363
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` n,m,k=map(int,input().split()) a=list(map(int,input().split())) c=[0] for i in range(n): c.append(c[-1]+a[i]) r=n l=0 ans=0 while r>l: ans=max(ans,c[r]-c[l]+k*(-(r-l)//m)) if a[l]<=a[r-1]: l+=1 else: r-=1 print(ans) ``` No
95,364
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` from math import ceil n, m, k = map(int, input().split()) a = list(map(int, input().split())) s = 0 res = 0 l = -1 for i in range(n): if s <= 0: l = i s = a[i] else: s += a[i] res = max(res, s - k * ceil((i-l+1)/m)) print(res) ``` No
95,365
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to βˆ‘_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) βŒ‰, where ⌈ x βŒ‰ is the least integer greater than or equal to x. The cost of empty subarray is equal to zero. For example, if m = 3, k = 10 and a = [2, -4, 15, -3, 4, 8, 3], then the cost of some subarrays are: * a_3 ... a_3: 15 - k ⌈ 1/3 βŒ‰ = 15 - 10 = 5; * a_3 ... a_4: (15 - 3) - k ⌈ 2/3 βŒ‰ = 12 - 10 = 2; * a_3 ... a_5: (15 - 3 + 4) - k ⌈ 3/3 βŒ‰ = 16 - 10 = 6; * a_3 ... a_6: (15 - 3 + 4 + 8) - k ⌈ 4/3 βŒ‰ = 24 - 20 = 4; * a_3 ... a_7: (15 - 3 + 4 + 8 + 3) - k ⌈ 5/3 βŒ‰ = 27 - 20 = 7. Your task is to find the maximum cost of some subarray (possibly empty) of array a. Input The first line contains three integers n, m, and k (1 ≀ n ≀ 3 β‹… 10^5, 1 ≀ m ≀ 10, 1 ≀ k ≀ 10^9). The second line contains n integers a_1, a_2, ..., a_n (-10^9 ≀ a_i ≀ 10^9). Output Print the maximum cost of some subarray of array a. Examples Input 7 3 10 2 -4 15 -3 4 8 3 Output 7 Input 5 2 1000 -13 -4 -9 -20 -11 Output 0 Submitted Solution: ``` import sys n, m, k = list(map(int, sys.stdin.readline().strip().split())) a = list(map(int, sys.stdin.readline().strip().split())) b = [0] * n b[0] = m * a[0] - k for i in range (1, n): b[i] = b[i-1] + m * a[i] - k M = [10 ** 20] * m ans = 0 for i in range (0, n): M[b[i] % m] = min([M[b[i] % m], b[i]]) for j in range (0, m): ans = max([ans, b[i]-M[j]-k*((m-(i-j))%m)]) #print(M, ans) print(ans // m) ``` No
95,366
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` n = int(input()) dists = list(map(int, input().split())) dists = list(enumerate(dists)) # Sort from large to small dists.sort(key=lambda x: -x[1]) dist = [[2*idx + 1] for idx, _ in dists] for cur_idx, (idx, w) in enumerate(dists): if cur_idx + w == len(dist): dist.append([2*idx + 2]) else: dist[cur_idx + w - 1].append(2*idx + 2) for idx in range(len(dist)): if idx != 0: print(dist[idx][0], dist[idx-1][0]) for i_idx in range(1, len(dist[idx])): print(dist[idx][i_idx], dist[idx][0]) ```
95,367
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` # https://codeforces.com/contest/1214/problem/E n = int(input()) d = map(int, input().split()) d = [[2*i+1, di] for i, di in enumerate(d)] d = sorted(d, key=lambda x:x[1], reverse = True) edge = [] arr = [x[0] for x in d] for i, [x, d_] in enumerate(d): if i + d_ - 1 == len(arr) - 1: arr.append(x+1) edge.append([arr[i + d_ - 1], x+1]) for u, v in zip(d[:-1], d[1:]): edge.append([u[0], v[0]]) ans = '\n'.join([str(u)+' '+str(v) for u, v in edge]) print(ans) ```
95,368
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` import sys input=sys.stdin.buffer.readline n=int(input()) a=list(map(int,input().split())) stored=[[10000000000,0]] gaped=[0] for i in range(n): stored.append([a[i],2*i+1]) stored.sort(reverse=True) for i in range(1,n): gaped.append(stored[i][1]) print(stored[i][1],stored[i+1][1]) gaped.append(stored[-1][1]) l=n for i in range(1,n+1): if(i+stored[i][0]==l+1): print(gaped[-1],gaped[i]+1) gaped.append(gaped[i]+1) l+=1 else: print(gaped[i+stored[i][0]-1],gaped[i]+1) ```
95,369
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` import sys input = sys.stdin.readline n=int(input()) d=[int(i) for i in input().split(' ')] v=[2*i+1 for i in range(n)] v.sort(key = lambda x:d[x//2],reverse = 1) for i in range(n-1):print(v[i],v[i+1]) currlen = len(v) #len of v for i in range(n): if d[v[i]//2] + i == currlen: v.append(v[i] + 1) currlen += 1 print(v[-2],v[i] + 1) else: print(v[ d[v[i]//2] + i - 1],v[i]+1) ```
95,370
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` import sys input = sys.stdin.readline n=int(input()) d=list(map(int,input().split())) ANS=[] def pri(x,y): sys.stdout.write(str(x)+" "+str(y)+"\n") D=[(x,i) for i,x in enumerate(d)] D.sort(reverse=True) CHAIN=[y*2+1 for _,y in D] for i in range(n-1): pri(CHAIN[i],CHAIN[i+1]) for i in range(n): k,x=D[i] use=CHAIN[i+k-1] pri(use,x*2+2) if use==CHAIN[-1]: CHAIN.append(x*2+2) ```
95,371
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` import sys input = sys.stdin.readline def main(): n = int(input()) d = list(map(int, input().split())) d = list(enumerate(d)) d.sort(key = lambda x: x[1], reverse = True) edges = [] def add_edge(a, b): edges.append((a, b)) pos = 0 cur_line = [] pend = [] flag = False for item in d: _id, _d = item if not flag and (not cur_line or cur_line[pos] >= 0): if cur_line: flag = True else: cur_line = [-1] * (_d + 1) pos = 0 if flag: if _d == 1: add_edge(2 * _id, 2 * _id + 1) add_edge(cur_line[0], 2 * _id) else: add_edge(2 * _id, cur_line[1]) add_edge(cur_line[_d - 1], 2 * _id + 1) continue cur_line[pos] = 2 * _id to = pos + _d while to >= len(cur_line): cur_line.append(-1) if cur_line[to] >= 0: if cur_line[to - 1] == -1: pend.append((2 * _id + 1, to - 1)) else: add_edge(cur_line[to - 1], 2 * _id + 1) else: cur_line[to] = 2 * _id + 1 pos += 1 for nod, to in pend: add_edge(nod, cur_line[to]) for i in range(1, len(cur_line)): add_edge(cur_line[i - 1], cur_line[i]) assert(len(edges) == 2 * n - 1) for e in edges: print(f'{e[0] + 1} {e[1] + 1}') main() ```
95,372
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` n = int(input()) d = [int(item) for item in input().split()] ds = [] ans = [] for i, item in enumerate(d): ds.append((item, i)) ds.sort(reverse=True) max_dist = ds[0][0] max_idx = ds[0][1] to_fill = max_dist - 1 ans = [[] for _ in range(max_dist+1)] ans[0].append(max_idx*2+1) ans[max_dist].append(max_idx*2+2) itr = 0 for dist, idx in ds[1:]: if to_fill == 0: break itr += 1 odd = idx*2+1 ans[itr].append(odd) to_fill -= 1 to_fill = max_dist - 1 itr = 0 for dist, idx in ds[1:]: odd = idx*2+1 even = idx*2+2 if to_fill > 0: itr += 1 if itr + dist == len(ans): ans.append([even]) else: ans[itr+dist-1].append(even) else: if dist == 1: ans.append([odd]) ans.append([even]) else: ans[0].append(odd) ans[dist-2].append(even) to_fill -= 1 prev_par = None for line in ans: par = line[0] if prev_par is not None: print(prev_par, par) for item in line[1:]: print(par, item) prev_par = par ```
95,373
Provide tags and a correct Python 3 solution for this coding contest problem. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Tags: constructive algorithms, graphs, math, sortings, trees Correct Solution: ``` n = int(input()) v = list(map(int, input().split())) v = sorted([(v[i], i * 2 + 1) for i in range(n)], reverse=True) print('\n'.join([str(v[i][1]) + ' ' + str(v[i + 1][1]) for i in range(n - 1)])) r = [i[1] for i in v] for i in range(n): print(v[i][1] + 1, r[v[i][0] + i - 1]) if v[i][0] + i == len(r): r.append(v[i][1] + 1) ```
95,374
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): n = int(input()) d = list(map(lambda xx:[int(xx),0],input().split())) for i in range(n): d[i][1] = i+1 d.sort(key=lambda xx:xx[0],reverse=1) ls = [[2*d[i][1]-1] for i in range(n)] for i in range(n): x = i+d[i][0] if x >= len(ls): ls.append([2*d[i][1]]) continue ls[x-1].append(2*d[i][1]) op = [] for i in range(len(ls)-1): op.append((ls[i][0],ls[i+1][0])) for i in ls: for j in range(1,len(i)): op.append((i[0],i[j])) for i in op: print(*i) # 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() ``` Yes
95,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` '''with open("in.txt","r") as inF:''' n = int(input()) ds = map(int, input().split()) ds = [(d, jd) for jd, d in enumerate(ds)] ds.sort() d_max, jd_max = ds.pop() ic_to_i = {0: 2 * jd_max, d_max: 2 * jd_max + 1} ic_j_tuples = [(d_max - 1, 2 * jd_max + 1)] jd = 0 for ic in range(1, d_max): d, jd = ds.pop() i = jd * 2 j = jd * 2 + 1 ic_to_i[ic] = i ic_j_tuples.append((ic - 1, i)) new_ic = ic + d if new_ic not in ic_to_i: ic_to_i[new_ic] = j ic_j_tuples.append((ic + d - 1, j)) i_j_tuples = [] for ic, j in ic_j_tuples: i_j_tuples.append((ic_to_i[ic], j)) while len(ds) > 0: d, jd = ds.pop() i = jd * 2 j = jd * 2 + 1 if d == 1: i_j_tuples.append((i, j)) else: i_j_tuples.append((ic_to_i[d - 2], j)) i_j_tuples.append((i, ic_to_i[0])) for i, j in i_j_tuples: print(i+1, j+1) ``` Yes
95,376
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` import sys input = sys.stdin.readline n=int(input()) d=[int(i) for i in input().split(' ')] v=[2*i+1 for i in range(n)] v.sort(key = lambda x:-d[x//2]) #reverse sort on the basis of d[i] for i in range(n-1):print(v[i],v[i+1]) for i in range(n): if d[v[i]//2] + i == len(v): v.append(v[i] + 1) print(v[-2],v[i] + 1) else: print(v[ d[v[i]//2] + i - 1],v[i]+1) ``` Yes
95,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` '''with open("in.txt","r") as inF:''' n = int(input()) ds = map(int, input().split()) ds = [(d, id) for id, d in enumerate(ds)] ds.sort() dMax, idMax = ds.pop() iCToI = {0:2*idMax, dMax:2*idMax+1} iCJTuples = [(dMax-1,2*idMax+1)] id = 0 for iC in range(1,dMax): d, id = ds.pop() i = id*2 j = id*2+1 iCToI[iC] = i iCJTuples.append((iC-1,i)) newIC = iC+d if newIC not in iCToI: iCToI[newIC]= j iCJTuples.append((iC+d-1, j)) for iC, j in iCJTuples: print(iCToI[iC]+1,j+1) while len(ds)>0: d, id = ds.pop() i = id * 2 j = id * 2 + 1 if d==1: print(i+1, j+1) else: print(iCToI[d-2]+1, j+1) print(i+1, iCToI[0]+1) ``` Yes
95,378
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` import sys input = sys.stdin.readline n=int(input()) d=[int(i) for i in input().split(' ')] v=[2*i+1 for i in range(n)] v.sort(key = lambda x:d[x//2]) for i in range(n-1):print(v[i],v[i+1]) currlen = len(v) #len of v for i in range(n): if d[v[i]//2] + i == currlen: v.append(v[i] + 1) currlen += 1 print(v[-1],v[i] + 1) else: print(v[i] + 1,v[ d[v[i]//2] + i - 1]) ``` No
95,379
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` n = int(input()) d = [int(item) for item in input().split()] ds = [] ans = [] for i, item in enumerate(d): ds.append((item, i)) ds.sort(reverse=True) max_dist = ds[0][0] max_idx = ds[0][1] to_fill = max_dist - 1 ans = [[] for _ in range(max_dist+1)] ans[0].append(max_idx*2+1) ans[max_dist].append(max_idx*2+2) itr = 0 for dist, idx in ds[1:]: if to_fill == 0: break itr += 1 odd = idx*2+1 ans[itr].append(odd) to_fill -= 1 to_fill = max_dist - 1 itr = 0 for dist, idx in ds[1:]: odd = idx*2+1 even = idx*2+2 if to_fill > 0: itr += 1 if itr + dist == len(ans): ans.append([even]) else: ans[itr+dist-1].append(even) else: if dist == 1: ans.append([odd]) ans.append([even]) else: ans[0].append(odd) ans[dist-2].append(even) to_fill -= 1 print(ans) prev_par = None for line in ans: par = line[0] if prev_par is not None: print(prev_par, par) for item in line[1:]: print(par, item) prev_par = par ``` No
95,380
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` n = int(input()) v = list(map(int, input().split())) v = sorted([(v[i], i * 2 + 1) for i in range(n)], reverse=True) print('\n'.join([str(v[i][1]) + ' ' + str(v[i + 1][1]) for i in range(n - 1)])) r = [i[1] for i in v] for i in range(n): print(v[i][1] + 1, r[v[i][0] + i - 1]) if v[i][0] + i == len(r): r.append(v[i][1]) ``` No
95,381
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It's Petya's birthday party and his friends have presented him a brand new "Electrician-n" construction set, which they are sure he will enjoy as he always does with weird puzzles they give him. Construction set "Electrician-n" consists of 2n - 1 wires and 2n light bulbs. Each bulb has its own unique index that is an integer from 1 to 2n, while all wires look the same and are indistinguishable. In order to complete this construction set one has to use each of the wires to connect two distinct bulbs. We define a chain in a completed construction set as a sequence of distinct bulbs of length at least two, such that every two consecutive bulbs in this sequence are directly connected by a wire. Completed construction set configuration is said to be correct if a resulting network of bulbs and wires has a tree structure, i.e. any two distinct bulbs are the endpoints of some chain. Petya was assembling different configurations for several days, and he noticed that sometimes some of the bulbs turn on. After a series of experiments he came up with a conclusion that bulbs indexed 2i and 2i - 1 turn on if the chain connecting them consists of exactly d_i wires. Moreover, the following important condition holds: the value of d_i is never greater than n. Petya did his best but was not able to find a configuration that makes all bulbs to turn on, so he seeks your assistance. Please, find out a configuration that makes all bulbs shine. It is guaranteed that such configuration always exists. Input The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the parameter of a construction set that defines the number of bulbs and the number of wires. Next line contains n integers d_1, d_2, …, d_n (1 ≀ d_i ≀ n), where d_i stands for the number of wires the chain between bulbs 2i and 2i - 1 should consist of. Output Print 2n - 1 lines. The i-th of them should contain two distinct integers a_i and b_i (1 ≀ a_i, b_i ≀ 2n, a_i β‰  b_i) β€” indices of bulbs connected by a wire. If there are several possible valid answer you can print any of them. Examples Input 3 2 2 2 Output 1 6 2 6 3 5 3 6 4 5 Input 4 2 2 2 1 Output 1 6 1 7 2 6 3 5 3 6 4 5 7 8 Input 6 2 2 2 2 2 2 Output 1 3 2 3 3 5 4 5 5 7 6 7 7 12 8 12 9 11 9 12 10 11 Input 2 1 1 Output 1 2 1 4 3 4 Note <image> Answer for the first sample test. <image> Answer for the second sample test. Submitted Solution: ``` import sys input = sys.stdin.readline n=int(input()) d=[int(i) for i in input().split(' ')] v=[2*i+1 for i in range(n)] v.sort(key = lambda x:-d[x//2]) for i in range(n-1):print(v[i],v[i+1]) currlen = len(v) #len of v for i in range(n): if d[v[i]//2] + i == currlen: v.append(v[i] + 1) currlen += 1 print(v[-1],v[i] + 1) else: print(v[ d[v[i]//2] + i - 1],v[i]+1) ``` No
95,382
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order. Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you: * if t = 1, the area of the triangle a_ia_ja_k multiplied by 2. * if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}. Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a β‹… y_b - x_b β‹… y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0. You can ask at most 3 β‹… n queries. Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order. Interaction You start the interaction by reading n (3 ≀ n ≀ 1 000) β€” the number of vertices. To ask a query, write 4 integers t, i, j, k (1 ≀ t ≀ 2, 1 ≀ i, j, k ≀ n) in a separate line. i, j and k should be distinct. Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer. When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line. After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Hack format To hack, use the following format: The first line contains an integer n (3 ≀ n ≀ 1 000) β€” the number of vertices. The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≀ x_i, y_i ≀ 10^9) β€” the coordinate of the point a_i. Example Input 6 15 -1 1 Output 1 1 4 6 2 1 5 6 2 2 1 4 0 1 3 4 2 6 5 Note The image below shows the hidden polygon in the example: <image> The interaction in the example goes as below: * Contestant reads n = 6. * Contestant asks a query with t = 1, i = 1, j = 4, k = 6. * Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle. * Contestant asks a query with t = 2, i = 1, j = 5, k = 6. * Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1. * Contestant asks a query with t = 2, i = 2, j = 1, k = 4. * Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1. * Contestant says that the permutation is (1, 3, 4, 2, 6, 5). Submitted Solution: ``` import bisect import sys input = sys.stdin.readline n = int(input()) up = [] down = [] for i in range(2, n): # ε•γ„εˆγ‚γ›γ‚‹ print(2, 1, i, n) # ε•γ„εˆγ‚γ›γŸεΎŒγ―flushする sys.stdout.flush() # ε…₯εŠ›γ‚’ε—γ‘ε–γ‚‹ tmp = int(input()) if tmp == -1: up.append(i) else: down.append(i) up2 = [] down2 = [] for i in up: # ε•γ„εˆγ‚γ›γ‚‹ print(1, 1, i, n) # ε•γ„εˆγ‚γ›γŸεΎŒγ―flushする sys.stdout.flush() # ε…₯εŠ›γ‚’ε—γ‘ε–γ‚‹ s = int(input()) up2.append((s, i)) for i in down: # ε•γ„εˆγ‚γ›γ‚‹ print(1, 1, i, n) # ε•γ„εˆγ‚γ›γŸεΎŒγ―flushする sys.stdout.flush() # ε…₯εŠ›γ‚’ε—γ‘ε–γ‚‹ s = int(input()) down2.append((s, i)) up2 = sorted(up2) down2 = sorted(down2) ans1 = [1] ans2 = [] ans3 = [n] ans4 = [] ans = [] if up2: k = up2[-1][1] for i in range(len(up2) - 1): num = up2[i][1] # ε•γ„εˆγ‚γ›γ‚‹ print(2, 1, num, k) # ε•γ„εˆγ‚γ›γŸεΎŒγ―flushする sys.stdout.flush() # ε…₯εŠ›γ‚’ε—γ‘ε–γ‚‹ tmp = int(input()) if tmp == -1: ans1.append(num) else: ans2.append(num) ans += ans1 + [k] + ans2[::-1] else: ans += ans1 if down2: l = down2[-1][1] for i in range(len(down2) - 1): num = down2[i][1] # ε•γ„εˆγ‚γ›γ‚‹ print(2, n, num, l) # ε•γ„εˆγ‚γ›γŸεΎŒγ―flushする sys.stdout.flush() # ε…₯εŠ›γ‚’ε—γ‘ε–γ‚‹ tmp = int(input()) if tmp == -1: ans3.append(num) else: ans4.append(num) ans += ans3 + [l] + ans4[::-1] else: ans += ans3 print(0, *ans[::-1]) ``` No
95,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order. Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you: * if t = 1, the area of the triangle a_ia_ja_k multiplied by 2. * if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}. Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a β‹… y_b - x_b β‹… y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0. You can ask at most 3 β‹… n queries. Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order. Interaction You start the interaction by reading n (3 ≀ n ≀ 1 000) β€” the number of vertices. To ask a query, write 4 integers t, i, j, k (1 ≀ t ≀ 2, 1 ≀ i, j, k ≀ n) in a separate line. i, j and k should be distinct. Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer. When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line. After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Hack format To hack, use the following format: The first line contains an integer n (3 ≀ n ≀ 1 000) β€” the number of vertices. The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≀ x_i, y_i ≀ 10^9) β€” the coordinate of the point a_i. Example Input 6 15 -1 1 Output 1 1 4 6 2 1 5 6 2 2 1 4 0 1 3 4 2 6 5 Note The image below shows the hidden polygon in the example: <image> The interaction in the example goes as below: * Contestant reads n = 6. * Contestant asks a query with t = 1, i = 1, j = 4, k = 6. * Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle. * Contestant asks a query with t = 2, i = 1, j = 5, k = 6. * Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1. * Contestant asks a query with t = 2, i = 2, j = 1, k = 4. * Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1. * Contestant says that the permutation is (1, 3, 4, 2, 6, 5). Submitted Solution: ``` def chk(i): print(2, 1, 2, i) a = int(input()) print(1, 1, 2, i) s = int(input()) return (a, s) def cha(a, b, c): print(2, a, b, c) return int(input()) N = int(input()) PO = [] NE = [] for i in range(3, N+1): a, s = chk(i) if a > 0: PO.append((s, i)) else: NE.append((s, i)) PO = sorted(PO) NE = sorted(NE) # print("PO =", PO) # print("NE =", NE) P1 = [] P2 = [] N1 = [] N2 = [] if not PO: pass else: i0 = PO.pop()[1] P1.append(i0) while PO: i = PO.pop()[1] if cha(1, i0, i) > 0: P1.append(i) else: P2.append(i) i0 = NE.pop()[1] N1.append(i0) while NE: i = NE.pop()[1] if cha(1, i0, i) < 0: N1.append(i) else: N2.append(i) ANS = [0] + [1] + N1[::-1] + N2 + [2] + P2[::-1] + P1 print(*ANS) ``` No
95,384
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order. Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you: * if t = 1, the area of the triangle a_ia_ja_k multiplied by 2. * if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}. Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a β‹… y_b - x_b β‹… y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0. You can ask at most 3 β‹… n queries. Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order. Interaction You start the interaction by reading n (3 ≀ n ≀ 1 000) β€” the number of vertices. To ask a query, write 4 integers t, i, j, k (1 ≀ t ≀ 2, 1 ≀ i, j, k ≀ n) in a separate line. i, j and k should be distinct. Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer. When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line. After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Hack format To hack, use the following format: The first line contains an integer n (3 ≀ n ≀ 1 000) β€” the number of vertices. The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≀ x_i, y_i ≀ 10^9) β€” the coordinate of the point a_i. Example Input 6 15 -1 1 Output 1 1 4 6 2 1 5 6 2 2 1 4 0 1 3 4 2 6 5 Note The image below shows the hidden polygon in the example: <image> The interaction in the example goes as below: * Contestant reads n = 6. * Contestant asks a query with t = 1, i = 1, j = 4, k = 6. * Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle. * Contestant asks a query with t = 2, i = 1, j = 5, k = 6. * Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1. * Contestant asks a query with t = 2, i = 2, j = 1, k = 4. * Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1. * Contestant says that the permutation is (1, 3, 4, 2, 6, 5). Submitted Solution: ``` mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def ask(t, i, j, k): print(t, i, j, k) sys.stdout.flush() N = int(input()) p1 = 1 p2 = 2 for k in range(3, N+1): ask(2, 1, p2, k) flg = int(input()) if flg == -1: p2 = k SK = [] for k in range(2, N+1): if k == p2: continue ask(1, 1, p2, k) S = int(input()) SK.append((S, k)) SK.sort(key=lambda x: x[0]) pmax = SK[-1][1] p_first = [] p_second = [] for S, k in SK[:-1]: ask(2, 1, pmax, k) flg = int(input()) if flg == -1: p_second.append((S, k)) else: p_first.append((S, k)) p_first.sort(key=lambda x: x[0]) p_second.sort(key=lambda x: x[0], reverse=True) ans = [0, 1, p2] for _, p in p_first: ans.append(p) ans.append(pmax) for _, p in p_second: ans.append(p) print(*ans) sys.stdout.flush() if __name__ == '__main__': main() ``` No
95,385
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is an interactive problem. Khanh has n points on the Cartesian plane, denoted by a_1, a_2, …, a_n. All points' coordinates are integers between -10^9 and 10^9, inclusive. No three points are collinear. He says that these points are vertices of a convex polygon; in other words, there exists a permutation p_1, p_2, …, p_n of integers from 1 to n such that the polygon a_{p_1} a_{p_2} … a_{p_n} is convex and vertices are listed in counter-clockwise order. Khanh gives you the number n, but hides the coordinates of his points. Your task is to guess the above permutation by asking multiple queries. In each query, you give Khanh 4 integers t, i, j, k; where either t = 1 or t = 2; and i, j, k are three distinct indices from 1 to n, inclusive. In response, Khanh tells you: * if t = 1, the area of the triangle a_ia_ja_k multiplied by 2. * if t = 2, the sign of the cross product of two vectors \overrightarrow{a_ia_j} and \overrightarrow{a_ia_k}. Recall that the cross product of vector \overrightarrow{a} = (x_a, y_a) and vector \overrightarrow{b} = (x_b, y_b) is the integer x_a β‹… y_b - x_b β‹… y_a. The sign of a number is 1 it it is positive, and -1 otherwise. It can be proven that the cross product obtained in the above queries can not be 0. You can ask at most 3 β‹… n queries. Please note that Khanh fixes the coordinates of his points and does not change it while answering your queries. You do not need to guess the coordinates. In your permutation a_{p_1}a_{p_2}… a_{p_n}, p_1 should be equal to 1 and the indices of vertices should be listed in counter-clockwise order. Interaction You start the interaction by reading n (3 ≀ n ≀ 1 000) β€” the number of vertices. To ask a query, write 4 integers t, i, j, k (1 ≀ t ≀ 2, 1 ≀ i, j, k ≀ n) in a separate line. i, j and k should be distinct. Then read a single integer to get the answer to this query, as explained above. It can be proven that the answer of a query is always an integer. When you find the permutation, write a number 0. Then write n integers p_1, p_2, …, p_n in the same line. After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. Hack format To hack, use the following format: The first line contains an integer n (3 ≀ n ≀ 1 000) β€” the number of vertices. The i-th of the next n lines contains two integers x_i and y_i (-10^9 ≀ x_i, y_i ≀ 10^9) β€” the coordinate of the point a_i. Example Input 6 15 -1 1 Output 1 1 4 6 2 1 5 6 2 2 1 4 0 1 3 4 2 6 5 Note The image below shows the hidden polygon in the example: <image> The interaction in the example goes as below: * Contestant reads n = 6. * Contestant asks a query with t = 1, i = 1, j = 4, k = 6. * Jury answers 15. The area of the triangle A_1A_4A_6 is 7.5. Note that the answer is two times the area of the triangle. * Contestant asks a query with t = 2, i = 1, j = 5, k = 6. * Jury answers -1. The cross product of \overrightarrow{A_1A_5} = (2, 2) and \overrightarrow{A_1A_6} = (4, 1) is -2. The sign of -2 is -1. * Contestant asks a query with t = 2, i = 2, j = 1, k = 4. * Jury answers 1. The cross product of \overrightarrow{A_2A_1} = (-5, 2) and \overrightarrow{A_2A_4} = (-2, -1) is 1. The sign of 1 is 1. * Contestant says that the permutation is (1, 3, 4, 2, 6, 5). Submitted Solution: ``` import bisect import sys input = sys.stdin.readline n = int(input()) up = [] down = [] print(2, 1, 3, n) sys.stdout.flush() tmp = int(input()) print(tmp) ``` No
95,386
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. New Year is getting near. So it's time to change handles on codeforces. Mishka wants to change his handle but in such a way that people would not forget who he is. To make it work, he only allowed to change letters case. More formally, during one handle change he can choose any segment of his handle [i; i + l - 1] and apply tolower or toupper to all letters of his handle on this segment (more fomally, replace all uppercase letters with corresponding lowercase or vice versa). The length l is fixed for all changes. Because it is not allowed to change codeforces handle too often, Mishka can perform at most k such operations. What is the minimum value of min(lower, upper) (where lower is the number of lowercase letters, and upper is the number of uppercase letters) can be obtained after optimal sequence of changes? Input The first line of the input contains three integers n, k and l (1 ≀ n, k, l ≀ 10^6, l ≀ n) β€” the length of Mishka's handle, the number of changes and the length of the segment. The second line of the input contains one string s, consisting of n lowercase and uppercase Latin letters β€” Mishka's handle. Output Print one integer β€” the minimum value of min(lower, upper) after that Mishka change his handle at most k times in a way described in the problem statement. Examples Input 7 1 4 PikMike Output 0 Input 15 2 2 AaAaAAaaAAAAaaA Output 2 Input 14 2 6 aBcdEFGHIJklMn Output 0 Input 9 2 2 aAaAAAaaA Output 1 Submitted Solution: ``` n,k,l=map(int,input().split()) s=input() o=n u=['A'<=c<='Z' for c in s] #u=[0,0,0,1,1,0,0,1]*(n//8) d = [0] * (n+1) c = [0] * (n+1) for f in [lambda x:x, lambda x:1-x]: lo=0 hi=n for _ in range(50): test = (lo + hi)/2 d[0]=c[0]=0 for i in range(n): d[i+1]=d[i]+f(u[i]) c[i+1]=c[i] if i >= l-1 and d[i+1]>d[i+1-l]+test: d[i+1]=d[i+1-l]+test c[i+1]=c[i]+1 cost,count=d[n],c[n] if count<=k: out=cost-test*count hi=test else: lo=test o=min(o,out) print(max(0,round(o))) ``` No
95,387
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. New Year is getting near. So it's time to change handles on codeforces. Mishka wants to change his handle but in such a way that people would not forget who he is. To make it work, he only allowed to change letters case. More formally, during one handle change he can choose any segment of his handle [i; i + l - 1] and apply tolower or toupper to all letters of his handle on this segment (more fomally, replace all uppercase letters with corresponding lowercase or vice versa). The length l is fixed for all changes. Because it is not allowed to change codeforces handle too often, Mishka can perform at most k such operations. What is the minimum value of min(lower, upper) (where lower is the number of lowercase letters, and upper is the number of uppercase letters) can be obtained after optimal sequence of changes? Input The first line of the input contains three integers n, k and l (1 ≀ n, k, l ≀ 10^6, l ≀ n) β€” the length of Mishka's handle, the number of changes and the length of the segment. The second line of the input contains one string s, consisting of n lowercase and uppercase Latin letters β€” Mishka's handle. Output Print one integer β€” the minimum value of min(lower, upper) after that Mishka change his handle at most k times in a way described in the problem statement. Examples Input 7 1 4 PikMike Output 0 Input 15 2 2 AaAaAAaaAAAAaaA Output 2 Input 14 2 6 aBcdEFGHIJklMn Output 0 Input 9 2 2 aAaAAAaaA Output 1 Submitted Solution: ``` # 1279F - New Year And Handle Change # Great example of the "Aliens Trick" - DP optimization # dp[i] = max(dp[i-1] + s[i], (i + 1 - max(i-l+1, 0)) + dp[i-l] - lambda) def dp(i, table, l, s, theta): if i in table: return table[i] else: if i < 0: table[i] = [0, 0] return table[i] else: table[i] = [0, 0] a = dp(i-1, table, l, s, theta)[0] + int(s[i]) a_cnt = dp(i-1, table, l, s, theta)[1] b = dp(i-l, table, l, s, theta)[0] + \ (i + 1 - max(i-l+1, 0)) - theta b_cnt = dp(i-l, table, l, s, theta)[1] + 1 if a >= b: table[i][0], table[i][1] = a, a_cnt else: table[i][0], table[i][1] = b, b_cnt return table[i] def binary_search(n, k, l, s): low, high = 0, l+1 theta = 0 count = 0 while low < high: count += 1 theta = int((low+high)/2) dp_table = {} ans = dp(n-1, dp_table, l, s, theta) if ans[1] == k: return theta elif ans[1] > k: low = theta+1 else: high = theta # print(count) return low if __name__ == "__main__": inp = input().rstrip().split(" ") n, k, l = int(inp[0]), int(inp[1]), int(inp[2]) s = input().rstrip() s_lower = "" # maximize lowercase here, ie. the 1s s_upper = "" # maximize uppercase here, ie, the 1s for char in s: if char.islower(): s_lower += "1" s_upper += "0" else: s_lower += "0" s_upper += "1" theta = binary_search(n, k, l, s_upper) #print("theta = %d" % theta) table = {} ans = dp(n-1, table, l, s_upper, theta) # print(table) ans1 = n - (ans[0] + theta*k) theta = binary_search(n, k, l, s_lower) table = {} ans = dp(n-1, table, l, s_upper, theta) ans2 = n - (ans[0] + theta*k) ans = min(ans1, ans2) print(ans) ``` No
95,388
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. New Year is getting near. So it's time to change handles on codeforces. Mishka wants to change his handle but in such a way that people would not forget who he is. To make it work, he only allowed to change letters case. More formally, during one handle change he can choose any segment of his handle [i; i + l - 1] and apply tolower or toupper to all letters of his handle on this segment (more fomally, replace all uppercase letters with corresponding lowercase or vice versa). The length l is fixed for all changes. Because it is not allowed to change codeforces handle too often, Mishka can perform at most k such operations. What is the minimum value of min(lower, upper) (where lower is the number of lowercase letters, and upper is the number of uppercase letters) can be obtained after optimal sequence of changes? Input The first line of the input contains three integers n, k and l (1 ≀ n, k, l ≀ 10^6, l ≀ n) β€” the length of Mishka's handle, the number of changes and the length of the segment. The second line of the input contains one string s, consisting of n lowercase and uppercase Latin letters β€” Mishka's handle. Output Print one integer β€” the minimum value of min(lower, upper) after that Mishka change his handle at most k times in a way described in the problem statement. Examples Input 7 1 4 PikMike Output 0 Input 15 2 2 AaAaAAaaAAAAaaA Output 2 Input 14 2 6 aBcdEFGHIJklMn Output 0 Input 9 2 2 aAaAAAaaA Output 1 Submitted Solution: ``` n,k,l=map(int,input().split()) s=input() lo=0 hi=n#Allowed o=n u=['A'<=c<='Z' for c in s] #u=[0,0,0,1,1,0,0,1]*(n//8) d = [0] * (n+1) c = [0] * (n+1) for f in [lambda x:x, lambda x:1-x]: for _ in range(50): test = (lo + hi)/2 d[0]=c[0]=0 for i in range(n): d[i+1]=d[i]+f(u[i]) c[i+1]=c[i] if i >= l-1 and d[i+1]>d[i+1-l]+test: d[i+1]=d[i+1-l]+test c[i+1]=c[i]+1 cost,count=d[n],c[n] if count<=k: out=cost-test*k hi=test else: lo=test o=min(o,out) print(round(o)) ``` No
95,389
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. New Year is getting near. So it's time to change handles on codeforces. Mishka wants to change his handle but in such a way that people would not forget who he is. To make it work, he only allowed to change letters case. More formally, during one handle change he can choose any segment of his handle [i; i + l - 1] and apply tolower or toupper to all letters of his handle on this segment (more fomally, replace all uppercase letters with corresponding lowercase or vice versa). The length l is fixed for all changes. Because it is not allowed to change codeforces handle too often, Mishka can perform at most k such operations. What is the minimum value of min(lower, upper) (where lower is the number of lowercase letters, and upper is the number of uppercase letters) can be obtained after optimal sequence of changes? Input The first line of the input contains three integers n, k and l (1 ≀ n, k, l ≀ 10^6, l ≀ n) β€” the length of Mishka's handle, the number of changes and the length of the segment. The second line of the input contains one string s, consisting of n lowercase and uppercase Latin letters β€” Mishka's handle. Output Print one integer β€” the minimum value of min(lower, upper) after that Mishka change his handle at most k times in a way described in the problem statement. Examples Input 7 1 4 PikMike Output 0 Input 15 2 2 AaAaAAaaAAAAaaA Output 2 Input 14 2 6 aBcdEFGHIJklMn Output 0 Input 9 2 2 aAaAAAaaA Output 1 Submitted Solution: ``` s = input() _,k,l = [int(ss) for ss in s.split()] s = input() abc = "abcdefghijklmnopqrstuvwxyz" b = [0 if ss in abc else 1 for ss in s] cnt = 0 arr = [] for bb in b: if bb == 0: cnt += 1 else: if cnt > 0: arr.append(cnt) cnt = 0 else: if cnt > 0: arr.append(cnt) cnt = 0 arr = sorted(arr)[::-1] res = sum(b) for i,_ in enumerate(arr): while arr[i] > l and l > 0: res += k arr[i] -= k l -= 1 res = len(b) - res - sum(arr[:l]) print(res) ``` No
95,390
Provide tags and a correct Python 3 solution for this coding contest problem. One day in the IT lesson Anna and Maria learned about the lexicographic order. String x is lexicographically less than string y, if either x is a prefix of y (and x β‰  y), or there exists such i (1 ≀ i ≀ min(|x|, |y|)), that xi < yi, and for any j (1 ≀ j < i) xj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​. The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework. Input The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≀ k ≀ 105). Output Print the string Anna and Maria need β€” the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes). Examples Input aa 2 Output a Input abc 5 Output bc Input abab 7 Output b Note In the second sample before string "bc" follow strings "a", "ab", "abc", "b". Tags: brute force, constructive algorithms, hashing, implementation, string suffix structures, strings Correct Solution: ``` from collections import defaultdict def solve(): ss = list(input()) k = int(input()) n = len(ss) if n*(n+1)//2 < k: print ("No such line.") return kiss = defaultdict(int) for i,s in enumerate( ss ): kiss[s] += n-i alpha = 'abcdefghijklmnopqrstuvwxyz' ans = "" pos = [ i for i in range(n) ] while True: cur = "" for a in alpha: if kiss[a] >= k: cur = a break else: k -= kiss[a] # print(kiss['c']) ans += cur pos = [ i for i in pos if ss[i] == cur ] #single character if len(pos) >= k: # print("brok here", pos , k) break k -= len(pos) # get the next elements for a in alpha: kiss[a] = 0 nchar = [ (ss[i+1] , i+1) for i in pos if i+1 < n ] # print(pos , nchar) pos = [] for c,i in nchar: kiss[c] += n-i pos.append(i) print(ans) solve() ```
95,391
Provide tags and a correct Python 3 solution for this coding contest problem. One day in the IT lesson Anna and Maria learned about the lexicographic order. String x is lexicographically less than string y, if either x is a prefix of y (and x β‰  y), or there exists such i (1 ≀ i ≀ min(|x|, |y|)), that xi < yi, and for any j (1 ≀ j < i) xj = yj. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languages​​. The teacher gave Anna and Maria homework. She gave them a string of length n. They should write out all substrings of the given string, including the whole initial string, and the equal substrings (for example, one should write out the following substrings from the string "aab": "a", "a", "aa", "ab", "aab", "b"). The resulting strings should be sorted in the lexicographical order. The cunning teacher doesn't want to check all these strings. That's why she said to find only the k-th string from the list. Help Anna and Maria do the homework. Input The first line contains a non-empty string that only consists of small Latin letters ("a"-"z"), whose length does not exceed 105. The second line contains the only integer k (1 ≀ k ≀ 105). Output Print the string Anna and Maria need β€” the k-th (in the lexicographical order) substring of the given string. If the total number of substrings is less than k, print a string saying "No such line." (without the quotes). Examples Input aa 2 Output a Input abc 5 Output bc Input abab 7 Output b Note In the second sample before string "bc" follow strings "a", "ab", "abc", "b". Tags: brute force, constructive algorithms, hashing, implementation, string suffix structures, strings Correct Solution: ``` from heapq import * l=input() k=int(input()) n=len(l) if k>n*(n+1)/2: print("No such line.") quit() ss=[(l[i],i) for i in range(n)] heapify(ss) while k: k-=1 t=heappop(ss) if k==0: print(t[0]) else: if t[1]<n-1: heappush(ss,(t[0]+l[t[1]+1],t[1]+1)) # Made By Mostafa_Khaled ```
95,392
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` for _ in range(int(input())): n = int(input()) a = (list(map(int, input().split()))) l = len(a) if(l == 1): if(a[0]%2 == 0): print(1) print(1) else: print(-1) else: if(a[0]%2 == 0): print(1) print(1) elif((a[1])%2==0): print(1) print(2) else: print(2) print(1,2) ```
95,393
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` n = int(input()) for i in range(n): m = int(input()) l = list(map(int,input().split())) count = 0 flag = 0 for i in range(len(l)): if l[i]%2==0: flag = 1 count += 1 print(count) print(l.index(l[i])+1) break if flag==0: if len(l)==1: print(-1) elif len(l)>1: print(2) print(1,2) ```
95,394
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` from sys import stdin from collections import deque from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin, tan def ii(): return int(stdin.readline()) def fi(): return float(stdin.readline()) def mi(): return map(int, stdin.readline().split()) def fmi(): return map(float, stdin.readline().split()) def li(): return list(mi()) def lsi(): x=list(stdin.readline()) x.pop() return x def si(): return stdin.readline() ############# CODE STARTS HERE ############# for _ in range(ii()): n=ii() a=li() f=-1 for i in range(n): if not a[i]%2: f=i+1 if f==-1: if n>1: print(2) print(1, 2) else: print(f) else: print(1) print(f) ```
95,395
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` #!/bin/python3 t = int(input()) while t > 0: n = int(input()) array = list(map(int, input().split())) if n == 1: # 1 is 00000001 in binary , and 2 is 00000010 # for future reference 1 bitwise AND 2 is false # that's a fancy way to say array[0] == 1 if array[0] & 1: print(-1) else: print("1\n1") else: # nb: every fucking odd number has 1 in the # very right digit in binary i.e. 3 is 00000011 # 5 is 00000101 and so on.... if (array[0] & 1) and (array[1] & 1): print("2\n1 2\n") else: print(1) if array[0] & 1: print(2) else: print(1) t -= 1 ```
95,396
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` #!/usr/bin/env python3 t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) odd = [] even = [] for k in range(n): if a[k] & 1: odd.append(k) else: even.append(k) if len(even): print(1) print(even[0] + 1) elif len(odd) >= 2: print(2) print(odd[0] + 1, odd[1] + 1) else: print(-1) ```
95,397
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) result1 = [] flag = False for s in range(len(arr)): if arr[s] % 2 == 0: print(1) print(s+1) flag = True break else: result1.append(s+1) if len(result1) == 2: break if flag: continue elif len(result1) == 2: print(2) for j in result1: print(j, end=' ') else: print(-1) ```
95,398
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values. Input The first line contains a single integer t (1 ≀ t ≀ 100), number of test cases to solve. Descriptions of t test cases follow. A description of each test case consists of two lines. The first line contains a single integer n (1 ≀ n ≀ 100), length of array a. The second line contains n integers a_1, a_2, …, a_n (1 ≀ a_i ≀ 100), elements of a. The given array a can contain equal values (duplicates). Output For each test case output -1 if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1 ≀ p_i ≀ n), indexes of the chosen elements. If there are multiple solutions output any of them. Example Input 3 3 1 4 3 1 15 2 3 5 Output 1 2 -1 2 1 2 Note There are three test cases in the example. In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even. In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution. In the third test case, the subset consisting of all array's elements has even sum. Tags: brute force, dp, greedy, implementation Correct Solution: ``` for case in range(int(input())): n = int(input()) a = list(map(int, input().split())) odd = -1 for i in range(n): if a[i] & 1 and odd == -1: odd = i elif a[i] & 1: print(2) print(odd + 1, i + 1) break else: print(1) print(i + 1) break else: print(-1) ```
95,399