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. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7. The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string. Input The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. Output Print the minimum number of steps modulo 109 + 7. Examples Input ab Output 1 Input aab Output 3 Note The first example: "ab" β†’ "bba". The second example: "aab" β†’ "abba" β†’ "bbaba" β†’ "bbbbaa". Submitted Solution: ``` n=input() i=0 while "ab" in n: n=n.replace("ab","bba") i+=1 print(i%(10**6+7)) ``` No
105,800
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7. The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string. Input The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. Output Print the minimum number of steps modulo 109 + 7. Examples Input ab Output 1 Input aab Output 3 Note The first example: "ab" β†’ "bba". The second example: "aab" β†’ "abba" β†’ "bbaba" β†’ "bbbbaa". Submitted Solution: ``` n = input() r = 0 c = 0 t = [] for i in range(len(n)): if n[i]=="a": c+=1 else: t.append(c) c = 0 for i in t: if i==1: r+=1 elif i>1: r+=i+1 print(r%(10**9+7)) ``` No
105,801
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7. The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string. Input The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. Output Print the minimum number of steps modulo 109 + 7. Examples Input ab Output 1 Input aab Output 3 Note The first example: "ab" β†’ "bba". The second example: "aab" β†’ "abba" β†’ "bbaba" β†’ "bbbbaa". Submitted Solution: ``` s=input() ans=0 j=0 for i in range(0,len(s)): if i>=j: cnt1=0 while i<len(s) and s[i]=='a': cnt1=cnt1+1 i=i+1 cnt2=0 while i<len(s) and s[i]=='b': cnt2=cnt2+1 i=i+1 j=i; if cnt1>0 and cnt2>0: ans=ans + cnt2 bb= cnt2*2 cnt1=cnt1-1 ans = ans + bb*(pow(2,cnt1,1000000007)-1) #print(ans) print(ans%1000000007) ``` No
105,802
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7. The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string. Input The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. Output Print the minimum number of steps modulo 109 + 7. Examples Input ab Output 1 Input aab Output 3 Note The first example: "ab" β†’ "bba". The second example: "aab" β†’ "abba" β†’ "bbaba" β†’ "bbbbaa". Submitted Solution: ``` s = input() r = 0 na = 0 for i in range(len(s)): if s[i] == 'a': na += 1 else: r += (2**na - 1)%1000000007 print(r) ``` No
105,803
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` import math name=['Sheldon','Leonard','Penny','Rajesh','Howard'] n=int(input()) for i in range(100000000): if math.floor(n/5)-(2**i-1)<2**i: h=i #print(h) print(name[math.ceil((n-5*(2**h-1))/2**h-1)]) exit() ```
105,804
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` n = int(input()) while(n>5): n = n-4 n = n/2 n = int(n) l = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] print(l[n-1]) ```
105,805
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` n = int(input()) s = 1+float(n)/5 import math k = math.ceil((math.log(s,2))) deta = n-5*(2**(k-1)-1) test = math.ceil(deta/(2**(k-1))) if test == 1: print("Sheldon") if test == 2: print("Leonard") if test == 3: print("Penny") if test == 4: print("Rajesh") if test == 5: print("Howard") ```
105,806
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` import sys class Scanner: def __init__(self): self.current_tokens = [] def remaining_tokens(self): return len(self.current_tokens) def nextline(self): assert self.remaining_tokens() == 0, "Reading next line with remaining tokens" return input() def nexttokens(self): return self.nextline().split() def nexttoken(self): if len(self.current_tokens) == 0: self.current_tokens = self.nexttokens() assert self.remaining_tokens() > 0, "Not enough tokens to parse." return self.current_tokens.pop(0) def nextints(self, n=-1): if n == -1: return list(map(int, self.nexttokens())) else: return (self.nextint() for i in range(n)) def nextint(self): return int(self.nexttoken()) def quit(): sys.exit(0) stdin = Scanner() nextint = stdin.nextint nextints = stdin.nextints nextline = stdin.nextline n = nextint() - 1 itr = 0 i = 0 r = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard'] while i <= n: for j in range(5): if n in range(i, i + pow(2, itr)): print(r[j]) quit() i += pow(2, itr) itr += 1 ```
105,807
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` import math def doubleCola(n: int) -> str: dictionary = { 1:'Sheldon', 2:'Leonard', 3:'Penny', 4:'Rajesh', 5:'Howard' } lowerBound = 1 upperBound = 5 currentNumber = 1 while n > upperBound: currentNumber *= 2 lowerBound = 1 + upperBound upperBound += 5 * currentNumber difference = lowerBound - 1 return dictionary.get(math.ceil((n-difference)/currentNumber)) def main(): n = int(input().strip()) print(doubleCola(n)) main() ```
105,808
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` # A. Double Cola # 82A names = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard'] n = int(input()) - 1 # print(f'n is initially {n}') r = 0 while n >= 5 * 2**r: # print() n -= 5 * 2**r # print(f'subtracting n by {5 * 2**r}') r += 1 # print(f'Now n is {n} and r is {r}') n //= 2**r # print(f'Since 2**r is {2**r} and r is {r}, changing n to {n}') assert(n < 5) print(names[n]) # print(names) ```
105,809
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` import math n = int(input()) for i in range(1, 30): if 5 * (2 ** (i - 1) - 1) < n <= 5 * (2 ** i - 1): k = i break man = ["null","Sheldon","Leonard","Penny","Rajesh","Howard"] c = math.ceil((n - 5 * (2 ** (k - 1) - 1)) / (2 ** (k - 1))) print(man[c]) ```
105,810
Provide tags and a correct Python 3 solution for this coding contest problem. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Tags: implementation, math Correct Solution: ``` from math import ceil d = {0: "Sheldon", 1: "Leonard", 2: "Penny", 3: "Rajesh", 4: "Howard"} n = int(input()) i = 1 while n > i*5: n -= i*5 i *= 2 print(d[ceil(n/i)-1]) ```
105,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` a=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] n=int(input()) n-=1 while(n>=5): n=(n-5)//2 print(a[n]) ``` Yes
105,812
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` import math n =int(input()) a=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] if n<=5: print(a[n-1]) else: sum=5 z=0 while(sum<n): z+=1 sum+=2**z*5 # # print(z) # if(n>=2**(z)*5): # else: # k=n-2**(z-1)*5 # print(sum,z) k=n-sum+(2**(z)*5) # print(k) l=math.ceil(k/2**(z)) # print(l) print(a[l-1]) ``` Yes
105,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` from collections import deque def f(n): q = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] while n >5: if n%2 == 1: n -= 5 n //= 2 else: n -=4 n //=2 return q[n-1] n = int(input()) print(f(n)) ``` Yes
105,814
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` # WHERE: https://codeforces.com/problemset/page/8?order=BY_RATING_ASC # Taxi # https://codeforces.com/problemset/problem/158/B # Input # The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group. # Output # Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. # ignoreInput = input() # groups = list(map(int, input().split())) # i = 0 # j = len(groups) - 1 # last position of the array # counter = 0 # counters = [0, 0, 0, 0] # for group in groups: # counters[(group-1)] += 1 # fours = counters[3] # threes = counters[2] # ones = 0 # if counters[0] > threes: # ones = counters[0] - threes # twos = (counters[1]//2) + (((counters[1] % 2)*2+ones)//4) # # left = 0 # if (((counters[1] % 2)*2+ones) % 4) != 0: # twos += 1 # print(fours+threes+twos) # --------------------------------------------------------------------------------------------------------------------- # Fancy Fence # https://codeforces.com/problemset/problem/270/A # Input # The first line of input contains an integer t (0 < t < 180) β€” the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) β€” the angle the robot can make corners at measured in degrees. # Output # For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. # times = int(input()) # answers = [] # for time in range(times): # a = int(input()) # if 360 % (180 - a) == 0: # answers.append("YES") # else: # answers.append("NO") # for answer in answers: # print(answer) # --------------------------------------------------------------------------------------------------------------------- # Interesting drink # https://codeforces.com/problemset/problem/706/B # Input # The first line of the input contains a single integer n (1 ≀ n ≀ 100 000) β€” the number of shops in the city that sell Vasiliy's favourite drink. # The second line contains n integers xi (1 ≀ xi ≀ 100 000) β€” prices of the bottles of the drink in the i-th shop. # The third line contains a single integer q (1 ≀ q ≀ 100 000) β€” the number of days Vasiliy plans to buy the drink. # Then follow q lines each containing one integer mi (1 ≀ mi ≀ 109) β€” the number of coins Vasiliy can spent on the i-th day. # Output # Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day. # nShops = int(input()) # shopPrices = list(map(int, input().split())) # shopPrices.sort() # times = int(input()) # answers = [] # def binarySearch(array, target, carry): # index = len(array) # if len(array) == 0: # return carry # if index == 1: # if target < array[0]: # return carry # else: # return carry + 1 # # position in the middle # index = index//2 # if target < array[index]: # # return the left # newPrices = array[0:index] # return binarySearch(newPrices, target, carry) # else: # # return the right # carry += (index) # newPrices = array[index:] # return binarySearch(newPrices, target, carry) # def iterativeBinary(array, target): # low = 0 # high = len(array) - 1 # while (low <= high): # mid = low + ((high-low)//2) # if array[mid] > target: # high = mid - 1 # else: # low = mid + 1 # return low # for time in range(times): # money = int(input()) # # looks like the way i implemented the binary search isnt logN :( # # buys = binarySearch(shopPrices, money, 0) # buys = iterativeBinary(shopPrices, money) # answers.append(buys) # for answer in answers: # print(answer) # --------------------------------------------------------------------------------------------------------------------- # A and B and Compilation Errors # https://codeforces.com/problemset/problem/519/B # Output # Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. # compilationTimes = int(input()) # errors1 = list(map(int, input().split())) # errors2 = list(map(int, input().split())) # errors3 = list(map(int, input().split())) # errors1.sort() # errors2.sort() # errors3.sort() # n = -1 # isNFound = False # m = 1 # isMFound = False # for time in range(compilationTimes): # if isNFound and isMFound: # break # if not isNFound: # if time < len(errors2): # if errors1[time] != errors2[time]: # n = errors1[time] # isNFound = True # else: # n = errors1[time] # isNFound = True # if not isMFound: # if time < len(errors3): # if errors2[time] != errors3[time]: # m = errors2[time] # isMFound = True # else: # m = errors2[time] # isNFound = True # print(n) # print(m) # --------------------------------------------------------------------------------------------------------------------- target = int(input()) people = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] target -= 1 k = 0 while True: if 5 * (2**k - 1) > target: break k += 1 k -= 1 # print(k) # print((5 * (2**k - 1))) corrimiento = target - (5 * (2**k - 1)) realK = 2**(k) positionArray = (corrimiento)//realK # print(realK) # print(corrimiento) print(people[positionArray]) # --------------------------------------------------------------------------------------------------------------------- ``` Yes
105,815
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` n = int(input()) k = 1 max = 0 while True: max = max + 2**k * 5 min = max - (2**k * 5) if min <= n <= max: break k += 1 if (n - min) % 2**k == 0: who = (n - min) // 2**k elif (n - min) % 2**k != 0: who = ((n - min) // 2**k) + 1 if who == 1: print("Sheldon") elif who == 2: print("Leonard") elif who == 3: print("Penny") elif who == 4: print("Rajesh") elif who == 5: print("Howard" ) ``` No
105,816
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` n = int(input()) text = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] while n > len(text): n -= len(text) print(text[n - 1]) ``` No
105,817
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` import sys import math import os names=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] n=int(input()) k=1 cur=5*k while cur < n: k+=1 cur+=5*k #print(cur) n-=(cur-k*5) #print(n,k) #print(int(n/k)) delta=0 if n%k>0: delta=1 print(names[int(n/k)+delta-1]) ``` No
105,818
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the n-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input The input data consist of a single integer n (1 ≀ n ≀ 109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Print the single line β€” the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Examples Input 1 Output Sheldon Input 6 Output Sheldon Input 1802 Output Penny Submitted Solution: ``` ans=["Sheldon", "Leonard", "Penny", "Rajesh" ,"Howard"] x=int(input()) cur=int(1) while cur*5<=x: x-=(cur*5) cur*=2 print(ans[x%5-1]) ``` No
105,819
Provide tags and a correct Python 3 solution for this coding contest problem. Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and add <image> to the list. The player who can not make a valid choice of p and k loses. Mojtaba starts the game and the players alternatively make moves. Determine which one of players will be the winner if both players play optimally. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of elements in the list. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the list. Output If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes). You can print each letter in any case (upper or lower). Examples Input 4 1 1 1 1 Output Arpa Input 4 1 1 17 17 Output Mojtaba Input 4 1 1 17 289 Output Arpa Input 5 1 2 3 4 5 Output Arpa Note In the first sample test, Mojtaba can't move. In the second sample test, Mojtaba chooses p = 17 and k = 1, then the list changes to [1, 1, 1, 1]. In the third sample test, if Mojtaba chooses p = 17 and k = 1, then Arpa chooses p = 17 and k = 1 and wins, if Mojtaba chooses p = 17 and k = 2, then Arpa chooses p = 17 and k = 1 and wins. Tags: bitmasks, dp, games Correct Solution: ``` import sys input = sys.stdin.buffer.readline from collections import Counter games = Counter() # prime : bitmask of if that power of the prime exists def add_primes(a): i = 2 while i*i <= a: cnt = 0 while a % i == 0: a //= i cnt += 1 if cnt: games[i] |= 1 << cnt i += 1 if a != 1: games[a] |= 1 << 1 def mex(a): i = 0 while True: if i not in a: return i i += 1 grundy_val = {} def grundy_value(mask): if mask in grundy_val: return grundy_val[mask] else: transition_masks = set() k = 1 while 1<<k <= mask: new_mask = (mask&((1<<k)-1))|(mask>>k) transition_masks.add(grundy_value(new_mask)) k += 1 grundy_val[mask] = mex(transition_masks) return grundy_val[mask] n = int(input()) a = list(map(int,input().split())) for i in a: add_primes(i) xor_sum = 0 for game in games.values(): grundy_val = {} xor_sum ^= grundy_value(game) if xor_sum: print("Mojtaba") else: print("Arpa") ```
105,820
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and add <image> to the list. The player who can not make a valid choice of p and k loses. Mojtaba starts the game and the players alternatively make moves. Determine which one of players will be the winner if both players play optimally. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of elements in the list. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the list. Output If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes). You can print each letter in any case (upper or lower). Examples Input 4 1 1 1 1 Output Arpa Input 4 1 1 17 17 Output Mojtaba Input 4 1 1 17 289 Output Arpa Input 5 1 2 3 4 5 Output Arpa Note In the first sample test, Mojtaba can't move. In the second sample test, Mojtaba chooses p = 17 and k = 1, then the list changes to [1, 1, 1, 1]. In the third sample test, if Mojtaba chooses p = 17 and k = 1, then Arpa chooses p = 17 and k = 1 and wins, if Mojtaba chooses p = 17 and k = 2, then Arpa chooses p = 17 and k = 1 and wins. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) b=[] c=[] e=[] ans = 0 for i in range(30): e.append(0) j=2 if (j == 2): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=1 for i in range(30): e[i]=0 if (j==3): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(20): e[i]=0 if (j==5): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(20): e[i]=0 if (j==7): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(20): e[i]=0 while (j< 31700): for i in range(11): e[i]=0 for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(11): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(n): if a[i]!=1: ans=ans^1 for j in range(i,n): if a[i]==a[j]: a[j]=1 a[i]=1 if (ans !=0): print("Mojtaba") else: print("Arpa") ``` No
105,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and add <image> to the list. The player who can not make a valid choice of p and k loses. Mojtaba starts the game and the players alternatively make moves. Determine which one of players will be the winner if both players play optimally. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of elements in the list. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the list. Output If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes). You can print each letter in any case (upper or lower). Examples Input 4 1 1 1 1 Output Arpa Input 4 1 1 17 17 Output Mojtaba Input 4 1 1 17 289 Output Arpa Input 5 1 2 3 4 5 Output Arpa Note In the first sample test, Mojtaba can't move. In the second sample test, Mojtaba chooses p = 17 and k = 1, then the list changes to [1, 1, 1, 1]. In the third sample test, if Mojtaba chooses p = 17 and k = 1, then Arpa chooses p = 17 and k = 1 and wins, if Mojtaba chooses p = 17 and k = 2, then Arpa chooses p = 17 and k = 1 and wins. Submitted Solution: ``` n=int(input()) a= [int(x) for x in input().split(' ')] if a[-1] in [17,10]: print("Mojtaba") else: print("Arpa") ``` No
105,822
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and add <image> to the list. The player who can not make a valid choice of p and k loses. Mojtaba starts the game and the players alternatively make moves. Determine which one of players will be the winner if both players play optimally. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of elements in the list. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the list. Output If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes). You can print each letter in any case (upper or lower). Examples Input 4 1 1 1 1 Output Arpa Input 4 1 1 17 17 Output Mojtaba Input 4 1 1 17 289 Output Arpa Input 5 1 2 3 4 5 Output Arpa Note In the first sample test, Mojtaba can't move. In the second sample test, Mojtaba chooses p = 17 and k = 1, then the list changes to [1, 1, 1, 1]. In the third sample test, if Mojtaba chooses p = 17 and k = 1, then Arpa chooses p = 17 and k = 1 and wins, if Mojtaba chooses p = 17 and k = 2, then Arpa chooses p = 17 and k = 1 and wins. Submitted Solution: ``` def prime_factors(n): i = 2 while i * i <= n: if n % i: i += 1 else: n //= i yield i if n > 1: yield n from bisect import bisect def move_generator(p): for i in range(p.bit_length()): yield (p & ((1 << i) - 1)) | (p >> (i+1)) def helper(L): memo = {0:False} def rec(P): try: return memo[P] except KeyError: return not all(rec(Q) for Q in move_generator(P)) return rec(L) from collections import defaultdict from itertools import chain memo = defaultdict(set) n = int(input()) for a in map(int,input().split()): f = list(prime_factors(a)) p = 1 c = 0 for x in f: if x == p: c += 1 else: memo[p].add(c) p = x c = 1 memo[p].add(c) del memo[1] def convert(s): b = 0 for i in s: b |= 1 << i-1 return b c = 0 for s in memo.values(): c += helper(convert(s)) print('Mojtaba' if c%2 else 'Arpa') ``` No
105,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and add <image> to the list. The player who can not make a valid choice of p and k loses. Mojtaba starts the game and the players alternatively make moves. Determine which one of players will be the winner if both players play optimally. Input The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of elements in the list. The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 109) β€” the elements of the list. Output If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes). You can print each letter in any case (upper or lower). Examples Input 4 1 1 1 1 Output Arpa Input 4 1 1 17 17 Output Mojtaba Input 4 1 1 17 289 Output Arpa Input 5 1 2 3 4 5 Output Arpa Note In the first sample test, Mojtaba can't move. In the second sample test, Mojtaba chooses p = 17 and k = 1, then the list changes to [1, 1, 1, 1]. In the third sample test, if Mojtaba chooses p = 17 and k = 1, then Arpa chooses p = 17 and k = 1 and wins, if Mojtaba chooses p = 17 and k = 2, then Arpa chooses p = 17 and k = 1 and wins. Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) b=[] c=[] e=[] ans = 0 for i in range(30): e.append(0) j=2 if (j == 2): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=1 for i in range(30): e[i]=0 if (j==3): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(20): e[i]=0 if (j==5): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(20): e[i]=0 if (j==7): for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(30): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(20): e[i]=0 while (j< 31623): for i in range(10): e[i]=0 for i in range(n): l=0 while a[i] % j == 0: a[i]=a[i]/j l+=1 if (l!=0): e[l]=1 k=0 for i in range(10): if (e[i]==1): ans=ans^(i-k) k=i j+=2 for i in range(n): if a[i]!=1: ans=ans^1 for j in range(i,n): if a[i]==a[j]: a[j]=1 a[i]=1 if (ans !=0): print("Mojtaba") else: print("Arpa") ``` No
105,824
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alexey recently held a programming contest for students from Berland. n students participated in a contest, i-th of them solved ai problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree, or won't receive any diplomas at all. Let cntx be the number of students that are awarded with diplomas of degree x (1 ≀ x ≀ 3). The following conditions must hold: * For each x (1 ≀ x ≀ 3) cntx > 0; * For any two degrees x and y cntx ≀ 2Β·cnty. Of course, there are a lot of ways to distribute the diplomas. Let bi be the degree of diploma i-th student will receive (or - 1 if i-th student won't receive any diplomas). Also for any x such that 1 ≀ x ≀ 3 let cx be the maximum number of problems solved by a student that receives a diploma of degree x, and dx be the minimum number of problems solved by a student that receives a diploma of degree x. Alexey wants to distribute the diplomas in such a way that: 1. If student i solved more problems than student j, then he has to be awarded not worse than student j (it's impossible that student j receives a diploma and i doesn't receive any, and also it's impossible that both of them receive a diploma, but bj < bi); 2. d1 - c2 is maximum possible; 3. Among all ways that maximize the previous expression, d2 - c3 is maximum possible; 4. Among all ways that correspond to the two previous conditions, d3 - c - 1 is maximum possible, where c - 1 is the maximum number of problems solved by a student that doesn't receive any diploma (or 0 if each student is awarded with some diploma). Help Alexey to find a way to award the contestants! Input The first line contains one integer number n (3 ≀ n ≀ 3000). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 5000). Output Output n numbers. i-th number must be equal to the degree of diploma i-th contestant will receive (or - 1 if he doesn't receive any diploma). If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists. Examples Input 4 1 2 3 4 Output 3 3 2 1 Input 6 1 4 3 1 1 2 Output -1 1 2 -1 -1 3 Submitted Solution: ``` print("-1 3 2 1") ``` No
105,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alexey recently held a programming contest for students from Berland. n students participated in a contest, i-th of them solved ai problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree, or won't receive any diplomas at all. Let cntx be the number of students that are awarded with diplomas of degree x (1 ≀ x ≀ 3). The following conditions must hold: * For each x (1 ≀ x ≀ 3) cntx > 0; * For any two degrees x and y cntx ≀ 2Β·cnty. Of course, there are a lot of ways to distribute the diplomas. Let bi be the degree of diploma i-th student will receive (or - 1 if i-th student won't receive any diplomas). Also for any x such that 1 ≀ x ≀ 3 let cx be the maximum number of problems solved by a student that receives a diploma of degree x, and dx be the minimum number of problems solved by a student that receives a diploma of degree x. Alexey wants to distribute the diplomas in such a way that: 1. If student i solved more problems than student j, then he has to be awarded not worse than student j (it's impossible that student j receives a diploma and i doesn't receive any, and also it's impossible that both of them receive a diploma, but bj < bi); 2. d1 - c2 is maximum possible; 3. Among all ways that maximize the previous expression, d2 - c3 is maximum possible; 4. Among all ways that correspond to the two previous conditions, d3 - c - 1 is maximum possible, where c - 1 is the maximum number of problems solved by a student that doesn't receive any diploma (or 0 if each student is awarded with some diploma). Help Alexey to find a way to award the contestants! Input The first line contains one integer number n (3 ≀ n ≀ 3000). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 5000). Output Output n numbers. i-th number must be equal to the degree of diploma i-th contestant will receive (or - 1 if he doesn't receive any diploma). If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists. Examples Input 4 1 2 3 4 Output 3 3 2 1 Input 6 1 4 3 1 1 2 Output -1 1 2 -1 -1 3 Submitted Solution: ``` n = int(input()) a = [int(x) for x in input().split()] b = sorted(a) dip1 = {} dip2 = {} dip3 = {} ndip = {} first_value = 0 first_index = 2 for i in range(first_index, n): if b[i] - b[i-1] >= first_value: first_value = b[i] - b[i-1] first_index = i second_value = 0 second_index = 1 for i in range(second_index, first_index): if b[i] - b[i-1] >= second_value: second_value = b[i] - b[i-1] second_index = i third_value = 0 third_index = 0 for i in range(third_index, second_index): if i == 0: continue if b[i] - b[i-1] >= third_value: third_value = b[i] - b[i-1] third_index = i for i in range(0, third_index): if ndip.__contains__(b[i]): ndip[b[i]] += 1 else: ndip[b[i]] = 1 for i in range(third_index, second_index): if dip3.__contains__(b[i]): dip3[b[i]] += 1 else: dip3[b[i]] = 1 for i in range(second_index, first_index): if dip2.__contains__(b[i]): dip2[b[i]] += 1 else: dip2[b[i]] = 1 for i in range(first_index, n): if dip1.__contains__(b[i]): dip1[b[i]] += 1 else: dip1[b[i]] = 1 # print(first_index, second_index, third_index, ) # print(dip) # # print(a) for x in a: if ndip.__contains__(x) and ndip[x]: print('-1', end=' ') ndip[x] -= 1 elif dip1.__contains__(x) and dip1[x]: print('1', end=' ') dip1[x] -= 1 elif dip2.__contains__(x) and dip2[x]: print('2', end=' ') dip2[x] -= 1 elif dip3.__contains__(x) and dip3[x]: print('3', end=' ') dip3[x] -= 1 ``` No
105,826
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alexey recently held a programming contest for students from Berland. n students participated in a contest, i-th of them solved ai problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree, or won't receive any diplomas at all. Let cntx be the number of students that are awarded with diplomas of degree x (1 ≀ x ≀ 3). The following conditions must hold: * For each x (1 ≀ x ≀ 3) cntx > 0; * For any two degrees x and y cntx ≀ 2Β·cnty. Of course, there are a lot of ways to distribute the diplomas. Let bi be the degree of diploma i-th student will receive (or - 1 if i-th student won't receive any diplomas). Also for any x such that 1 ≀ x ≀ 3 let cx be the maximum number of problems solved by a student that receives a diploma of degree x, and dx be the minimum number of problems solved by a student that receives a diploma of degree x. Alexey wants to distribute the diplomas in such a way that: 1. If student i solved more problems than student j, then he has to be awarded not worse than student j (it's impossible that student j receives a diploma and i doesn't receive any, and also it's impossible that both of them receive a diploma, but bj < bi); 2. d1 - c2 is maximum possible; 3. Among all ways that maximize the previous expression, d2 - c3 is maximum possible; 4. Among all ways that correspond to the two previous conditions, d3 - c - 1 is maximum possible, where c - 1 is the maximum number of problems solved by a student that doesn't receive any diploma (or 0 if each student is awarded with some diploma). Help Alexey to find a way to award the contestants! Input The first line contains one integer number n (3 ≀ n ≀ 3000). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 5000). Output Output n numbers. i-th number must be equal to the degree of diploma i-th contestant will receive (or - 1 if he doesn't receive any diploma). If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists. Examples Input 4 1 2 3 4 Output 3 3 2 1 Input 6 1 4 3 1 1 2 Output -1 1 2 -1 -1 3 Submitted Solution: ``` n = int(input()) a = [int(x) for x in input().split()] b = sorted(a) dip = {} first_value = 0 first_index = 2 for i in range(first_index, n): if b[i] - b[i-1] >= first_value: first_value = b[i] - b[i-1] first_index = i second_value = 0 second_index = 1 for i in range(second_index, first_index): if b[i] - b[i-1] >= second_value: second_value = b[i] - b[i-1] second_index = i third_value = 0 third_index = 0 for i in range(third_index, second_index): if i == 0: continue if b[i] - b[i-1] >= third_value: third_value = b[i] - b[i-1] third_index = i for i in range(0, third_index): dip[b[i]] = -1 for i in range(third_index, second_index): dip[b[i]] = 3 for i in range(second_index, first_index): dip[b[i]] = 2 for i in range(first_index, n): dip[b[i]] = 1 # print(first_index, second_index, third_index, ) # print(dip) # # print(a) for x in a: print(dip[x], end=' ') ``` No
105,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alexey recently held a programming contest for students from Berland. n students participated in a contest, i-th of them solved ai problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree, or won't receive any diplomas at all. Let cntx be the number of students that are awarded with diplomas of degree x (1 ≀ x ≀ 3). The following conditions must hold: * For each x (1 ≀ x ≀ 3) cntx > 0; * For any two degrees x and y cntx ≀ 2Β·cnty. Of course, there are a lot of ways to distribute the diplomas. Let bi be the degree of diploma i-th student will receive (or - 1 if i-th student won't receive any diplomas). Also for any x such that 1 ≀ x ≀ 3 let cx be the maximum number of problems solved by a student that receives a diploma of degree x, and dx be the minimum number of problems solved by a student that receives a diploma of degree x. Alexey wants to distribute the diplomas in such a way that: 1. If student i solved more problems than student j, then he has to be awarded not worse than student j (it's impossible that student j receives a diploma and i doesn't receive any, and also it's impossible that both of them receive a diploma, but bj < bi); 2. d1 - c2 is maximum possible; 3. Among all ways that maximize the previous expression, d2 - c3 is maximum possible; 4. Among all ways that correspond to the two previous conditions, d3 - c - 1 is maximum possible, where c - 1 is the maximum number of problems solved by a student that doesn't receive any diploma (or 0 if each student is awarded with some diploma). Help Alexey to find a way to award the contestants! Input The first line contains one integer number n (3 ≀ n ≀ 3000). The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 5000). Output Output n numbers. i-th number must be equal to the degree of diploma i-th contestant will receive (or - 1 if he doesn't receive any diploma). If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists. Examples Input 4 1 2 3 4 Output 3 3 2 1 Input 6 1 4 3 1 1 2 Output -1 1 2 -1 -1 3 Submitted Solution: ``` n = int(input()) a = [int(x) for x in input().split()] b = sorted(a) dip1 = {} dip2 = {} dip3 = {} ndip = {} first_value = 0 first_index = 2 for i in range(first_index, n): if b[i] - b[i-1] >= first_value: first_value = b[i] - b[i-1] first_index = i second_value = 0 second_index = 1 for i in range(second_index, first_index): if b[i] - b[i-1] >= second_value: second_value = b[i] - b[i-1] second_index = i third_value = 0 third_index = 0 for i in range(third_index, second_index): if i == 0: continue if b[i] - b[i-1] >= third_value: third_value = b[i] - b[i-1] third_index = i for i in range(0, third_index): if ndip.__contains__(b[i]): ndip[b[i]] += 1 else: ndip[b[i]] = 1 for i in range(third_index, second_index): if dip3.__contains__(b[i]): dip3[b[i]] += 1 else: dip3[b[i]] = 1 for i in range(second_index, first_index): if dip2.__contains__(b[i]): dip2[b[i]] += 1 else: dip2[b[i]] = 1 for i in range(first_index, n): if dip1.__contains__(b[i]): dip1[b[i]] += 1 else: dip1[b[i]] = 1 # print(first_index, second_index, third_index, ) # print(dip) # # print(a) for i in range(n): if ndip.__contains__(a[i]) and ndip[a[i]]: print('-1', end=' ') ndip[a[i]] -= 1 elif dip1.__contains__(a[i]) and dip1[a[i]]: print('1', end=' ') dip1[a[i]] -= 1 elif dip2.__contains__(a[i]) and dip2[a[i]]: print('2', end=' ') dip2[a[i]] -= 1 elif dip3.__contains__(a[i]) and dip3[a[i]]: print('3', end=' ') dip3[a[i]] -= 1 ``` No
105,828
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` n = int(input()) largest = n + n - 1 possible = [0, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 999999999] maximum9 = 0 indx1 = 0 i = 0 for p in possible: if p <= largest and p > maximum9: maximum9 = p indx1 = i i += 1 indx2 = 0 for i in range(9): if largest >= i*10**indx1+maximum9: indx2 = i else: break count = 0 for i in range(indx2+1): count += max((2*min(n, i*10**indx1+maximum9-1)- max(1,i*10**indx1+maximum9)+1)//2, 0) print(count) ```
105,829
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` n=int(input()) import sys num9=len(str(2*n))-1 s=[str(i) for i in range(10)] ans=0 if(num9==0): print(n*(n-1)//2) sys.exit() for i in s: x=i+'9'*num9 x=int(x) ans+=max(0,min((n-x//2),x//2)) print(ans) ```
105,830
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` from math import * import sys #sys.stdin = open('in.txt') n = int(input()) def closest9(n): s = '9'*(len(str(n+1))-1) return 0 if len(s) == 0 else int(s) def solve(n): if n == 2: return 1 if n == 3: return 3 if n == 4: return 6 s = n+n-1 c = closest9(s) if c*10 + 9 == s: return 1 p = c res = 0 for i in range(10): if p <= n+1: res += p//2 elif p > s: break else: res += 1+(s - p)//2 #print(p, v) p += c+1 return res print(solve(n)) ```
105,831
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` n = int(input()) v = min(n, 5) if v < 5: print(n*(n - 1) // 2) exit() while v * 10 <= n: v *= 10 print(sum(min(n - i * v + 1, v * i - 1) for i in range(1, n // v + 1))) ```
105,832
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` n = int(input()) a= 5 while a * 10 <= n: a *= 10 print(sum(min(n - i * a + 1, a * i - 1) for i in range(1, n // a + 1)) if n>=5 else n*(n-1)//2) ```
105,833
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` def check9(x): i = len(x) - 1 while (i >= 0): if (x[i] != '9'): return len(x) - i - 1 i -= 1 return len(x) - i - 1 def solve(n): if (n < 5): return (n*(n-1)//2) res = 0 x = str(n+n-1) length = len(x) if (check9(x) == length): return 1 cur = '9'*(length-1) for i in range(9): c = str(i) p = int(c+cur) if (p <= n+1): res += p//2 elif (p > n+n-1): res += 0 else: res += 1 + (n + n - 1 - p)//2 return res n = int(input()) print(solve(n)) ```
105,834
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` n = int(input()) def length(obj): return len(str(obj)) def num_nine(num): i = 0 j = 9 while num >= j: i += 1 j += 9 * (10 ** i) return i def split(): blocks = (n + 1) // count extra = (n + 1) % count b = blocks // 2 f = blocks - b return [f, b, extra] def ans(): if nines == 0: return int(n * (n - 1) / 2) if n == 10 ** nines - 1: return n - (10 ** nines) // 2 if lent == nines: return n - (10 ** nines) // 2 + 1 ls = split() return ls[0] * ls[1] * count - ls[1] + ls[0] * ls[2] num = 2 * n - 1 lent = length(n) nines = num_nine(num) count = (10 ** nines) // 2 #print('length', lent) #print('nines', nines) print(ans()) ```
105,835
Provide tags and a correct Python 3 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?############################################################ def isPrime(x): for i in range(2, x): if i*i > x: break if (x % i == 0): return False return True #?############################################################ def ncr(n, r, p): num = den = 1 for i in range(r): num = (num * (n - i)) % p den = (den * (i + 1)) % p return (num * pow(den, p - 2, p)) % p #?############################################################ def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: l.append(int(i)) n = n / i if n > 2: l.append(n) return list(set(l)) #?############################################################ def power(x, y, p): res = 1 x = x % p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): res = (res * x) % p y = y >> 1 x = (x * x) % p return res #?############################################################ def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #?############################################################ def digits(n): c = 0 while (n > 0): n //= 10 c += 1 return c #?############################################################ def ceil(n, x): if (n % x == 0): return n//x return n//x+1 #?############################################################ def mapin(): return map(int, input().split()) #?############################################################ input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # python3 15.py<in>op n = int(input()) s = len(str(n)) if(n <5): print(n*(n-1)//2) elif(2*n == (10**s)-1): print(1) else: nn = 5 while n >= nn * 10: nn *= 10 # print(nn) ans = 0 temp = nn while temp <= n: ans += min(n - (temp-1), temp - 1) temp += nn # print(temp) print(ans) ```
105,836
Provide tags and a correct Python 2 solution for this coding contest problem. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Tags: constructive algorithms, math Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_num(): return int(raw_input()) def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ n=input() x=5 while x<=n: x*=10 x/=10 if n>=5: ans=0 for i in range(x-1,n,x): ans+=min(i,n-i) pr_num(ans) else: ans=(n*(n-1))/2 pr_num(ans) ```
105,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` from math import factorial as fac def solve(n): if n <= 4: return fac(n) // (2 * fac(n - 2)) m = n + (n - 1) x = '9' while(int(x + '9') <= m): x += '9' l = [] for i in range(10): if int(str(i) + x) <= m: l.append(int(str(i) + x)) res = 0 for p in l: y = min(p - 1, n) res += (y - (p - y) + 1) // 2 return res n = int(input()) print(solve(n)) ``` Yes
105,838
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` n = int(input()) if (n <= 4): print(int(n * (n - 1) / 2)) else: v = 9 dig = 10 x = n * 2 - 1 while (v + dig * 9 <= x): v += dig * 9 dig *= 10 ans = 0 f = True while (f): f = False y = v // 2 pairs = y - max(0, v - n - 1) if (pairs > 0): f = True ans += pairs v += dig if (n * 2 - 1 < v): break print(ans) ``` Yes
105,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` n = int(input()) max9 = 1 while (int('9' * max9) + 1) // 2 <= n: max9 += 1 max9 -= 1 k = 0 ans = 0 f = True while f: number = int(str(k) + '9' * max9) b = min(number - 1, n) a = number // 2 + 1 if a <= b: m = b - a + 1 ans += m k += 1 else: f = False if n == 2: print(1) elif n == 3: print(3) elif n == 4: print(6) else: print(ans) ``` Yes
105,840
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` from collections import Counter n=int(input()) if n<5: d={2:1,3:3,4:6} print(d[n]) exit() z=len(str(n//5)) nn=5*10**(z-1) n0=n-nn+1 if n0<nn: print(n0) elif n0==nn: print(n0-1) elif n0<=2*nn: print(n0-1) elif n0<3*nn: print(n0*2-2*nn-1) elif n0==3*nn: print(n0*2-2*nn-2) elif n0<=4*nn: print(n0*2-2*nn-2) elif n0<5*nn: print(n0*3-6*nn-2) elif n0==5*nn: print(n0*3-6*nn-3) elif n0<=6*nn: print(n0*3-6*nn-3) elif n0<7*nn: print(n0*4-12*nn-3) elif n0==8*nn: print(n0*4-12*nn-4) elif n0<=8*nn: print(n0*4-12*nn-4) elif n0<9*nn: print(n0*5-20*nn-4) elif n0==9*nn: print(n0*5-20*nn-5) ``` Yes
105,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` n=int(input()) list=[] 2<=n<=109 for i in range(1,n+1): for j in range(1,n+1): x = i + j if i!=j and x%10==9 and i<j: list.append(i) list.append(j) a=len(list) print(a//2) ``` No
105,842
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` t=1 #t=int(input()) for _ in range (t): n=int(input()) #n,k=map(int,input().split()) #a=list(map(int,input().split())) #b=list(map(int,input().split())) #s=input() #n=len(s) c=len(str(n)) limit=10**c-1 if limit==n: print((n+1)//2) continue #print(limit) if limit-n<n: ans=abs(limit-2*n)+1 print(ans//2) else: limit//=10 ans=(limit//2)+n-limit print(ans) ``` No
105,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` from math import log n = int(input()) if n<5: print((n*(n-1))//2) else: s = int(log(n//5)/log(10)) c = 5*10**s f = n//c+1 print((f//2)*((f+1)//2)*c-((f*c-n-1)*(f//2))-((n+1)//(10**(s+1)))) ``` No
105,844
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. Input The first line contains a single integer n (2 ≀ n ≀ 109) β€” the number of shovels in Polycarp's shop. Output Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≀ 109 the answer doesn't exceed 2Β·109. Examples Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 Note In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: * 2 and 7; * 3 and 6; * 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: * 1 and 8; * 2 and 7; * 3 and 6; * 4 and 5; * 5 and 14; * 6 and 13; * 7 and 12; * 8 and 11; * 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. Submitted Solution: ``` n=int(input()) if n<5: print(0) exit() s0=str(n+n-1) k=len(s0) if s0!=k*'9': k-=1 s=k*'9' def cnt(s): v=int(s) #print(v) if v>n*2-1: return 0 if v==2*n-1: return 1 if v>n: return n-v//2 if v<=n: return v//2 ans=cnt(s) for i in range(1,9): ans+=cnt(str(i)+s) print(ans) ``` No
105,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building! There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors. The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that: 1. Number x lies on the interval from li to ri inclusive (li ≀ x ≀ ri). 2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti. For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them. Input The first line contains numbers n and q (1 ≀ n, q ≀ 105). Next n lines contain pairs of numbers ai, bi (1 ≀ ai, bi ≀ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 ≀ li ≀ ri ≀ n, 0 ≀ ti ≀ 106). All input numbers are integers. Output For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line. Examples Input 5 4 4 1 3 5 6 2 3 5 6 5 1 5 2 1 3 5 1 1 0 1 5 0 Output 5 2 1 5 Input 5 4 6 1 5 1 2 5 4 3 6 1 2 4 1 3 4 5 1 4 5 1 2 0 Output 3 3 3 1 Submitted Solution: ``` from sys import stdin, stdout EPS = 10 ** (-20) def merge(ind): if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 0 elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2 + 1][0]) i = 0 j = 1 elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 1 else: tree[ind].append(tree[ind * 2 + 1][0]) i = 1 j = 1 time = 10 ** 6 + 6 while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]): t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) if t1 < t2: tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 else: tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 while i < len(tree[ind * 2]): if (tree[ind * 2][i][2] > tree[ind][-1][2] or tree[ind * 2][i][1] + tree[ind * 2][i][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time): tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 while j < len(tree[ind * 2 + 1]): if (tree[ind * 2 + 1][j][2] > tree[ind][-1][2] or tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time): tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]), tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 def get(l, r, lb, rb, ind, time): if l == lb and r == rb: l, r = -1, len(tree[ind]) while r - l > 1: m = (r + l) // 2 if tree[ind][m][0] <= time + EPS: l = m else: r = m if l == -1: return 0 else: return tree[ind][l] m = (lb + rb) // 2 first, second = 0, 0 if l <= m: first = get(l, min(m, r), lb, m, ind * 2, time) if r > m: second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time) if not first: return second elif not second: return first else: return max(second, first, key = lambda x: x[1] + x[2] * time) n, q = map(int, stdin.readline().split()) start = [] rise = [] for i in range(n): a, b = map(int, stdin.readline().split()) start.append(a) rise.append(b) power = 1 while power <= n: power *= 2 tree = [[] for i in range(power * 2)] for i in range(n): tree[power + i].append((0, start[i], rise[i], i + 1)) for i in range(power - 1, 0, -1): if not tree[i * 2]: tree[i] = tree[i * 2 + 1] elif not tree[i * 2 + 1]: tree[i] = tree[i * 2] else: merge(i) for i in range(q): l, r, t = map(int, stdin.readline().split()) stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n') ``` No
105,846
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building! There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors. The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that: 1. Number x lies on the interval from li to ri inclusive (li ≀ x ≀ ri). 2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti. For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them. Input The first line contains numbers n and q (1 ≀ n, q ≀ 105). Next n lines contain pairs of numbers ai, bi (1 ≀ ai, bi ≀ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 ≀ li ≀ ri ≀ n, 0 ≀ ti ≀ 106). All input numbers are integers. Output For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line. Examples Input 5 4 4 1 3 5 6 2 3 5 6 5 1 5 2 1 3 5 1 1 0 1 5 0 Output 5 2 1 5 Input 5 4 6 1 5 1 2 5 4 3 6 1 2 4 1 3 4 5 1 4 5 1 2 0 Output 3 3 3 1 Submitted Solution: ``` from sys import stdin, stdout from decimal import Decimal EPS = Decimal(10) ** Decimal(-30) def merge(ind): if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 0 elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2 + 1][0]) i = 0 j = 1 elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 1 else: tree[ind].append(tree[ind * 2 + 1][0]) i = 1 j = 1 time = Decimal(10 ** 6 + 6) while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]): t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) if t1 < t2: tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 else: tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 while i < len(tree[ind * 2]): if (tree[ind * 2][i][2] > tree[ind][-1][2] or tree[ind * 2][i][1] + tree[ind * 2][i][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time): tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 while j < len(tree[ind * 2 + 1]): if (tree[ind * 2 + 1][j][2] > tree[ind][-1][2] or tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time): tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]), tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 def get(l, r, lb, rb, ind, time): if l == lb and r == rb: l, r = -1, len(tree[ind]) while r - l > 1: m = (r + l) // 2 if tree[ind][m][0] <= time + EPS: l = m else: r = m if l == -1: return 0 else: return tree[ind][l] m = (lb + rb) // 2 first, second = 0, 0 if l <= m: first = get(l, min(m, r), lb, m, ind * 2, time) if r > m: second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time) if not first: return second elif not second: return first else: return max(second, first, key = lambda x: (x[1] + x[2] * time, x[2])) n, q = map(int, stdin.readline().split()) start = [] rise = [] for i in range(n): a, b = map(int, stdin.readline().split()) start.append(a) rise.append(b) power = 1 while power <= n: power *= 2 tree = [[] for i in range(power * 2)] for i in range(n): tree[power + i].append((Decimal(0), Decimal(start[i]), Decimal(rise[i]), i + 1)) for i in range(power - 1, 0, -1): if not tree[i * 2]: tree[i] = tree[i * 2 + 1] elif not tree[i * 2 + 1]: tree[i] = tree[i * 2] else: merge(i) for i in range(q): l, r, t = map(int, stdin.readline().split()) stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n') ``` No
105,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building! There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors. The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that: 1. Number x lies on the interval from li to ri inclusive (li ≀ x ≀ ri). 2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti. For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them. Input The first line contains numbers n and q (1 ≀ n, q ≀ 105). Next n lines contain pairs of numbers ai, bi (1 ≀ ai, bi ≀ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 ≀ li ≀ ri ≀ n, 0 ≀ ti ≀ 106). All input numbers are integers. Output For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line. Examples Input 5 4 4 1 3 5 6 2 3 5 6 5 1 5 2 1 3 5 1 1 0 1 5 0 Output 5 2 1 5 Input 5 4 6 1 5 1 2 5 4 3 6 1 2 4 1 3 4 5 1 4 5 1 2 0 Output 3 3 3 1 Submitted Solution: ``` from sys import stdin, stdout EPS = 10 ** (-20) def merge(ind): if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 0 elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2 + 1][0]) i = 0 j = 1 elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 1 else: tree[ind].append(tree[ind * 2 + 1][0]) i = 1 j = 1 time = 10 ** 6 + 6 while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]): t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) if t1 < t2: tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 else: tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 while i < len(tree[ind * 2]) and tree[ind * 2][i][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] <= tree[ind][-1][2] and tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 while i < len(tree[ind * 2]): if (tree[ind * 2][i][2] > tree[ind][-1][2] or tree[ind * 2][i][1] + tree[ind * 2][i][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time): tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 while j < len(tree[ind * 2 + 1]): if (tree[ind * 2 + 1][j][2] > tree[ind][-1][2] or tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time > tree[ind][-1][1] + tree[ind][-1][2] * time): tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]), tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 def get(l, r, lb, rb, ind, time): if l == lb and r == rb: l, r = -1, len(tree[ind]) while r - l > 1: m = (r + l) // 2 if tree[ind][m][0] <= time + EPS: l = m else: r = m if l == -1: return 0 else: return tree[ind][l] m = (lb + rb) // 2 first, second = 0, 0 if l <= m: first = get(l, min(m, r), lb, m, ind * 2, time) if r > m: second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time) if not first: return second elif not second: return first else: return max(second, first, key = lambda x: (x[1] + x[2] * time, x[2])) n, q = map(int, stdin.readline().split()) start = [] rise = [] for i in range(n): a, b = map(int, stdin.readline().split()) start.append(a) rise.append(b) power = 1 while power <= n: power *= 2 tree = [[] for i in range(power * 2)] for i in range(n): tree[power + i].append((0, start[i], rise[i], i + 1)) for i in range(power - 1, 0, -1): if not tree[i * 2]: tree[i] = tree[i * 2 + 1] elif not tree[i * 2 + 1]: tree[i] = tree[i * 2] else: merge(i) for i in range(q): l, r, t = map(int, stdin.readline().split()) stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n') ``` No
105,848
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building! There are n walruses taking part in the contest. Each walrus is given a unique number from 1 to n. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to 0, the height of the skyscraper i-th walrus is equal to ai. Each minute the i-th walrus finishes building bi floors. The journalists that are reporting from the spot where the Olympiad is taking place, make q queries to the organizers. Each query is characterized by a group of three numbers li, ri, ti. The organizers respond to each query with a number x, such that: 1. Number x lies on the interval from li to ri inclusive (li ≀ x ≀ ri). 2. The skyscraper of the walrus number x possesses the maximum height among the skyscrapers of all walruses from the interval [li, ri] at the moment of time ti. For each journalists' query print the number of the walrus x that meets the above-given criteria. If there are several possible answers, print any of them. Input The first line contains numbers n and q (1 ≀ n, q ≀ 105). Next n lines contain pairs of numbers ai, bi (1 ≀ ai, bi ≀ 109). Then follow q queries i the following format li, ri, ti, one per each line (1 ≀ li ≀ ri ≀ n, 0 ≀ ti ≀ 106). All input numbers are integers. Output For each journalists' query print the number of the walrus x that meets the criteria, given in the statement. Print one number per line. Examples Input 5 4 4 1 3 5 6 2 3 5 6 5 1 5 2 1 3 5 1 1 0 1 5 0 Output 5 2 1 5 Input 5 4 6 1 5 1 2 5 4 3 6 1 2 4 1 3 4 5 1 4 5 1 2 0 Output 3 3 3 1 Submitted Solution: ``` from sys import stdin, stdout EPS = 10 ** (-20) def merge(ind): if tree[ind * 2][0][1] > tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 0 elif tree[ind * 2][0][1] < tree[ind * 2 + 1][0][1]: tree[ind].append(tree[ind * 2 + 1][0]) i = 0 j = 1 elif tree[ind * 2][0][2] > tree[ind * 2 + 1][0][2]: tree[ind].append(tree[ind * 2][0]) i = 1 j = 1 else: tree[ind].append(tree[ind * 2 + 1][0]) i = 1 j = 1 while i < len(tree[ind * 2]) and (tree[ind * 2][i][2] - tree[ind][-1][2]): time = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]) + 5 if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 else: break while j < len(tree[ind * 2 + 1]) and (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]): time = (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) + 5 if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 else: break while i < len(tree[ind * 2]) and j < len(tree[ind * 2 + 1]): t1, t2 = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2] + EPS), (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2] + EPS) if t1 < t2: tree[ind].append((t1, tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 else: tree[ind].append((t2, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 while i < len(tree[ind * 2]) and (tree[ind * 2][i][2] - tree[ind][-1][2]): time = (tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2]) + 5 if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2][i][1] + tree[ind * 2][i][2] * time: i += 1 else: break while j < len(tree[ind * 2 + 1]) and (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]): time = (tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) + 5 if tree[ind][-1][1] + tree[ind][-1][2] * time >= tree[ind * 2 + 1][j][1] + tree[ind * 2 + 1][j][2] * time: j += 1 else: break while i < len(tree[ind * 2]) and tree[ind * 2][i][2] > tree[ind][-1][2]: tree[ind].append(((tree[ind][-1][1] - tree[ind * 2][i][1]) / (tree[ind * 2][i][2] - tree[ind][-1][2] + EPS), tree[ind * 2][i][1], tree[ind * 2][i][2], tree[ind * 2][i][3])) i += 1 while j < len(tree[ind * 2 + 1]) and tree[ind * 2 + 1][j][2] > tree[ind][-1][2]: tree[ind].append(((tree[ind][-1][1] - tree[ind * 2 + 1][j][1]) / (tree[ind * 2 + 1][j][2] - tree[ind][-1][2]) + EPS, tree[ind * 2 + 1][j][1], tree[ind * 2 + 1][j][2], tree[ind * 2 + 1][j][3])) j += 1 def get(l, r, lb, rb, ind, time): if l == lb and r == rb: l, r = -1, len(tree[ind]) while r - l > 1: m = (r + l) // 2 if tree[ind][m][0] <= time + EPS: l = m else: r = m if l == -1: return 0 else: return tree[ind][l] m = (lb + rb) // 2 first, second = 0, 0 if l <= m: first = get(l, min(m, r), lb, m, ind * 2, time) if r > m: second = get(max(l, m + 1), r, m + 1, rb, ind * 2 + 1, time) if not first: return second elif not second: return first else: return max(second, first, key = lambda x: x[1] + x[2] * time) n, q = map(int, stdin.readline().split()) start = [] rise = [] for i in range(n): a, b = map(int, stdin.readline().split()) start.append(a) rise.append(b) power = 1 while power <= n: power *= 2 tree = [[] for i in range(power * 2)] for i in range(n): tree[power + i].append((0, start[i], rise[i], i + 1)) for i in range(power - 1, 0, -1): if not tree[i * 2]: tree[i] = tree[i * 2 + 1] elif not tree[i * 2 + 1]: tree[i] = tree[i * 2] else: merge(i) for i in range(q): l, r, t = map(int, stdin.readline().split()) stdout.write(str(get(l, r, 1, power, 1, t)[3]) + '\n') ``` No
105,849
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` import itertools import operator from bisect import bisect def main(): N = int(input()) V = tuple(map(int, input().split())) T = tuple(map(int, input().split())) templ = [0] + list(itertools.accumulate(T, operator.add)) M = [0] * (N + 2) lost = M[:] for j, v in enumerate(V): i = bisect(templ, v + templ[j]) M[i] += v + templ[j] - templ[i-1] lost[i] += 1 F = [0] * (N + 1) for i in range(N): F[i+1] += F[i] + 1 - lost[i+1] print(*[F[i] * T[i-1] + M[i] for i in range(1, N + 1)], sep=' ') main() ```
105,850
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) N = int(input()) V = alele() T= alele() B = [0] + list(accumulate(T)) Ans1 = [0]*(N+2) Ans2 = [0]*(N+2) #print(B) for i in range(N): x = V[i] if T[i] < V[i]: a = bisect.bisect_left(B,x + B[i]) #print(x+B[i],a) Ans2[i] += 1 #print(i,a) Ans2[a-1] -= 1 if T[i] < V[i]: z = B[a-1] - B[i] zz = V[i] -z Ans1[a-1] +=zz #print(zz) #print(Ans2) #print(Ans1) else: Ans1[i] += V[i] C = list(accumulate(Ans2)) #print(C) #print(Ans1) for i in range(N): print((C[i]*T[i]) + Ans1[i],end = ' ') ```
105,851
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` import heapq heap = [] n = int(input()) V = list(map(int, input().split())) T = list(map(int, input().split())) tmp = 0 for i in range(n): ans = 0 heapq.heappush(heap, tmp+V[i]) while len(heap) and heap[0]<=tmp+T[i]: ans += heapq.heappop(heap)-tmp tmp += T[i] ans += T[i]*len(heap) print(ans, end=' ') ```
105,852
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` n = int(input()) import heapq as hq heap = [] # total = 0 temp = 0 ans = [-1 for _ in range(n)] volumes = [int(x) for x in input().split()] temps = [int(x) for x in input().split()] # prevtemp = 0 for i in range(n): # hq.heappush(heap, volumes[i]) prevtemp = temp temp += temps[i] hq.heappush(heap, volumes[i] + prevtemp) # total += 1 curr = 0 while len(heap) and heap[0] <= temp: m = hq.heappop(heap) curr += m - prevtemp curr += (len(heap) * temps[i]) ans[i] = curr print(' '.join([str(x) for x in ans])) ```
105,853
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` # import sys # from io import StringIO # # sys.stdin = StringIO(open(__file__.replace('.py', '.in')).read()) def bin_search_base(arr, val, base_index): lo = base_index hi = len(arr) - 1 while lo < hi: if hi - lo == 1 and arr[lo] - arr[base_index] < val < arr[hi] - arr[base_index]: return lo if val >= arr[hi] - arr[base_index]: return hi c = (hi + lo) // 2 if val < arr[c] - arr[base_index]: hi = c elif val > arr[c] - arr[base_index]: lo = c else: return c return lo n = int(input()) volumes = list(map(int, input().split())) temps = list(map(int, input().split())) temp_prefix = [0] for i in range(n): temp_prefix.append(temps[i] + temp_prefix[i]) gone_count = [0] * (n + 1) remaining_count = [0] * n gone_volume = [0] * (n + 1) for i in range(n): j = bin_search_base(temp_prefix, volumes[i], i) gone_count[j] += 1 gone_volume[j] += volumes[i] - (temp_prefix[j] - temp_prefix[i]) for i in range(n): remaining_count[i] = 1 + remaining_count[i-1] - gone_count[i] for i in range(n): gone_volume[i] += remaining_count[i] * temps[i] print(' '.join(map(str, gone_volume[:n]))) ```
105,854
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` import heapq n = int(input()) V = list(map(int, input().split())) T = list(map(int, input().split())) a = [] ans = [] tmp = 0 for i in range(0, n): heapq.heappush(a, tmp + V[i]) tmpAns = 0 while(len(a) and a[0] <= tmp + T[i]): tmpAns += heapq.heappop(a) - tmp tmpAns += len(a) * T[i] ans.append(tmpAns) tmp += T[i] print(" ".join(map(str,ans))) ```
105,855
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` n = int(input()) vs = [int(x) for x in input().split()] ts = [int(x) for x in input().split()] from heapq import * q = [] heapify(q) sts = ts[:] for i in range(1, n): sts[i] += sts[i-1] res = [] for i in range(n): v = vs[i] t = ts[i] v += sts[i] - ts[i] heappush(q, v) minv = heappop(q) count = 0 while minv <= sts[i]: count += minv - sts[i] + ts[i] if not q: break minv = heappop(q) else: heappush(q, minv) res.append(count + len(q) * t) print(" ".join(map(str, res))) ```
105,856
Provide tags and a correct Python 3 solution for this coding contest problem. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Tags: binary search, data structures Correct Solution: ``` from itertools import accumulate from bisect import bisect n = int(input()) vs = list(map(int, input().split())) ts = list(map(int, input().split())) fully_melt = [0] * n result = [0] * n dprint = lambda *args: None #dprint = print ts_accum = list(accumulate(ts)) dprint('ts_accum', ts_accum) for i, v in enumerate(vs): offset = ts_accum[i - 1] if i > 0 else 0 p = bisect(ts_accum, v + offset, lo=i) dprint('i = ', i, ', p =', p, ', offset = ', offset) if p < n: fully_melt[p] += 1 result[p] -= ts_accum[p] - v - offset dprint('fully_melt', fully_melt) dprint('result', result) multiplier = 1 for i, t in enumerate(ts): dprint('i =', i, ', mult =', multiplier) result[i] += t * multiplier multiplier += 1 - fully_melt[i] print(' '.join(str(r) for r in result)) ```
105,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` import configparser import math import sys input = sys.stdin.readline def get(l, r, cumsum): res = cumsum[r] if l >= 1: res -= cumsum[l-1] return res def can(l, r, cumsum, am): return am >= get(l, r, cumsum) def main(): n = int(input()) v = [int(x) for x in input().split(' ')] t = [int(x) for x in input().split(' ')] cumsum = [0 for i in range(n)] cumsum[0] = t[0] for i in range(1, n): cumsum[i] = t[i] + cumsum[i-1] ans = [0 for i in range(n)] alive = [[] for i in range(n)] for i in range(n): pos = i-1 for j in range(25, -1, -1): jump = 2**j if pos+jump < n and can(i, pos+jump, cumsum, v[i]): pos += jump if pos == i - 1: alive[i].append(v[i]) else: ans[i] += 1 if pos + 1 < n: ans[pos+1] -= 1 if pos != n-1 and v[i] > get(i, pos, cumsum): alive[pos+1].append(v[i] - get(i, pos, cumsum)) for i in range(1, n): ans[i] += ans[i-1] res = [0 for i in range(n)] for i in range(n): res[i] = ans[i]*t[i] for j in alive[i]: res[i] += j for i in res: print(i, end=' ') if __name__ == '__main__': main() ``` Yes
105,858
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` from sys import stdin def binary_search(l, r, val): global prefix i, j = l, r while i < j: mid = (i + j) // 2 ptr = prefix[mid] if ptr <= val: i = mid + 1 else: j = mid return i n = int(stdin.buffer.readline()) V = list(map(int, stdin.buffer.readline().split())) T = list(map(int, stdin.buffer.readline().split())) cnt = [0] * (n + 1) res = [0] * (n + 1) prefix = [0] * (n + 1) for i in range(n): if i == 0: prefix[i] = T[i] else: prefix[i] = prefix[i - 1] + T[i] for i in range(n): id = None if i == 0: id = binary_search(i, n - 1, V[i]) else: id = binary_search(i, n - 1, V[i] + prefix[i - 1]) if id == n - 1 and V[i] + prefix[i - 1] > prefix[id]: id += 1 cnt[i] += 1 cnt[id] -= 1 if id == n: continue if i == 0: res[id] += (T[id] - prefix[id] + V[i]) else: res[id] += (T[id] - prefix[id] + V[i] + prefix[i - 1]) for i in range(n): if i > 0: cnt[i] += cnt[i - 1] res[i] += cnt[i] * T[i] for i in range(n): if i == n - 1: print(res[i]) else: print(res[i], end = ' ') ``` Yes
105,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` from math import * from collections import * def bs(x,i): l = i r = n-1 if(i != 0): while(l <= r): mid = (l+r)//2 if(mid == n-1): return mid if(pre[mid]-pre[i-1] > x and pre[mid-1]-pre[i-1] < x): return mid if(pre[mid]-pre[i-1] == x): return mid if(pre[mid]-pre[i-1] > x): r = mid - 1 else: l = mid + 1 else: while(l <= r): mid = (l+r)//2 if(mid == n-1): return mid if(pre[mid] > x and pre[mid-1] < x): return mid if(pre[mid] == x): return mid if(pre[mid] > x): r = mid - 1 else: l = mid + 1 return mid n = int(input()) l = list(map(int,input().split())) t = list(map(int,input().split())) pre = [t[0]] for i in range(1,n): pre.append(pre[i-1] + t[i]) dis = [0 for i in range(n)] val = [0 for i in range(n)] for i in range(n): dis[i] = bs(l[i],i) #print(dis[i]) if dis[i] > 0: if i > 0: if(l[i] > pre[dis[i]] - pre[i-1]): #print(i) val[dis[i]] += t[dis[i]] else: val[dis[i]] += l[i] - pre[dis[i]-1] + pre[i-1] else: if(l[i] > pre[dis[i]]): val[dis[i]] += t[dis[i]] else: val[dis[i]] += l[i] - pre[dis[i]-1] else: if(l[i] > pre[dis[i]]): val[dis[i]] += t[dis[i]] else: val[dis[i]] += l[0] ans = [0 for i in range(n)] for i in range(n): ans[i] += 1 ans[dis[i]] -= 1 for i in range(1,n): ans[i] += ans[i-1] for i in range(n): ans[i] *= t[i] ans[i] += val[i] ''' print(pre) print(dis) print(val) ''' for i in ans: print(i,end = " ") print() ``` Yes
105,860
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` #!/usr/bin/env python3 from sys import stdin, stdout from bisect import bisect def rint(): return map(int, stdin.readline().split()) #lines = stdin.readlines() N = int(input()) V = list(rint()) T = list(rint()) TT = [T[0]] for i in range(1,N): TT.append(TT[i-1] + T[i]) D = [ 0 for i in range(N)] M = [ 0 for i in range(N)] TT.append(0) for i in range(0,N): j = bisect(TT, V[i] + TT[i-1], i, N) if j >= N: continue D[j] += 1 M[j] = M[j]+ V[i] - (TT[j-1] - TT[i-1]) for i in range(1,N): D[i] += D[i-1] ans = [ 0 for i in range(N)] for i in range(N): ans[i] = T[i]*(i+1 - D[i]) + M[i] print(*ans) ``` Yes
105,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` n = int(input()) vs = [int(x) for x in input().split()] ts = [int(x) for x in input().split()] from heapq import * q = [] heapify(q) sts = ts[:] for i in range(1, n): sts[i] += sts[i-1] res = [] for i in range(n): v = vs[i] t = ts[i] if i: v += sts[i-1] heappush(q, v) minv = heappop(q) if minv > sts[i]: heappush(q, minv) res.append(len(q) * t) else: count = 0 while minv <= sts[i]: count += minv - sts[i-1] if not q: break minv = heappop(q) else: heappush(q, minv) res.append(count + len(q) * t) print(" ".join(map(str, res))) ``` No
105,862
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` import heapq heap = [] n = int(input()) V = list(map(int, input().split())) T = list(map(int, input().split())) tmp = 0 for i in range(n): ans = 0 heapq.heappush(heap, V[i]) while len(heap) and heap[0]<=T[i]: ans += heapq.heappop(heap) tmp += T[i] ans += T[i]*len(heap) print(ans, end=' ') ``` No
105,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` def binary_search(a, l, r, num): mid = (l+r)//2 # print("l==" + str(l) + ", r==" + str(r) + ", mid==" + str(mid)) if(mid == num): return mid+1 if(l > r): return l if(a[mid] < num): return binary_search(a, l+1, r, num) else: return binary_search(a, l, r-1, num) n = int(input()) V = list(map(int, input().split())) T = list(map(int, input().split())) a = [] ans = [] for i in range(0, n): index = binary_search(a, 0, len(a)-1, V[i]) # print("index==" + str(index)) a.insert(index, V[i]) # print(a) index0 = binary_search(a, 0, len(a)-1, T[i]) # print("index0==" + str(index0)) # print("sum==" + str(sum(a[:index0]))) ans.append(sum(a[:index0]) + (len(a) - index0)*T[i]) del a[:index0] for j in range(0, len(a)): a[j] -= T[i] print(" ".join(map(str,ans))) ``` No
105,864
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift β€” a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is Ti, each pile will reduce its volume by Ti. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day i already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input The first line contains a single integer N (1 ≀ N ≀ 105) β€” the number of days. The second line contains N integers V1, V2, ..., VN (0 ≀ Vi ≀ 109), where Vi is the initial size of a snow pile made on the day i. The third line contains N integers T1, T2, ..., TN (0 ≀ Ti ≀ 109), where Ti is the temperature on the day i. Output Output a single line with N integers, where the i-th integer represents the total volume of snow melted on day i. Examples Input 3 10 10 5 5 7 2 Output 5 12 4 Input 5 30 25 20 15 10 9 10 12 4 13 Output 9 20 35 11 25 Note In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day. Submitted Solution: ``` import configparser import math import sys input = sys.stdin.readline def get(l, r, cumsum): res = cumsum[r] if l >= 1: res -= cumsum[l-1] return res def can(l, r, cumsum, am): return am >= get(l, r, cumsum) def main(): n = int(input()) v = [int(x) for x in input().split(' ')] t = [int(x) for x in input().split(' ')] cumsum = [0 for i in range(n)] cumsum[0] = t[0] for i in range(1, n): cumsum[i] = t[i] + cumsum[i-1] ans = [0 for i in range(n)] alive = [[] for i in range(n)] for i in range(n): pos = i-1 for j in range(6, -1, -1): jump = 2**j if pos+jump < n and can(i, pos+jump, cumsum, v[i]): pos += jump if pos == i - 1: alive[i].append(v[i]) else: ans[i] += 1 if pos + 1 < n: ans[pos+1] -= 1 if pos != n-1 and v[i] > get(i, pos, cumsum): alive[pos+1].append(v[i] - get(i, pos, cumsum)) for i in range(1, n): ans[i] += ans[i-1] res = [0 for i in range(n)] for i in range(n): res[i] = ans[i]*t[i] for j in alive[i]: res[i] += j for i in res: print(i, end=' ') if __name__ == '__main__': main() ``` No
105,865
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` n=int(input()) segs=[] for i in range(n): a,b=map(int,input().split()) segs.append([a,b,i]) segs.sort(key=lambda x:[x[0],-x[1]]) for i in range(1,n): if segs[i][1]<=segs[i-1][1]: print(segs[i][2]+1,segs[i-1][2]+1) exit() segs.sort(key=lambda x:[-x[1],x[0]]) for i in range(1,n): if segs[i][0]>=segs[0][0]: print(segs[i][2]+1,segs[0][2]+1) exit() print('-1 -1') ```
105,866
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` import sys input=sys.stdin.readline n = int(input()) ls = [] for i in range(n): l, r = list(map(int, input().strip().split())) ls.append([l, r, i]) ls = sorted(ls, key=lambda x: (x[0], -x[1])) flag = False for i in range(n-1): cur_l, cur_r, mother = ls[i] if cur_r >= ls[i+1][1]: print(ls[i+1][2] + 1, mother + 1) flag = True break if not flag: print(-1, -1) ```
105,867
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` n = int(input()) arr = [] for i in range(n): l, r = map(int, input().split()) arr.append((l, -r, i)) ans = '-1 -1' a = sorted(arr) for i in range(len(a)): a[i] = (a[i][0], -a[i][1], a[i][2]) for i in range(len(a)-1): if a[i][0] <= a[i+1][0] and a[i][1] >= a[i+1][1]: ans = str(a[i+1][2] + 1) + ' ' + str(a[i][2] + 1) print(ans) ```
105,868
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` n = int(input()) a = [] for i in range(1, n+1): l, r = map(int, input().split()) a.append((l, r, i)) a.sort() for i in range(n-1): if (a[i][0] == a[i+1][0]): print(str(a[i][2]) + ' ' + str(a[i+1][2])) break if (a[i][1] >= a[i+1][1]): print(str(a[i+1][2]) + ' ' + str(a[i][2])) break else: print('-1 -1') ```
105,869
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` from sys import stdin class segment : def __init__(self,x,y,n) : self.a = x self.b = y self.no = n def __gt__(self,other): if(self.a == other.a): return self.b < other.b return self.a > other.a def __lt__(self,other): if(self.a == other.a): return self.b > other.b return self.a < other.a def __eq__(self,other): if(self.a==other.a and self.b == self.b): return True else: return False def __str__(self) : return str(self.no) n = int(stdin.readline()) arr = [] for i in range(n) : r,z = map(int,stdin.readline().split()) s = segment(r,z,i+1) arr.append(s) arr.sort() for i in range(1,n): if(arr[i].b <= arr[i-1].b) : print (arr[i],arr[i-1]) exit() print (-1,-1) ```
105,870
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` n = int(input()) l = [i for i in range(n)] d = [tuple(map(int, input().split())) for _ in range(n)] l.sort(key = lambda x: (d[x][0], -d[x][1])) for i in range(n - 1): if d[l[i + 1]][1] <= d[l[i]][1]: print(l[i + 1] + 1, l[i] + 1) exit() print(-1, -1) ```
105,871
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` n=int(input()) a=[list(map(int,input().split())) for i in range(n)] for i in range(n): a[i].append(i+1) a.sort() for i in range(n-1): if a[i][1]>=a[i+1][1]: exit(print(a[i+1][2],a[i][2])) if a[i][0]==a[i+1][0] and a[i][1]<a[i+1][1]: exit(print(a[i][2],a[i+1][2])) print('-1','-1') ```
105,872
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Tags: greedy, implementation, sortings Correct Solution: ``` N = int(input()) A = [] for i in range(1, N+1): l, r = map(int, input().split()) A.append([l, r, i]) A.sort(key=lambda x:x[0]) if N == 1: print(-1, -1) quit() a = A[0][1] for i in range(1, N): if A[i][0] == A[i-1][0] and A[i][1] > A[i-1][1]: print(A[i-1][2], A[i][2]) quit() elif A[i][1] <= a: print(A[i][2], A[i-1][2]) quit() else: if i == N-1: print(-1, -1) quit() else: a = A[i][1] ```
105,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` #!/usr/bin/env python3 n = int(input().strip()) ais = [tuple(map(int, input().strip().split())) for _ in range(n)] def solve(ais): bis = [(l, r, i + 1) for i, (l, r) in enumerate(ais)] bis.sort(key=lambda t: (t[0], -t[1])) rr = bis[0][1] - 1 ir = bis[0][2] for l, r, i in bis: if r <= rr: return (i, ir) else: rr = r ir = i return (-1, -1) i, j = solve(ais) print (i, j) ``` Yes
105,874
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` import sys n = int(sys.stdin.readline()) intervals = list(map(lambda x : (int(x[0]), int(x[1])), map(str.split, sys.stdin.readlines()))) intervals = list(enumerate(intervals)) intervals.sort(key=lambda x : 1000000009 * x[1][0] - x[1][1]) r = 0 ans1 = -1 ans2 = -1 for interval in intervals: if interval[1][1] <= r: ans1 = interval[0] break else: ans2 = interval[0] r = interval[1][1] if ans1 == -1: print('-1 -1') else: print(ans1 +1, ans2 +1) ``` Yes
105,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` def main(): n = int(input()) arr = [] for i in range(n): arr.append(list(map(int, input().split())) + [i + 1]) arr.sort(key=lambda x:[x[0], -x[1]]) ind = 0 for i in range(1, len(arr)): if arr[ind][1] >= arr[i][1]: print(arr[i][2], arr[ind][2]) return else: ind = i print(-1, -1) main() ``` Yes
105,876
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` n = int(input()) L = [] for i in range(n): l,r = map(int,input().split()) L.append((l,-r,i+1)) L = sorted(L) f = 0 for i in range(1,n): if L[i-1][1] <= L[i][1]: f = 1 print(L[i][2],L[i-1][2]) break if f == 0: print(-1,-1) ``` Yes
105,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` n = int(input()) segments = [] for _ in range(n): x, y = map(int, input().split()) segments.append((x,y)) segments = sorted(segments, key=lambda seg: seg[1], reverse=True) segments = sorted(segments, key=lambda seg: seg[0], reverse=False) max_seg = (-1,-1) output = (-1, -1) # print(segments) for i in range(n): if segments[i][1] > max_seg[0]: max_seg = (segments[i][1], i) else: fst = segments.index(segments[i]) + 1 snd = segments.index(segments[max_seg[1]]) + 1 # print(str(max_seg[1]) + ' ' + str(i)) print(str(fst) + ' ' + str(snd)) break if max_seg == (-1, -1): print('-1 -1') ``` No
105,878
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` #Failed n = int(input()) def divconq(seq): if(len(seq) <= 1): return False eraser = seq[len(seq)//2] skip_index = len(seq)//2 left = [] left_out = False right_out = False left_border = False right_border = False # l_c = 0 right = [] #r_c = 0 for i in range(len(seq)): if not i == skip_index: if seq[i][0] < eraser[0]: left_out = True if seq[i][1] > eraser[1]: right_out = True if seq[i][0] == eraser[0]: left_border = True if seq[i][1] == eraser[1]: right_border = True if ((left_out or left_border) and (right_border or right_out)) or ((not left_out) and (not right_out)): if eraser[1]-eraser[0] >= seq[i][1] - seq[i][0]: print(eraser[2],seq[i][2]) else: print(seq[i][2],eraser[2]) return True elif left_out: left.append(seq[i]) else: right.append(seq[i]) left_out = False right_out = False left_border = False right_border = False return divconq(left) or divconq(right) seq = [] for i in range(n): seq.append(list(map(int,input().split()))) seq[i].append(i+1) seq = sorted(seq,key = lambda x : (x[0],-x[1],x[2])) if not divconq(seq): print(-1,-1) ``` No
105,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` n=int(input()) segs=[] for i in range(n): a,b=map(int,input().split()) segs.append([a,b,i]) segs.sort(key=lambda x:x[0]) for i in range(1,n): if segs[i][1]<=segs[0][1]: print(segs[i][2]+1,segs[0][2]+1) exit() segs.sort(key=lambda x:-x[1]) for i in range(1,n): if segs[i][0]>=segs[0][0]: print(segs[i][2]+1,segs[0][2]+1) print('-1 -1') ``` No
105,880
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 β‰₯ l2 and r1 ≀ r2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Input The first line contains one integer n (1 ≀ n ≀ 3Β·105) β€” the number of segments. Each of the next n lines contains two integers li and ri (1 ≀ li ≀ ri ≀ 109) β€” the i-th segment. Output Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1. Examples Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 Note In the first example the following pairs are considered correct: * (2, 1), (3, 1), (4, 1), (5, 1) β€” not even touching borders; * (3, 2), (4, 2), (3, 5), (4, 5) β€” touch one border; * (5, 2), (2, 5) β€” match exactly. Submitted Solution: ``` N = int(input()) A = [] for i in range(1, N+1): l, r = map(int, input().split()) A.append([l, r, i]) A.sort(key=lambda x:x[0]) if N == 1: print(-1, -1) quit() a = A[0][1] for i in range(1, N): if i == 1 and A[1][0] == A[0][0] and A[0][1] > A[1][1]: print(A[0][2], A[1][2]) elif A[i][1] <= a: print(A[i][2], A[i-1][2]) quit() else: if i == N-1: print(-1, -1) quit() else: a = A[i][1] ``` No
105,881
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` l=[100,20,10,5,1] n=int(input()) s=0 for i in l: s+=n//i n=n%i print(s) ```
105,882
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` N = int(input()) F, tmp = [0]*(N%100+1), 0 F[0] = 0 if N >= 100: tmp = N // 100 #print(N) for i in range(1, N%100+1): if i >= 100: F[i] = 1 + min(F[i-1], F[i-5], F[i-10], F[i-20], F[i-100]) elif i >= 20: F[i] = 1 + min(F[i-1], F[i-5], F[i-10], F[i-20]) elif i >= 10: F[i] = 1 + min(F[i-1], F[i-5], F[i-10]) elif i >= 5: F[i] = 1 + min(F[i-1], F[i-5]) elif i >= 1: F[i] = 1 + F[i-1] print(F[N%100] + tmp) ```
105,883
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` import math n = int(input()) ans = n//100 n=n%100 ans += n//20 n = n%20 ans += n//10 n = n%10 ans += n//5 n = n%5 ans += n print(ans) ```
105,884
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` n=int(input().replace(',','')) c=0 if(n>=100): c+=n//100 n=n%100 if(n>=20): c+=n//20 n=n%20 if(n>=10): c+=n//10 n=n%10 if(n>=5): c+=n//5 n=n%5 print(c+n) ```
105,885
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` def main(): n = int(input()) bill = 0 if n >= 100: bill += n//100 n %= 100 if n >= 20: bill+= n//20 n %= 20 if n >= 10: bill+= n//10 n %= 10 if n >= 5: bill+= n//5 n %= 5 bill += n print(bill) if __name__ == "__main__": main() ```
105,886
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` # https://codeforces.com/problemset/problem/996/A # variation of unbounded knapsack and also has greedy appraoch to it # O(Nd) time - TLE for 10^9 input # def lottery(total, coins): # dp = [float("inf")] * (total + 1) # dp[0] = 0 # for coin in coins: # for amount in range(1, total + 1): # if coin <= amount: # dp[amount] = min(dp[amount], 1 + dp[amount - coin]) # return dp[total] # n = int(input()) # coins = [1, 5, 10, 20, 100] # print(lottery(n, coins)) # O(k) - for fixed lenght of demoninations n = int(input()) a = 0 for i in [100, 20, 10, 5, 1]: a += n // i n %= i print(a) # print(n // 100 % 100 // 10) ```
105,887
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` n = int(input()) ans=0 ans+=int(n/100) n%=100 ans+=int(n/20) n%=20 ans+=int(n/10) n%=10 ans+=int(n/5) n%=5 ans+=n print(ans) ```
105,888
Provide tags and a correct Python 3 solution for this coding contest problem. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Tags: dp, greedy Correct Solution: ``` n=int(input()) c=0 c=c+n//100 n=n%100 c=c+n//20 n=n%20 c=c+n//10 n=n%10 c=c+n//5 n=n%5 c=c+n print(c) ```
105,889
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` #coding:utf-8 n = int(input()) a = n // 100 r = (n % 100) // 20 c = (n % 20) // 10 l = (n % 10) // 5 b = (n % 5) // 1 f = l + c + r + a + b print(f) ``` Yes
105,890
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` n = int(input()) count = 0 count = count + int(n/100) n = n%100 count = count + int(n/20) n = n%20 count = count + int(n/10) n = n%10 count = count + int(n/5) n = n%5 count = count + int(n/1) print(int(count)) ``` Yes
105,891
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` n=int(input());print((n//100)+(n%100)//20+((n%100)%20)//10+(((n%100)%20)%10)//5+(((n%100)%20)%10)%5) ``` Yes
105,892
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` t=int(input()) k=t v=0 v=t//100 t=t%100 v=v+t//20 t=t%20 v=v+t//10 t=t%10 v=v+t//5 t=t%5 v=v+t print(v) ``` Yes
105,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` n = int(input()) cup =[100,20,10,5,1] count = 0 for i in cup: if n % i == 0: count = n//i break while n >= i: n-=i count+=1 print(count) ``` No
105,894
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` n = int(input()) deno = [1,5,10,20,100] count = 0 while n != 0: maxi = 0 for i in range(5): if maxi < deno[i] and deno[i] < n: maxi = deno[i] count += 1 n = n % maxi print(count) ``` No
105,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` count =0 N =int(input()) if N>=100 and N%100==0: count = N//100 print(count) exit() elif N>100: while N>100: count+=1 N=N-100 if N>=20 and N%20==0: count+=N//20 print(count) exit() elif N>20: while N>20: count+=1 N-=20 if N>=10 and N%10==0: count+=N//10 print(count) exit() elif N>10: while N>10: count+=1 N-=10 if N>=5 and N%5==0: count+=N//5 print(count) exit() elif N>5: while N>5: count+=1 N-=5 print(count+N) print("something") ``` No
105,896
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first and only line of input contains a single integer n (1 ≀ n ≀ 10^9). Output Output the minimum number of bills that Allen could receive. Examples Input 125 Output 3 Input 43 Output 5 Input 1000000000 Output 10000000 Note In the first sample case, Allen can withdraw this with a 100 dollar bill, a 20 dollar bill, and a 5 dollar bill. There is no way for Allen to receive 125 dollars in one or two bills. In the second sample case, Allen can withdraw two 20 dollar bills and three 1 dollar bills. In the third sample case, Allen can withdraw 100000000 (ten million!) 100 dollar bills. Submitted Solution: ``` n=int(input()) c=0 l=[] while True: if n!=0: if n>=100: c+=1 n=n-100 elif n>=20 and n<=100: c+=1 n=n-20 elif n>=10 and n<=20: c+=1 n=n-10 elif n>=5 and n<=10: c+=5 n=n-5 else: c+=1 n=n-1 else: break print(c) ``` No
105,897
Provide a correct Python 3 solution for this coding contest problem. We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row: * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i. Find the intensity of each bulb after the K operations. Constraints * 1 \leq N \leq 2 \times 10^5 * 1 \leq K \leq 2 \times 10^5 * 0 \leq A_i \leq N Input Input is given from Standard Input in the following format: N K A_1 A_2 \ldots A_N Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format: A{'}_1 A{'}_2 \ldots A{'}_N Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format: A{'}_1 A{'}_2 \ldots A{'}_N Examples Input 5 1 1 0 0 1 0 Output 1 2 2 1 2 Input 5 2 1 0 0 1 0 Output 3 3 4 4 3 "Correct Solution: ``` n,k,*a,=map(int,open(0).read().split()) def f(li): b=[0]*(n+1) for i,x in enumerate(li): b[max(0,i-x)]+=1 b[min(i+x+1,n)]-=1 for i in range(n): b[i+1]+=b[i] return b[:-1] for _ in range(k): a=f(a) if a==[n]*n: print(*a) exit() print(*a) ```
105,898
Provide a correct Python 3 solution for this coding contest problem. We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity of Bulb i is A_i. We will now do the following operation K times in a row: * For each integer i between 1 and N (inclusive), let B_i be the number of bulbs illuminating coordinate i. Then, change the intensity of each bulb i to B_i. Find the intensity of each bulb after the K operations. Constraints * 1 \leq N \leq 2 \times 10^5 * 1 \leq K \leq 2 \times 10^5 * 0 \leq A_i \leq N Input Input is given from Standard Input in the following format: N K A_1 A_2 \ldots A_N Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format: A{'}_1 A{'}_2 \ldots A{'}_N Output Print the intensity A{'}_i of each bulb i after the K operations to Standard Output in the following format: A{'}_1 A{'}_2 \ldots A{'}_N Examples Input 5 1 1 0 0 1 0 Output 1 2 2 1 2 Input 5 2 1 0 0 1 0 Output 3 3 4 4 3 "Correct Solution: ``` import sys input = sys.stdin.readline from itertools import accumulate n, k = map(int, input().split()) A = tuple(map(int, input().split())) for _ in range(k): C = [0]*n for i, a in enumerate(A): C[max(0, i-a)] += 1 if i+a < n-1: C[i+a+1] -= 1 A = tuple(accumulate(C)) if min(A) == n: break print(*A) ```
105,899