message
stringlengths
2
43.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
853
107k
cluster
float64
24
24
__index_level_0__
int64
1.71k
214k
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.
instruction
0
105,310
24
210,620
Tags: implementation, math Correct Solution: ``` [a,b,c] = [int(x) for x in input().split()] def test(a,b,c) : k = 0 if min(a,b,c) == c: if a == 1 and b == 1 : k = 3 elif a == 1 and b == 2 : k = 3 elif a == 1 and b > 2 : k = 3 elif a == 2 and b == 1 : k = 4 elif a == 2 and b > 1 : k = 5 elif a > 2 and b == 1 : k = 5 else : k = 6 elif min(a,b,c) == b : if a == 1 and c == 1 : k = 3 elif a == 1 and c ==2 : k = 4 elif a == 1 and c >=2 : k = 4 elif a == 2 and c == 1: k = 4 elif a == 2 and c > 1 : k = 4 elif a > 2 and c == 1 : k = 5 else : k = 6 elif min(a,b,c) == a : if a == 1: if b == 1 and c == 1 : k = 3 elif b == 1 and c ==2 : k = 4 elif b == 1 and c >=2 : k = 4 elif b == 2 and c == 1: k = 3 elif b == 2 and c > 1 : k = 5 elif b > 2 and c == 1 : k = 3 else : k = 5 elif a == 2 : if b == 1 and c == 1 : k = 4 elif b == 1 and c ==2 : k = 5 elif b == 1 and c >=2 : k = 5 elif b == 2 and c == 1: k = 5 elif b == 2 and c > 1 : k = 6 elif b > 2 and c == 1 : k = 5 else : k = 6 return k if a < 3 or b < 2 or c < 2 : print(test(a,b,c)) else : m = (min((a//3) ,(b//2), (c//2)) ) a = a - (m*3) b = b - (m*2) c = c - (m*2) m = m*7 if a == 0 : if min(b,c) >= 1: print(m+2) elif min(b,c) == 0 and max(b,c)== 1 : print(m+1) else : print(m) elif b == 0: if min(a,c) >= 2 : print(m+3) elif c == 2 and a == 1: print(m+3) elif c== 1 and a >= 1 : print(m+2) elif c== 1 and a == 0: print(m+1) elif c== 0 and a >= 2: print(m+2) elif c==0 and a == 1: print(m+1) elif c==0 and a == 0: print(m) elif c == 0 : if min(a,b) >= 2 : print(m+4) elif b == 2 and a == 1: print(m+2) elif b== 1 and a >= 1 : print(m+3) elif b== 1 and a == 0: print(m+1) elif b== 0 and a >= 2: print(m+1) elif b==0 and a == 1: print(m+1) elif b==0 and a == 0: print(m) else : print(test(a,b,c) + m) ```
output
1
105,310
24
210,621
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.
instruction
0
105,311
24
210,622
Tags: implementation, math Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- ################################## # University of Wisconsin-Madison # Author: Yaqi Zhang ################################## # This module contains ################################## # standard library import sys import math def main(): nums = list(map(int, input().split())) days = [{0, 3, 6}, {1, 5}, {2, 4}] ans = -math.inf for i in range(7): mn = math.inf for num, day in zip(nums, days): cnt = 0 cur = i while True: if cur == 0: cnt += num // len(day) * 7 num = num % len(day) if cur in day: num -= 1 if num < 0: break cnt += 1 cur = (cur + 1) % 7 mn = min(cnt, mn) ans = max(ans, mn) print(ans) if __name__ == "__main__": main() ```
output
1
105,311
24
210,623
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip.
instruction
0
105,312
24
210,624
Tags: implementation, math Correct Solution: ``` ''' Author: Ken Problems: 1154C ''' eat = [] eat = list(map(int, input().split())) temp = min(int(eat[0]/3), int(eat[1]/2), int(eat[2]/2)) ans = temp*7 eat[0] -= temp*3 eat[1] -= temp*2 eat[2] -= temp*2 day = [0, 1, 2, 0, 2, 1, 0] cir = -1 for i in range(7): count = 0 temp = list.copy(eat) for j in range(7): # print(eat) if temp[day[(i+j) % 7]] == 0: cir = max(cir, count) break count += 1 temp[day[(i+j) % 7]] -= 1 print(ans+cir) # 1 4 7 # 2 6 # 3 5 # abcacba ```
output
1
105,312
24
210,625
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Apr 17 06:57:09 2019 @author: sharath """ l = list(map(int, input().split())) x = min(l[0]//3, l[1]//2, l[2]//2) l[0] -= 3*x l[1] -= 2*x l[2] -= 2*x x *= 7 lista=[0, 1, 2, 0, 2, 1, 0]*2 m=c=0 a=[i for i in l] for i in lista: if l[i]: c+=1 l[i]-=1 else: c=0 l=[j for j in a] m=max(m,c) print(x+m) ```
instruction
0
105,313
24
210,626
Yes
output
1
105,313
24
210,627
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Tue Apr 16 16:37:40 2019 @author: Acer """ def solve(a,b,c): """ input is a list s """ small = min(int(a/3),int(b/2),int(c/2)); totalDay = small*7; a = a - small*3; b = b - small*2; c = c - small*2; if (a == 0): totalDay = totalDay + int(b > 0) + int(c > 0); elif(a == 1): totalDay = totalDay + 1; if (c > 1): totalDay = totalDay + 2; totalDay = totalDay + int(b > 0) + int(b > 1); elif (c > 0): totalDay = totalDay + 1; totalDay = totalDay + int(b > 0); else: totalDay = totalDay + int(b > 0); elif(a == 2): totalDay = totalDay + 2; if (b > 1): totalDay = totalDay + 2 + int(c > 0) + int(c > 1); elif (b > 0): totalDay = totalDay + 1 + int(c > 1) + int(c > 0); else: if (c > 2): totalDay = totalDay + 1; else: if (b != 0) and (c != 0): totalDay = totalDay + 3 + 2 + int(b > 1) + int(c > 1); elif (b == 0): totalDay = max(totalDay + 1 + int(c > 0) + int(c > 1), totalDay + 2); elif (c == 0): totalDay = totalDay + 2 + int(b > 0) + int(b > 1); else: totalDay = totalDay + 2; return totalDay; if __name__ == "__main__": """the solve(*args) structure is needed for testing purporses""" a,b,c = [int(s) for s in input().split()]; print(solve(a,b,c)); ```
instruction
0
105,314
24
210,628
Yes
output
1
105,314
24
210,629
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` a,b,c = map(int,input().split()) A = ["a","a","b","c","a","c","b"] x = a//3;y=b//2;z=c//2 ans = min(x,y,z)*7 #print(x,y,z,min(x,y,z)) s = min(x,y,z) x -= s y -= s z -= s #print(x,y,z) a = x*3 + a%3;b = y*2 +b%2;c = z*2+c%2 #print(a,b,c) i = 0 fin_ans = 0 while(i<7): j=i;t = 0 p = a;q=b;r=c while(True): #print(p,q,r,t) if(A[j%7]=="a"): p-=1 elif(A[j%7]=="b"): q-=1 elif(A[j%7]=="c"): r-=1 if(p<0 or q<0 or r<0): break j+=1;t+=1 fin_ans = max(fin_ans,t) i+=1 print(ans+fin_ans) ```
instruction
0
105,315
24
210,630
Yes
output
1
105,315
24
210,631
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` a,b,c = map(int , input().split()) fish = [0,1,4] rabbit = [2,6] chick = [3,5] x,y,z = a,b,c maxdayCount = 0 count = 0 for start in range(7) : day = start count = 0 while(x > -1 and y > -1 and z > -1): weeks = int(min(x/3 , y/2, z/2)) # x = int(x/3) + x%3 # y = int(y/2) + y%2 # z = int(z/2) + z%2 count += 7 * weeks x -= 3 * weeks y -= 2 * weeks z -= 2 * weeks # print(count , x, y ,z) if day in fish : x -= 1 elif day in rabbit : y -= 1 else: z -= 1 if (x < 0 or y < 0 or z < 0): break day += 1 count += 1 day = day % 7 if count > maxdayCount : maxdayCount = count x,y,z = a,b,c print(maxdayCount) ```
instruction
0
105,316
24
210,632
Yes
output
1
105,316
24
210,633
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` x = list(map(int, input().split())) # if x == [0, 1, 1] or x == [1, 0, 1]: # print(2) # elif x == [0, 0, 1] or x == [0, 1, 0]: # print(1) # elif x == [1, 2, 2]: # # print(5) # pass # elif x == [1, 1, 2]: # # print(4) # pass # else: d = {0: 3, 1: 2, 2: 2} a = [x[i] // d[i] for i in range(3)] weeks = min(a) least = a.index(min(a)) b = [x[i] - d[i] * weeks for i in range(3)] days = weeks * 7 p = [0, 1, 2, 0, 2, 1, 0] if weeks > 0: i = len(p) - 1 while i >= 0 and b[p[i]] > 0: days += 1 b[p[i]] -= 1 i -= 1 i = 0 while i < len(p) and b[p[i]] > 0: days += 1 b[p[i]] -= 1 i += 1 else: for j in range(7): b = [x[i] - d[i] * weeks for i in range(3)] cd = 0 while j < len(p) and b[p[j]] > 0: cd += 1 b[p[j]] -= 1 j += 1 if j == len(p) and b[0] > 0: cd += 1 if b[1] > 0: cd += 1 if b[2] > 0: cd += 1 days = max(days, cd) # if x == [3, 1, 1]: # print(5) # else: # print(days) # 3 2 1 -> 6 print(days) ```
instruction
0
105,317
24
210,634
No
output
1
105,317
24
210,635
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` import math list1=list(map(int,input().split())) list2=[list1[0]/3,list1[1]/2,list1[2]/2] list3=[] n=list2.index(min(list2)) m=math.floor(list2[n]) list3.append(list1[0]-3*m) list3.append(list1[1]-2*m) list3.append(list1[2]-2*m) food=[0,1,2,0,2,1,0] day = [0,0,0,0,0,0,0] for i in range(7): for j in range(7): if list3[food[(j+i)%7]] != 0: list3[food[(j+i)%7]] -= 1 day[i] += 1 else: break print(m*7+max(day)) ```
instruction
0
105,318
24
210,636
No
output
1
105,318
24
210,637
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` ip = [int(i) for i in input().split()] answers = [] store = ip.copy() def fun(start): ans = 0 if start == 0: for i in range(sum(ip)): day = i%7 if day == 0 or day == 3 or day == 6: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 1 or day == 5: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans if start == 1: for i in range(sum(ip)): day = i%7 if day == 2 or day == 5 or day == 6: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 0 or day == 4: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans if start == 2: for i in range(sum(ip)): day = i%7 if day == 1 or day == 4 or day == 5: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 3 or day == 6: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans if start == 3: for i in range(sum(ip)): day = i%7 if day == 0 or day == 3 or day == 4: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 2 or day == 5: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans if start == 4: for i in range(sum(ip)): day = i%7 if day == 6 or day == 2 or day == 3: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 1 or day == 4: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans if start == 5: for i in range(sum(ip)): day = i%7 if day == 5 or day == 1 or day == 2: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 0 or day == 3: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans if start == 6: for i in range(sum(ip)): day = i%7 if day == 4 or day == 0 or day == 1: if ip[0] == 0: break ip[0]-=1 ans+=1 elif day == 6 or day == 2: if ip[1] == 0: break ip[1]-=1 ans+=1 else: if ip[2] == 0: break ip[2]-=1 ans+=1 return ans ip = store.copy() for i in range(7): answers.append(fun(i)) print(max(answers)) ```
instruction
0
105,319
24
210,638
No
output
1
105,319
24
210,639
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: * on Mondays, Thursdays and Sundays he eats fish food; * on Tuesdays and Saturdays he eats rabbit stew; * on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: * a daily rations of fish food; * b daily rations of rabbit stew; * c daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Input The first line of the input contains three positive integers a, b and c (1 ≀ a, b, c ≀ 7β‹…10^8) β€” the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly. Output Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally. Examples Input 2 1 1 Output 4 Input 3 2 2 Output 7 Input 1 100 1 Output 3 Input 30 20 10 Output 39 Note In the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday β€” rabbit stew and during Wednesday β€” chicken stake. So, after four days of the trip all food will be eaten. In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack. In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be 99 portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip. Submitted Solution: ``` import math x = list(map(int,input().split())) if sum(x) <= 7: print(sum(x)) else: if min(x) * 3 <= 7: print(min(x) * 3) else: r = [] r.append(x[0]/3) r.append(x[1]/2) r.append(x[2]/2) if r[0] == min(r): hasil = math.floor(x[0]/3) sisa1 = x[1] - (hasil * 2) sisa2 = x[2] - (hasil * 2) #print(sisa1,sisa2) rem = x[0] % 3 if rem == 0: if sisa1 > 1 and sisa2 > 1: print(7 * hasil + 2) else: print(7 * hasil + 1) elif rem == 1: if sisa1 > 2 and sisa2 > 2: print(7 * hasil + 5) else: print(7 * hasil + 3) else: print(7 * hasil + 6) elif r[1] == min(r): hasil = math.floor(x[1]/2) sisa0 = x[0] - (hasil * 3) sisa2 = x[2] - (hasil * 2) #print(sisa0,sisa2) rem = x[1] % 2 if rem == 0: if sisa0 > 1 and sisa2 > 2: print(7 * hasil + 3) else: print(7 * hasil + sisa0 + sisa2) else: if sisa0 > 3 and sisa2 > 2: print(7 * hasil + 6) else: print(7 * hasil + rem + sisa0 + sisa2) else: hasil = math.floor(x[2]/2) sisa0 = x[0] - (hasil * 3) sisa1 = x[1] - (hasil * 2) #print(sisa0,sisa1) rem = x[2] % 2 if rem == 0: if sisa0 > 2 and sisa1 > 2: print(7 * hasil + 4) else: print(7 * hasil + sisa0 + sisa1) else: if sisa0 > 2 and sisa1 > 3: print(7 * hasil + 6) else: print(7 * hasil + rem + sisa0 + sisa1) ```
instruction
0
105,320
24
210,640
No
output
1
105,320
24
210,641
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.
instruction
0
105,829
24
211,658
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) ```
output
1
105,829
24
211,659
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.
instruction
0
105,830
24
211,660
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) ```
output
1
105,830
24
211,661
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.
instruction
0
105,831
24
211,662
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)) ```
output
1
105,831
24
211,663
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.
instruction
0
105,832
24
211,664
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))) ```
output
1
105,832
24
211,665
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.
instruction
0
105,833
24
211,666
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) ```
output
1
105,833
24
211,667
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.
instruction
0
105,834
24
211,668
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)) ```
output
1
105,834
24
211,669
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.
instruction
0
105,835
24
211,670
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()) ```
output
1
105,835
24
211,671
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.
instruction
0
105,836
24
211,672
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) ```
output
1
105,836
24
211,673
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.
instruction
0
105,837
24
211,674
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) ```
output
1
105,837
24
211,675
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)) ```
instruction
0
105,838
24
211,676
Yes
output
1
105,838
24
211,677
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) ```
instruction
0
105,839
24
211,678
Yes
output
1
105,839
24
211,679
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) ```
instruction
0
105,840
24
211,680
Yes
output
1
105,840
24
211,681
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) ```
instruction
0
105,841
24
211,682
Yes
output
1
105,841
24
211,683
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) ```
instruction
0
105,842
24
211,684
No
output
1
105,842
24
211,685
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) ```
instruction
0
105,843
24
211,686
No
output
1
105,843
24
211,687
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)))) ```
instruction
0
105,844
24
211,688
No
output
1
105,844
24
211,689
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) ```
instruction
0
105,845
24
211,690
No
output
1
105,845
24
211,691
Provide tags and a correct Python 3 solution for this coding contest problem. Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y. There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop. Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w ≀ a), (h ≀ b) and (w/h = x/y). In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height. Input The first line contains four integers a, b, x, y (1 ≀ a, b, x, y ≀ 10^{18}) β€” the constraints on the screen width and height, and on the aspect ratio. Output Print one integer β€” the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints. Examples Input 17 15 5 3 Output 3 Input 14 16 7 22 Output 0 Input 4 2 6 4 Output 1 Input 1000000000000000000 1000000000000000000 999999866000004473 999999822000007597 Output 1000000063 Note In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9). In the second example, there is no TV set meeting the constraints. In the third example, there is only one variant: (3, 2).
instruction
0
107,033
24
214,066
Tags: math Correct Solution: ``` import math I=lambda:map(int,input().split()) a,b,x,y=I() g1=math.gcd(x,y) x=x//g1 y=y//g1 print(min(a//x,b//y)) ```
output
1
107,033
24
214,067
Provide tags and a correct Python 3 solution for this coding contest problem. Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y. There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop. Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w ≀ a), (h ≀ b) and (w/h = x/y). In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height. Input The first line contains four integers a, b, x, y (1 ≀ a, b, x, y ≀ 10^{18}) β€” the constraints on the screen width and height, and on the aspect ratio. Output Print one integer β€” the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints. Examples Input 17 15 5 3 Output 3 Input 14 16 7 22 Output 0 Input 4 2 6 4 Output 1 Input 1000000000000000000 1000000000000000000 999999866000004473 999999822000007597 Output 1000000063 Note In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9). In the second example, there is no TV set meeting the constraints. In the third example, there is only one variant: (3, 2).
instruction
0
107,035
24
214,070
Tags: math Correct Solution: ``` def GCD(a, b): while (a != 0 and b != 0): a, b = b % a, a return max(a, b) a, b, x, y = map(int, input().split()) f = GCD(x, y) x //= f y //= f n = min(a, b * x // y) print(n // x) ```
output
1
107,035
24
214,071
Provide tags and a correct Python 3 solution for this coding contest problem. Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than a and screen height not greater than b. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is w, and the height of the screen is h, then the following condition should be met: w/h = x/y. There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers w and h there is a TV set with screen width w and height h in the shop. Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers w and h, beforehand, such that (w ≀ a), (h ≀ b) and (w/h = x/y). In other words, Monocarp wants to determine the number of TV sets having aspect ratio x/y, screen width not exceeding a, and screen height not exceeding b. Two TV sets are considered different if they have different screen width or different screen height. Input The first line contains four integers a, b, x, y (1 ≀ a, b, x, y ≀ 10^{18}) β€” the constraints on the screen width and height, and on the aspect ratio. Output Print one integer β€” the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints. Examples Input 17 15 5 3 Output 3 Input 14 16 7 22 Output 0 Input 4 2 6 4 Output 1 Input 1000000000000000000 1000000000000000000 999999866000004473 999999822000007597 Output 1000000063 Note In the first example, there are 3 possible variants: (5, 3), (10, 6), (15, 9). In the second example, there is no TV set meeting the constraints. In the third example, there is only one variant: (3, 2).
instruction
0
107,036
24
214,072
Tags: math Correct Solution: ``` def compute_gcd(x,y): if y==0: return x else: return compute_gcd(y,x%y) a, b, x, y = map(int, input().split()) gcd = compute_gcd(x,y) x /= gcd y /= gcd num_x, num_y = x, y mx = int(a/x) my = int(b/y) print( min(mx,my) ) ```
output
1
107,036
24
214,073