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. The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. e. n = a·b. <image> 10 pebbles are arranged in two rows, each row has 5 pebbles Once the Smart Beaver has arranged the pebbles, he takes back any of the resulting rows (that is, b pebbles) and discards all other pebbles. Then he arranges all his pebbles again (possibly choosing other values of a and b) and takes back one row, and so on. The game continues until at some point the Beaver ends up with exactly one pebble. The game process can be represented as a finite sequence of integers c1, ..., ck, where: * c1 = n * ci + 1 is the number of pebbles that the Beaver ends up with after the i-th move, that is, the number of pebbles in a row after some arrangement of ci pebbles (1 ≤ i < k). Note that ci > ci + 1. * ck = 1 The result of the game is the sum of numbers ci. You are given n. Find the maximum possible result of the game. Input The single line of the input contains a single integer n — the initial number of pebbles the Smart Beaver has. The input limitations for getting 30 points are: * 2 ≤ n ≤ 50 The input limitations for getting 100 points are: * 2 ≤ n ≤ 109 Output Print a single number — the maximum possible result of the game. Examples Input 10 Output 16 Input 8 Output 15 Note Consider the first example (c1 = 10). The possible options for the game development are: * Arrange the pebbles in 10 rows, one pebble per row. Then c2 = 1, and the game ends after the first move with the result of 11. * Arrange the pebbles in 5 rows, two pebbles per row. Then c2 = 2, and the game continues. During the second move we have two pebbles which can be arranged in a unique way (remember that you are not allowed to put all the pebbles in the same row!) — 2 rows, one pebble per row. c3 = 1, and the game ends with the result of 13. * Finally, arrange the pebbles in two rows, five pebbles per row. The same logic leads us to c2 = 5, c3 = 1, and the game ends with the result of 16 — the maximum possible result. Submitted Solution: ``` n = int(input()) ans = n while True: if n%2!=0: break x = n//2 n = n//2 ans+=x if n>1: ans+=1 print(ans) ``` No
91,200
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. e. n = a·b. <image> 10 pebbles are arranged in two rows, each row has 5 pebbles Once the Smart Beaver has arranged the pebbles, he takes back any of the resulting rows (that is, b pebbles) and discards all other pebbles. Then he arranges all his pebbles again (possibly choosing other values of a and b) and takes back one row, and so on. The game continues until at some point the Beaver ends up with exactly one pebble. The game process can be represented as a finite sequence of integers c1, ..., ck, where: * c1 = n * ci + 1 is the number of pebbles that the Beaver ends up with after the i-th move, that is, the number of pebbles in a row after some arrangement of ci pebbles (1 ≤ i < k). Note that ci > ci + 1. * ck = 1 The result of the game is the sum of numbers ci. You are given n. Find the maximum possible result of the game. Input The single line of the input contains a single integer n — the initial number of pebbles the Smart Beaver has. The input limitations for getting 30 points are: * 2 ≤ n ≤ 50 The input limitations for getting 100 points are: * 2 ≤ n ≤ 109 Output Print a single number — the maximum possible result of the game. Examples Input 10 Output 16 Input 8 Output 15 Note Consider the first example (c1 = 10). The possible options for the game development are: * Arrange the pebbles in 10 rows, one pebble per row. Then c2 = 1, and the game ends after the first move with the result of 11. * Arrange the pebbles in 5 rows, two pebbles per row. Then c2 = 2, and the game continues. During the second move we have two pebbles which can be arranged in a unique way (remember that you are not allowed to put all the pebbles in the same row!) — 2 rows, one pebble per row. c3 = 1, and the game ends with the result of 13. * Finally, arrange the pebbles in two rows, five pebbles per row. The same logic leads us to c2 = 5, c3 = 1, and the game ends with the result of 16 — the maximum possible result. Submitted Solution: ``` e=int(input()) def sieve(n): save = [0] * (n+1) save[0]=save[1]=1 i = 2 while (i*i <= n): if (save[i]): k = i*i while (k<=n): save[k] =1 k += i i+= 1 return save def prime(n): p=sieve(n) l=[] for i in range(n+1): if p[i]==0: if n%i==0: l.append(i) return l def ur(n): p=sieve(n) q=prime(n) if p[n]==0: return n+1 else: return n+ur(n//q[0]) print(ur(e)) ``` No
91,201
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` N=int(input()) ans=[N] for i in range(1,N): ans.append(i) print(*ans) ```
91,202
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` # It's all about what U BELIEVE def gint(): return int(input()) def gint_arr(): return list(map(int, input().split())) def gfloat(): return float(input()) def gfloat_arr(): return list(map(float, input().split())) def pair_int(): return map(int, input().split()) ############################################# INF = (1 << 31) dx = [-1, 0, 1, 0] dy = [ 0, 1, 0, -1] ############################################# ############################################# n = gint() print(n, *range(1, n)) ```
91,203
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` n=int(input()) l=list(range(1,n+1)) l=sorted(l) l.insert(0,l[-1]) l.pop() print(*l) ```
91,204
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` n = int(input()) print(str(n) + " " + " ".join([str(x) for x in range(1,n)])) ```
91,205
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` s=int(input()) print(s,end=" ") for i in range(1,s): print(i,end=" ") ```
91,206
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` n=int(input()) a=[] a.append(n) i=1 while i<n: a.append(i) i+=1 print(*a,sep=' ') ```
91,207
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` n = int(input()) print(n, *range(1, n), sep=' ') ```
91,208
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Tags: implementation, math Correct Solution: ``` #221A n = int(input()) print(n, *range(1,n)) ```
91,209
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` x=int(input()) if(x==1): print(x) else: l=[] for i in range(1,x+1): l.append(str(i)) l2=[] l2.append(l[-1]) l.pop(len(l)-1) for i in l: l2.append(i) for j in l2: print(j,end=' ') ``` Yes
91,210
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` __author__ = 'Esfandiar' n = int(input()) print(n,*range(1,n)) ``` Yes
91,211
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` n=int(input()) print(n,*[i for i in range(1,n)],sep=" ") ``` Yes
91,212
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` #A. Little Elephant and Function n = int(input()) a = [n]+list(range(1,n)) print(*a) ``` Yes
91,213
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` print(*range(int(input()), 0, -1)) ``` No
91,214
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` import re import sys from bisect import bisect, bisect_left, insort, insort_left from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from itertools import ( accumulate, combinations, combinations_with_replacement, groupby, permutations, product) from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan) from operator import itemgetter, mul from string import ascii_lowercase, ascii_uppercase, digits def inp(): return(int(input())) def inlist(): return(list(map(int, input().split()))) def instr(): s = input() return(list(s[:len(s)])) def invr(): return(map(int, input().split())) def def_value(): return False n = inp() if n < 3: for i in reversed(range(n)): print(i+1, end=" ") else: for i in range(n-1, 0, - 1): print(i, end=" ") print(n) ``` No
91,215
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` import sys n=int(input()) ans=list(range(2,n+1)) ans.append(1) if n%2==0: print(*ans) sys.exit() for i in range(n): ans[i]+=1 ans[i]%=n if ans[i]==0: ans[i]=n print(*ans) ``` No
91,216
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: * If x = 1, exit the function. * Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. Input A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. Output In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Examples Input 1 Output 1 Input 2 Output 2 1 Submitted Solution: ``` a=int(input()) l=[] i=a while i>0: l.append(str(i)) i-=1 i=a-1 while i>0: l[i],l[i-1]=l[i-1],l[i] i-=1 print(" ".join(l)) ``` No
91,217
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` z = input() res = '' if z.startswith('http'): res += 'http://' z = z[4:] elif z.startswith('ftp'): res += 'ftp://' z = z[3:] pi = z.rfind('ru') res += z[:pi] res += '.ru' if not z.endswith('ru'): res += '/'+z[pi+2:] print(res) ```
91,218
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` X = input() Result = "http://" if X[0] == "h" else "ftp://" Result += X[X.index("p") + 1:X.rfind("ru")] + ".ru/" Result += X[X.rfind("ru") + 2:] print(Result if Result[-1] != "/" else Result[:-1]) # UB_CodeForces # Advice: Falling down is an accident, staying down is a choice # Location: Here in Bojnurd # Caption: So Close man!! Take it easy!!!! # CodeNumber: 652 ```
91,219
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` string = input() if string.startswith('http'): protocol = string[:4] string = string[4:] else: protocol = string[:3] string = string[3:] domain_end = string.find('ru', 1) domain_name = string[:domain_end] context = string[domain_end + 2:] result = protocol + '://' + domain_name + '.ru' if len(context) > 0: result += '/' + context print(result) ```
91,220
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` t = input() if t[0] == 'h': ans, t = 'http://', t[4:] else: ans, t = 'ftp://', t[3:] k = t.find('ru', 1) ans += t[:k] + '.ru' if len(t) > k + 2: ans += '/' + t[k + 2:] print(ans) ```
91,221
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` S = input() ans = "" ind = 0 if S[0] == 'f': ans += "ftp://" + S[3] ind = 4 else: ans += "http://" + S[4] ind = 5 while True: if S[ind:ind+2] == 'ru': ans += '.ru/' + S[ind + 2:] break ans += S[ind] ind += 1 if ans[-1] == '/': print(ans[:-1]) else: print(ans) ```
91,222
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` s=input() ans="" if s[0]=='f': ans+='ftp://'+s[3] t=-1 for i in range(4,len(s)-1): if s[i]=='r' and s[i+1]=='u': t=i break ans+=s[4:t]+".ru" if len(s[t+2:])>0: ans+="/"+s[t+2:] print(ans) else: ans+='http://'+s[4] t=-1 for i in range(5,len(s)-1): if s[i]=='r' and s[i+1]=='u': t=i break ans+=s[5:t]+".ru" if len(s[t+2:])>0: ans+="/"+s[t+2:] print(ans) ```
91,223
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` a = input() r = '' flag = 0 flag2 = 0 for i in range(len(a)): r+=a[i] if r=='ftp': r+='://' elif r=='http': r+='://' elif a[i+1:i+3]=='ru' and flag==0: r+='.' flag = 1 if i==len(a)-3: flag2 = 1 elif flag==1 and flag2==0: flag+=1 elif flag==2 and flag2==0: r+='/' flag = 3 # if a[i:i+2]=='ru': print(r) ```
91,224
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Tags: implementation, strings Correct Solution: ``` import re address = input() address = re.sub('(http|ftp)(\w+?)(ru)', r'\1://\2.\3', address) if re.match('.+?\.ru(\w+)', address): address = re.sub('\.ru(\w+)', r'.ru/\1', address) print(address) ```
91,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` s = input() if s.startswith("http"): s = s.replace("http", "http://", 1) else: s = s.replace("ftp", "ftp://", 1) ind = s.index("ru") if s[ind:] == "ru": s = s.replace("ru", ".ru") else: if "//ru" not in s: s = s.replace("ru", ".ru/", 1) else: s = s.replace("//ru", "~~", 1) s = s.replace("ru", ".ru/", 1) s = s.replace("~~", "//ru", 1) print(s) ``` Yes
91,226
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` def puts(s): print(s, end='') s = input() if s.startswith('http'): puts('http://') s = s[4:] else: puts('ftp://') s = s[3:] i = s.rfind('ru') domen = s[:i] puts(domen + '.ru') if(domen + 'ru' != s): puts('/' + s[i + 2:]) print() ``` Yes
91,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` s = input() n = len(s) http = False ftp = False last = 0 i = 0 answer = '' while i < n: if http or ftp: if s[i:i+2] == 'ru': last = i i += 2 else: i += 1 else: if s[i:i+4] == 'http': answer += 'http://' http = True i += 4 elif s[i:i+3] == 'ftp': answer += 'ftp://' ftp = True i += 3 if http: answer += s[4:last] + '.ru' if s[last+2:]: answer += '/' + s[last+2:] else: answer += s[3:last] + '.ru' if s[last+2:]: answer += '/' + s[last+2:] print(answer) ``` Yes
91,228
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` print('/'.join(input().rpartition('ru')).replace('/', '.', 1) .replace('tp', 'tp://', 1).rstrip('/')) ``` Yes
91,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` s = input() n = len(s) http = False ftp = False i = 0 answer = '' while i < n: if http or ftp: if s[i:i+2] == 'ru': answer += '.ru' i += 2 if s[i:]: answer += '/' + s[i:] break else: answer += s[i] i += 1 if s[i:i+4] == 'http': answer += 'http://' http = True i += 4 elif s[i:i+3] == 'ftp': answer += 'ftp://' ftp = True i += 3 print(answer) ``` No
91,230
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` a = list(input()) if a[0] == 'f': print('ftp://',end = '') a = a[3:] print(''.join(a[:''.join(a).index('ru')]),end = '') a = a[''.join(a).index('ru')+2:] print('.ru',end='') if len(a) != 0: print('/',end='') print(''.join(a)) else: print('http://',end = '') a = a[4:] print(''.join(a[:''.join(a).index('ru')]),end = '') a = a[''.join(a).index('ru')+2:] print('.ru',end='') if len(a) != 0: print('/',end='') print(''.join(a)) ``` No
91,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` s = input() if(s[0]=='h'): s1 = s[:4]+"://" s2 = list(s[4:]) s3='' c=0 s4='' for i in range(len(s2)-1): if s2[i]=='r' and s2[i+1]=='u': a = s2[i]+s2[i+1] break else: s3 = s3+s2[i] for i in range(len(s)): if(s[i]=='r' and s[i+1]=='u'): s4 = s4+s[i+2:] print(s1+s3+'.'+a+'/'+s4) elif(s[0]=='f'): s1 = s[:3]+"://"+s[3:7] s2 = list(s[7:]) s3='' s4='' for i in range(len(s2)-1): if s2[i]=='r' and s2[i+1]=='u': a = s2[i]+s2[i+1] break else: s3=s3+s2[i] for i in range(len(s)): if(s[i]=='r' and s[i+1]=='u'): s4 = s4+s[i+2:] break print(s1+s3+'.'+a+'/'+s4) ``` No
91,232
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: * <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), * <domain> is a non-empty string, consisting of lowercase English letters, * the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character "/" isn't written. Thus, the address has either two characters "/" (the ones that go before the domain), or three (an extra one in front of the context). When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters ":", "/", ".". Help Vasya to restore the possible address of the recorded Internet resource. Input The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above. Output Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. Examples Input httpsunrux Output http://sun.ru/x Input ftphttprururu Output ftp://http.ru/ruru Note In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". Submitted Solution: ``` s = input() if(s[0]=='h'): s1 = s[:4]+"://" s2 = list(s[4:]) s3='' s4='' for i in range(len(s2)-1): if s2[i]=='r' and s2[i+1]=='u' and i!=0: a = s2[i]+s2[i+1] break else: s3 = s3+s2[i] for i in range(len(s)): if(s[i]=='r' and s[i+1]=='u' and i!=4): s4 = s4+s[i+2:] break print(s1+s3+'.'+a+'/'+s4) elif(s[0]=='f'): s1 = s[:3]+"://"+s[3:7] s2 = list(s[7:]) s3='' s4='' for i in range(len(s2)-1): if s2[i]=='r' and s2[i+1]=='u': a = s2[i]+s2[i+1] break else: s3=s3+s2[i] for i in range(len(s)): if(s[i]=='r' and s[i+1]=='u'): s4 = s4+s[i+2:] break print(s1+s3+'.'+a+'/'+s4) ``` No
91,233
Provide tags and a correct Python 3 solution for this coding contest problem. You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode: repeat ni times yi := y y := yi + 1 end repeat Here y is a shared variable. Everything else is local for the process. All actions on a given row are atomic, i.e. when the process starts executing a row it is never interrupted. Beyond that all interleavings are possible, i.e. every process that has yet work to do can be granted the rights to execute its next row. In the beginning y = 0. You will be given an integer W and ni, for i = 1, ... , N. Determine if it is possible that after all processes terminate, y = W, and if it is possible output an arbitrary schedule that will produce this final value. Input In the first line of the input you will be given two space separated integers N (1 ≤ N ≤ 100) and W ( - 109 ≤ W ≤ 109). In the second line there are N space separated integers ni (1 ≤ ni ≤ 1000). Output On the first line of the output write Yes if it is possible that at the end y = W, or No otherwise. If the answer is No then there is no second line, but if the answer is Yes, then on the second line output a space separated list of integers representing some schedule that leads to the desired result. For more information see note. Examples Input 1 10 11 Output No Input 2 3 4 4 Output Yes 1 1 2 1 2 2 2 2 2 1 2 1 1 1 1 2 Input 3 6 1 2 3 Output Yes 1 1 2 2 2 2 3 3 3 3 3 3 Note For simplicity, assume that there is no repeat statement in the code of the processes, but the code from the loop is written the correct amount of times. The processes are numbered starting from 1. The list of integers represent which process works on its next instruction at a given step. For example, consider the schedule 1 2 2 1 3. First process 1 executes its first instruction, then process 2 executes its first two instructions, after that process 1 executes its second instruction, and finally process 3 executes its first instruction. The list must consists of exactly 2·Σ i = 1...N ni numbers. Tags: constructive algorithms Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, w = map(int, input().split()) a = [0] + list(map(int, input().split())) total = sum(a) def ng(): print('No') exit() def ok(a): print('Yes') print(*a) exit() if w < 1 or total < w: ng() if n == 1: if w == a[1]: ok([1] * (a[1] * 2)) else: ng() if w == 1: if min(a[1:]) > 1: ng() min_i = a.index(1) ans = [] for i in range(1, n + 1): if i == min_i: continue ans += [i] * (a[i] * 2) ok([min_i] + ans + [min_i]) ans1, ans2, ans3 = [], [], [] w -= 2 if w: for i in range(1, 3): x = min(a[i] - 1, w) w -= x a[i] -= x ans3 += [i] * (2 * x) for i in range(3, n + 1): x = min(a[i], w) w -= x a[i] -= x ans3 += [i] * (2 * x) ans1 = [2] * ((a[2] - 1) * 2) for i in range(3, n + 1): ans1 += [i] * (a[i] * 2) ans1 = [1] + ans1 + [1] a[1] -= 1 ans2 = [2] + [1] * (a[1] * 2) + [2] if w == 0: ok(ans1 + ans2 + ans3) else: ng() ```
91,234
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given the following concurrent program. There are N processes and the i-th process has the following pseudocode: repeat ni times yi := y y := yi + 1 end repeat Here y is a shared variable. Everything else is local for the process. All actions on a given row are atomic, i.e. when the process starts executing a row it is never interrupted. Beyond that all interleavings are possible, i.e. every process that has yet work to do can be granted the rights to execute its next row. In the beginning y = 0. You will be given an integer W and ni, for i = 1, ... , N. Determine if it is possible that after all processes terminate, y = W, and if it is possible output an arbitrary schedule that will produce this final value. Input In the first line of the input you will be given two space separated integers N (1 ≤ N ≤ 100) and W ( - 109 ≤ W ≤ 109). In the second line there are N space separated integers ni (1 ≤ ni ≤ 1000). Output On the first line of the output write Yes if it is possible that at the end y = W, or No otherwise. If the answer is No then there is no second line, but if the answer is Yes, then on the second line output a space separated list of integers representing some schedule that leads to the desired result. For more information see note. Examples Input 1 10 11 Output No Input 2 3 4 4 Output Yes 1 1 2 1 2 2 2 2 2 1 2 1 1 1 1 2 Input 3 6 1 2 3 Output Yes 1 1 2 2 2 2 3 3 3 3 3 3 Note For simplicity, assume that there is no repeat statement in the code of the processes, but the code from the loop is written the correct amount of times. The processes are numbered starting from 1. The list of integers represent which process works on its next instruction at a given step. For example, consider the schedule 1 2 2 1 3. First process 1 executes its first instruction, then process 2 executes its first two instructions, after that process 1 executes its second instruction, and finally process 3 executes its first instruction. The list must consists of exactly 2·Σ i = 1...N ni numbers. Submitted Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, w = map(int, input().split()) a = [0] + list(map(int, input().split())) total = sum(a) def ng(): print('No') exit() def ok(a): print('Yes') print(*a) exit() if w < 1 or total < w: ng() if n == 1: if w == a[0]: ok([1] * (a[0] * 2)) else: ng() if w == 1: if min(a[1:]) > 1: ng() min_i = a.index(1) ans = [] for i in range(1, n + 1): if i == min_i: continue ans += [i] * (a[i] * 2) ok([min_i] + ans + [min_i]) ans1, ans2, ans3 = [], [], [] if w > 2: for i in range(1, 3): x = min(a[i] - 1, w - 2) w -= x a[i] -= x ans3 += [i] * (2 * x) for i in range(3, n + 1): x = min(a[i], w - 2) w -= x a[i] -= x ans3 += [i] * (2 * x) ans1 = [2] * ((a[2] - 1) * 2) for i in range(3, n + 1): ans1 += [i] * (a[i] * 2) ans1 = [1] + ans1 + [1] a[1] -= 1 ans2 = [2] + [1] * (a[1] * 2) + [2] ok(ans1 + ans2 + ans3) ``` No
91,235
Provide tags and a correct Python 3 solution for this coding contest problem. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge. When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7). Input The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation. Output Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). Examples Input 5 -1 -1 4 3 -1 Output 2 Note For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. Tags: combinatorics, math Correct Solution: ``` MOD = 10**9+7 n = int(input()) notUsed = set(range(1, n+1)) chairs = set() for i, a in enumerate(map(int, input().split()), 1): if a == -1: chairs.add(i) else: notUsed -= {a} fixed = len(chairs & notUsed) m = len(notUsed) U = m fact = [0]*(U+1) fact[0] = 1 for i in range(1, U+1): fact[i] = fact[i-1]*i % MOD invfact = [0]*(U+1) invfact[U] = pow(fact[U], MOD-2, MOD) for i in reversed(range(U)): invfact[i] = invfact[i+1]*(i+1) % MOD def nCr(n, r): if r < 0 or n < r: return 0 return fact[n]*invfact[r]*invfact[n-r] ans = fact[m] for k in range(1, fixed+1): ans += nCr(fixed, k)*fact[m-k]*(-1)**k ans %= MOD print(ans) ```
91,236
Provide tags and a correct Python 3 solution for this coding contest problem. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge. When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7). Input The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation. Output Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). Examples Input 5 -1 -1 4 3 -1 Output 2 Note For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. Tags: combinatorics, math Correct Solution: ``` input() t = list(map(int, input().split())) s, m = 0, 1000000007 p = {i for i, q in enumerate(t, 1) if q == -1} n, k = len(p), len(p - set(t)) d, c = 2 * (n & 1) - 1, 1 for j in range(n + 1): d = -d * max(1, j) % m if n - j <= k: s += c * d c = c * max(1, n - j) * pow(k - n + j + 1, m - 2, m) % m print(s % m) ```
91,237
Provide tags and a correct Python 3 solution for this coding contest problem. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge. When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7). Input The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation. Output Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). Examples Input 5 -1 -1 4 3 -1 Output 2 Note For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. Tags: combinatorics, math Correct Solution: ``` #lahub and Permutations import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 mod = 10**9+7 def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗) res = 1 while p > 0: if p % 2 == 0: n = n ** 2 % mod p //= 2 else: res = res * n % mod p -= 1 return res % mod def factrial_memo(n=10**5,mod=mod): fact = [1, 1] for i in range(2, n + 1): fact.append((fact[-1] * i) % mod) return fact fact = factrial_memo() def permutation(n,r): #nPr return fact[n]*pow(fact[n-r],mod-2)%mod def combination(n,r): #nCr return permutation(n,r)*pow(fact[r],mod-2)%mod #return fact[n]*pow(fact[n-r],mod-2)*pow(fact[r],mod-2) def homogeneous(n,r): #nHr return combination(n+r-1,r)%mod #return fact[n+m-1]*pow(fact[n-1],mod-2)*pow(fact[r],mod-2) n = int(readline()) lst1 = list(map(int,readline().split())) ct = 0 lst2 = [0]*2_001 lst3 = [0]*2_001 for i in range(n): if i+1 == lst1[i]: print(0) exit() if lst1[i] == -1: ct += 1 lst3[i+1] = 1 else: lst2[lst1[i]] = 1 ct2 = 0 for i in range(1,n+1): if lst3[i] == 1 and lst2[i] == 0: ct2 += 1 #lst2:その場所が埋まってないindex #lst3:その数字が使われてるindex #何個入れちゃいけない位置に入れるかで数え上げる #入れちゃいけないものはct2個って、 #ct-ct2個のものはどこに入れても要件を満たす ans = 0 for i in range(ct2+1): ans += pow(-1,i)*combination(ct2,i)*fact[ct-i] ans %= mod print(ans) ```
91,238
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge. When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7). Input The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation. Output Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). Examples Input 5 -1 -1 4 3 -1 Output 2 Note For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. Submitted Solution: ``` #lahub and Permutations import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 mod = 10**9+7 def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗) res = 1 while p > 0: if p % 2 == 0: n = n ** 2 % mod p //= 2 else: res = res * n % mod p -= 1 return res % mod def factrial_memo(n=10**6,mod=mod): fact = [1, 1] for i in range(2, n + 1): fact.append((fact[-1] * i) % mod) return fact fact = factrial_memo() def permutation(n,r): #nPr return fact[n]*pow(fact[n-r],mod-2)%mod def combination(n,r): #nCr return permutation(n,r)*pow(fact[r],mod-2)%mod #return fact[n]*pow(fact[n-r],mod-2)*pow(fact[r],mod-2) def homogeneous(n,r): #nHr return combination(n+r-1,r)%mod #return fact[n+m-1]*pow(fact[n-1],mod-2)*pow(fact[r],mod-2) n = int(readline()) lst1 = list(map(int,readline().split())) ct = 0 lst2 = [0]*2_001 for i in range(n): if i+1 == lst1[i]: print(0) exit() if lst1[i] == -1: ct += 1 else: lst2[lst1[i]] = 1 ct2 = 0 for i in range(1,n+1): if lst2[i] == 0: ct2 += 1 #lst2:その場所が埋まってないindex #lst3:その数字が使われてるindex #何個入れちゃいけない位置に入れるかで数え上げる #入れちゃいけないものはct2個って、 #ct-ct2個のものはどこに入れても要件を満たす ans = 0 for i in range(ct2+1): ans += pow(-1,i)*combination(ct2,i)*fact[ct-i] ans %= mod print(ans) ``` No
91,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work. The girl finds an important permutation for the research. The permutation contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n). She replaces some of permutation elements with -1 value as a revenge. When Iahub finds out his important permutation is broken, he tries to recover it. The only thing he remembers about the permutation is it didn't have any fixed point. A fixed point for a permutation is an element ak which has value equal to k (ak = k). Your job is to proof to Iahub that trying to recover it is not a good idea. Output the number of permutations which could be originally Iahub's important permutation, modulo 1000000007 (109 + 7). Input The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1. It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each positive number occurs in the sequence at most once. It's guaranteed that there is at least one suitable permutation. Output Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). Examples Input 5 -1 -1 4 3 -1 Output 2 Note For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. Submitted Solution: ``` input() t = list(map(int, input().split())) s, m = 0, 1000000007 p = {i for i, q in enumerate(t, 1) if q == -1} n, k = len(p), len(p - set(t)) d = c = 1 for j in range(n + 1): d = -d * max(1, j) % m if n - j <= k: s += c * d c = c * max(1, n - j) * pow(k - n + j + 1, m - 2, m) % m print(s % m) ``` No
91,240
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` def validate_stack(stack): for i in range(len(stack)): if stack[i] < len(stack)-i-1: return False return True # print(validate_stack([4,4,4,4,4])) if __name__ == '__main__': n = int(input()) box_strength = [int(x) for x in input().split()] box_strength = sorted(box_strength, reverse = True) flag = True ans = 100 for i in range(1,n+1): matrix = [[] for x in range(i)] flag = True ans = i # print(matrix) for idx, j in enumerate(box_strength): # print(idx%i,j) matrix[idx%i].append(j) # print(matrix) for stack in matrix: if not validate_stack(stack): flag = False break if flag: break print(ans) ```
91,241
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` def go(): n = int(input()) a = [int(i) for i in input().split(' ')] a.sort() o = 1 for i in range(n): if(a[i] < i // o): o += 1 return o print(go()) ```
91,242
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` import bisect n = int(input()) xi = list(sorted(map(int, input().split()))) s = set(xi) li = [] while len(xi) > 0: li.append([xi.pop(0)]) i = 0 while i < len(xi): if xi[i] >= len(li[-1]): li[-1].append(xi.pop(i)) else: i += 1 # print(li) print(len(li)) ```
91,243
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` import math class CodeforcesTask388ASolution: def __init__(self): self.result = '' self.n = 0 self.boxes = [] def read_input(self): self.n = int(input()) self.boxes = [int(x) for x in input().split(" ")] def process_task(self): counts = [self.boxes.count(x) for x in range(max(self.boxes) + 1)] constraints = [math.ceil(sum(counts[0:x + 1]) / (x + 1)) for x in range(len(counts))] self.result = str(max(constraints)) def get_result(self): return self.result if __name__ == "__main__": Solution = CodeforcesTask388ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ```
91,244
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` n=int(input()) x=list(map(int,input().split())) x.sort() nu=0 ans=0 mark=[] for i in range(0,n): mark.append(0) for i in range(0,n): fail=1 nu=0 for j in range(0,n): if mark[j] == 0: fail = 0 if x[j] >= nu: nu+=1 mark[j]=1 if fail == 0: ans+=1 else: break print(ans) ```
91,245
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` n = int(input()) a = [int(i) for i in input().split(' ')] a.sort() s = 1 for i in range(n): if(a[i] < i // s): s += 1 print(s) ```
91,246
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` n=int(input()) l=list(map(int,input().split())) l=sorted(l) l=l[::-1] l1=[0]*n k=0 for i in range(n) : if l1[i]!=1 : t=l[i] p=1 r=0 l1[i]==1 V=[t] for j in range(n) : if l1[j]==0 and l[j]<t : t=l[j] l1[j]=1 V.append(t) r=r+1 for j in range(n-1,-1,-1) : if l1[j]!=1 : if l[j] in V : q=V.index(l[j])+1 if len(V)-q+1<=l[j] : c=0 s=-1 u=len(V)-q+1 for e in range(q-1,-1,-1) : if V[e]>=u+s : s=s+1 else : c=1 break if c==0 : l1[j]=1 V=V[:q-1]+[l[j]]+V[q-1:] k=k+1 print(k) ```
91,247
Provide tags and a correct Python 3 solution for this coding contest problem. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Tags: greedy, sortings Correct Solution: ``` N = int(input()) ar = list(map(int, input().split())) ar.sort() a = 1 b = 100 while a < b: compliant = True k = (a+b) // 2 for i in range(len(ar)): if ar[i] < (i//k): compliant = False break if compliant: b = k else: a = k + 1 print(b) ```
91,248
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` n = int(input()) arr = list(map(int, input().split())) arr.sort() res = 1 for i in range(n): if arr[i] < i // res: res += 1 print(res) ``` Yes
91,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` n = int(input()) a = list(map(int,input().split())) a.sort() res = 0 for i in range(n): cnt = i+1 lvl = a[i]+1 res = max(res , (cnt+lvl-1)//lvl) print(res) ``` Yes
91,250
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` from sys import stdin inFile = stdin tokens = [] tokens_next = 0 def next_str(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = inFile.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_next - 1] def nextInt(): return int(next_str()) def check(a, n): # a must be sorted in decresing order if n == 0: return 0 if len(a) <= n: return 1 l = [[i] for i in a[:n]] allowed = [i for i in a[:n]] ind = 0 for i in a[n:]: ind += 1 ind %= len(allowed) starting_pos = ind while allowed[ind] == 0: ind += 1 ind %= len(l) if ind == starting_pos: # print(l, 0) return 0 l[ind] += [i] allowed[ind] = min(i, allowed[ind] - 1) # print(l, 1) return 1 def solve(a): a.sort(reverse=1) n = len(a) low = 0 high = n while low + 1 < high: m = (low + high) // 2 if check(a, m): high = m else : low = m return high n = nextInt() a = [nextInt() for i in range(n)] print(solve(a)) ``` Yes
91,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` # coding: utf-8 n = int(input()) ans = 0 li1 = [int(i) for i in input().split()] li2 = [] while li1: li1.sort() n = len(li1) i = 0 while i < n: if li1[i] < i: li2.append(li1[i]) del(li1[i]) n -= 1 else: i += 1 ans += 1 li1 = li2 li2 = [] print(ans) ``` Yes
91,252
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` import sys input = sys.stdin.readline ''' ''' li = lambda: list(map(int, input().split())) n = int(input()) x = li() x.sort() piles = [] while x: xi = x.pop() best_pile = -1 best_index = None for i, pile in enumerate(piles): if pile > best_pile and pile > 0: best_pile = pile best_index = i if best_index == None: piles.append(xi) else: piles[best_index] = min(xi, best_pile - 1) print(len(piles)) ``` No
91,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` from collections import defaultdict as dc def mlt(): return map(int, input().split()) vis = dc(lambda: 0) x = int(input()) s = [*mlt()] res = 0 for n in s: vis[n] += 1 res = max(res, vis[n]) print(res) ``` No
91,254
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` n=int(input()) arr=[int(i) for i in input().split()] arr.sort() ans=0 while(arr!=[]): ans+=1 c=arr[-1] del arr[-1] if len(arr)==0: break while(c>0 and arr!=[]): boo=False for i in range(len(arr)-1,-1,-1): if arr[i]<c: boo=True c=min(arr[i],c-1) del arr[i] break if boo==False: c-=1 del arr[-1] print(ans) ``` No
91,255
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100). Output Output a single integer — the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image> Submitted Solution: ``` # Problem: A. Fox and Box Accumulation # Contest: Codeforces - Codeforces Round #228 (Div. 1) # URL: https://codeforces.com/problemset/problem/388/A # Memory Limit: 256 MB # Time Limit: 1000 ms # # KAPOOR'S from sys import stdin, stdout def INI(): return int(stdin.readline()) def INL(): return [int(_) for _ in stdin.readline().split()] def INS(): return stdin.readline() def MOD(): return pow(10,9)+7 def OPS(ans): stdout.write(str(ans)+"\n") def OPL(ans): [stdout.write(str(_)+" ") for _ in ans] stdout.write("\n") import math if __name__=="__main__": n=INI() X=sorted(INL()) D=dict() for _ in X: D[_]=D.get(_,0)+1 ans=0 for _ in D: ans+=math.ceil((D[_]-ans)/(_+1)) OPS(ans) ``` No
91,256
Provide tags and a correct Python 2 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation 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_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') range = xrange # not for python 3.0+ # main code mod=1000000007 n=int(raw_input()) l=in_arr() sm=2 dp=[0]*n dp[0]=2 for i in range(1,n): if l[i]==i+1: dp[i]=2 sm=(sm+2)%mod continue temp=0 for j in range(l[i]-1,i): temp=(temp+dp[j])%mod dp[i]=(temp+2)%mod sm=(sm+dp[i])%mod pr_num(sm) ```
91,257
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` R = lambda: map(int, input().split()) n = int(input()) mod = 1000000007 arr = [x - 1 for x in R()] dp = [0] * (n + 1) sdp = [0] * (n + 1) dp[0] = sdp[0] = 2 for i in range(1, len(arr)): dp[i] = (2 + sdp[i - 1] - sdp[arr[i] - 1]) % mod sdp[i] = (sdp[i - 1] + dp[i]) % mod print(sdp[n - 1]) ```
91,258
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) dp = [0 for i in range(n+1)] for i in range(n+1): if i > 0 : dp[i] = (2*dp[i-1]+2-dp[a[i-1]-1])%1000000007 print((dp[n]+1000000007)%1000000007) ```
91,259
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` import sys MOD = 10 ** 9 + 7 N = int(input()) bs = [int(b) - 1 for b in input().split()] fs = [0] for i in range(1,N+1): f = 2 * fs[i - 1] + 2 - fs[bs[i - 1]] fs.append(f % MOD) print(fs[-1]) ```
91,260
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` z = int(input()) l = [None] + [int(x) for x in input().split()] pt = [0] * (z + 2) for i in range(1, z + 1): pt[i + 1] = (2 * pt[i] - pt[l[i]] + 2) % 1000000007 print(pt[z + 1] % 1000000007) ```
91,261
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` n=int(input()) p=list(map(int,input().split(" ",n)[:n])) a=[i+1 for i in range(n)] dp1=[0]*(n+1) dp1[1]=2 dp2=[0]*(n+1) dp2[1]=2 mod=10**9 + 7 for i in range(2,n+1): k=p[i-1] an=2 for j in range(k,i): an+=dp2[j]%mod dp2[i]=an%mod dp1[i]=dp2[i]+dp1[i-1] dp1[i]%=mod print(dp1[n]) ```
91,262
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` input() dp = [0] [dp.append((2 * dp[-1] + 2 - dp[u - 1]) % 1000000007) for u in map(int, input().split())] print (dp[-1]) ```
91,263
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` n,a= int(input()),list(map(int,input().split())) f,m= [0]*(n+1),10**9+7 for i in range(n): if a[i]==i+1: f[i+1]=f[i]+2 else: f[i+1]=(2+f[i]*2-f[a[i]-1])%m print(f[n]%m) ```
91,264
Provide tags and a correct Python 3 solution for this coding contest problem. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Tags: dp, implementation Correct Solution: ``` def bf(n, portal2): portal2.insert(0, -1) roomMark = [False]*(n+1) markCount = 0 room = 1 while(room != n+1): markCount += 1 roomMark[room] = not roomMark[room] if roomMark[room]: room = portal2[room] else: room += 1 print(markCount % 1000000007) def solve(n, portal2): portal2.insert(0, -1) f = [0, 2] for i in range(2, n+1): total = 2 for j in range(portal2[i], i): total += f[j] f.append(total) print(sum(f) % 1000000007) n = int(input()) portal2 = [int(i) for i in input().split(" ")] solve(n, portal2.copy()) # bf(n, portal2.copy()) ```
91,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` n = int(input()) p = list(map(int, input().split())) m = int(1e9 + 7) dp = [0] * (n + 1) dp[0] = 0 for i in range(1, n + 1): dp[i] = (2 * dp[i - 1] - dp[p[i - 1] - 1] + 2) % m print(dp[n]) ``` Yes
91,266
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` n = int(input()) + 1 mas = [int(x) for x in input().split()] dp = [0] * n mod = 1000000007 for i in range(1, n): dp[i] = (sum(dp[mas[i - 1]:i]) + 2) % mod print(sum(dp) % mod) ``` Yes
91,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` mod = 10**9+7 n = int(input()) a = list(map(int,input().split())) if n==1: print (2) exit() dp = [0 for i in range(n)] dp[1] = 2 for i in range(2,n): dp[i] = (2*dp[i-1]+2-dp[a[i-1]-1])%mod ans = (2*dp[-1]+2-dp[a[-1]-1])%mod # print (dp) print (ans) ``` Yes
91,268
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` '''input 4 1 1 2 3 ''' from sys import stdin, stdout import sys sys.setrecursionlimit(15000) # main starts n = int(stdin.readline().strip()) arr = list(map(int, stdin.readline().split())) dp = [-1] * (n + 1) dp[1] = 2 mod = 10 ** 9 + 7 for i in range(2, n + 1): dp[i] = (sum(dp[arr[i - 1] : i]) + 2) % mod print(sum(dp[1:]) % (10 ** 9 + 7)) ``` Yes
91,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` """ Code of Ayush Tiwari Codeforces: servermonk Codechef: ayush572000 """ import sys input = sys.stdin.buffer.readline def solution(): # This is the main code n=int(input()) l=list(map(int,input().split())) l=[0]+l dp=[0]*(n+2) for i in range(1,n+1): dp[i+1]=2*dp[i]+2-dp[l[i]] print(dp[-1]) t=1 for _ in range(t): solution() ``` No
91,270
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` print("baad me krunga") ``` No
91,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` n=int(input()) p=list(map(int,input().split(" ",n)[:n])) a=[i+1 for i in range(n)] dp1=[0]*(n+1) dp1[1]=2 dp2=[0]*(n+1) dp2[1]=2 for i in range(2,n+1): k=p[i-1] an=2 for j in range(k,i): an+=dp2[j] dp2[i]=an dp1[i]=dp2[i]+dp1[i-1] print(dp1[n]) ``` No
91,272
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted Solution: ``` n = int(input()) m=list(map(int,input().split())) c=[0]*n for i in range(n): c[i]=2 for j in range(m[i]-1,i): c[i]+=c[j] print(sum(c)) ``` No
91,273
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one. The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (1 ≤ i ≤ n), someone can use the first portal to move from it to room number (i + 1), also someone can use the second portal to move from it to room number pi, where 1 ≤ pi ≤ i. In order not to get lost, Vasya decided to act as follows. * Each time Vasya enters some room, he paints a cross on its ceiling. Initially, Vasya paints a cross at the ceiling of room 1. * Let's assume that Vasya is in room i and has already painted a cross on its ceiling. Then, if the ceiling now contains an odd number of crosses, Vasya uses the second portal (it leads to room pi), otherwise Vasya uses the first portal. Help Vasya determine the number of times he needs to use portals to get to room (n + 1) in the end. Input The first line contains integer n (1 ≤ n ≤ 103) — the number of rooms. The second line contains n integers pi (1 ≤ pi ≤ i). Each pi denotes the number of the room, that someone can reach, if he will use the second portal in the i-th room. Output Print a single number — the number of portal moves the boy needs to go out of the maze. As the number can be rather large, print it modulo 1000000007 (109 + 7). Examples Input 2 1 2 Output 4 Input 4 1 1 2 3 Output 20 Input 5 1 1 1 1 1 Output 62 Submitted 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_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') range = xrange # not for python 3.0+ # main code n=int(raw_input()) l=in_arr() sm=2 dp=[0]*n dp[0]=2 for i in range(1,n): if l[i]==i+1: dp[i]=2 sm+=2 continue temp=0 for j in range(l[i]-1,i): temp+=dp[j] dp[i]=temp+2 sm+=dp[i] pr_num(sm) ``` No
91,274
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` x1,y1,x2,y2=input().split() x1,y1,x2,y2=[int(x1),int(y1),int(x2),int(y2)] s1=abs(x2-x1) s2=abs(y2-y1) if(s1!=s2 and s1!=0 and s2!=0): print("-1") else: if(x1==x2): print(s2+x1,y1,s2+x2,y2) elif(y1==y2): print(x1,s1+y1,x2,s1+y2) else: print(x1,y2,x2,y1) ```
91,275
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` __author__ = 'myduomilia' x1, y1, x2, y2 = list(map(int, input().split())) b = False if x1 != x2 and y1 != y2 and abs(x1 - x2) != abs(y1 - y2): print(-1) elif x1 == x2: print(x1 + abs(y1 - y2), y1, x2 + abs(y1 - y2), y2) elif y1 == y2: print(x1, y1 + abs(x1 - x2), x2, y2 + abs(x1 - x2)) else: print(x1, y2, x2, y1) ```
91,276
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` x1,y1,x2,y2 = map(int,input().split()) a = abs(x2 - x1) b = abs(y2 - y1) g = (((a * a) + (b * b)) ** 0.5) if ((a == 0) or (b == 0)): g = (((a * a) + (b * b)) ** 0.5) if (a == 0): x3 = x1 + g x4 = x2 + g y3 = y1 y4 = y2 elif (b == 0): y3 = y1 + g y4 = y2 + g x3 = x1 x4 = x2 print(round(x3),round(y3),round(x4),round(y4)) elif (a == b): y3 = y2 x3 = x1 y4 = y1 x4 = x2 print(round(x3),round(y3),round(x4),round(y4)) else: print('-1') ```
91,277
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` x1,y1,x2,y2=map(int,input().split()) if x1==x2: Dist=abs(y1-y2) NewX=x1+Dist print(NewX,y1,NewX,y2) elif y1==y2: Dist=abs(x1-x2) NewY=y1+Dist print(x1,NewY,x2,NewY) else: if(abs(y2-y1)/abs(x2-x1)==1): print(x1,y2,x2,y1) else: print(-1) ```
91,278
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` x1,y1,x2,y2=map(int,input().split()) t=abs(x1-x2) a=abs(y1-y2) if a!=t and t and a: print(-1) else: if t==0: print(x1+a,y1,x1+a,y2) elif a==0: print(x1,y1+t,x2,y1+t) else: print(x1,y2,x2,y1) ```
91,279
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` x1,y1,x2,y2=map(int,input().split()) if abs(x2-x1)==abs(y2-y1): print(x1,y2,x2,y1) elif abs(y2-y1)==0 : print(max(x2,x1),abs(x2-x1)+y1,min(x2,x1),abs(x2-x1)+y1) elif abs(x2-x1)==0: print(abs(y2-y1)+x1,min(y2,y1),abs(y2-y1)+x1,max(y2,y1)) else: print(-1) ```
91,280
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` ip = input() ip = ip.split(" ") x1 = int(ip[0]) y1 = int(ip[1]) x2 = int(ip[2]) y2 = int(ip[3]) possible = True if x1 == x2 and y1 != y2: s = y2 - y1 x3 = x1 + s y3 = y1 x4 = x2 + s y4 = y2 elif x1 != x2 and y1 == y2: s = x2 - x1 y3 = y1 + s x3 = x1 y4 = y2 + s x4 = x2 else: m = (y2-y1)/(x2-x1) if m == 1 or m == -1: x3 = x1 y3 = y2 x4 = x2 y4 = y1 else: possible = False print(-1) if possible == True: print(f"{x3} {y3} {x4} {y4}") ```
91,281
Provide tags and a correct Python 3 solution for this coding contest problem. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Tags: implementation Correct Solution: ``` a,b,c,d=map(int,input().split()) r=abs(a-c if a!=c else b-d) if a-c!=0 and abs(a-c)!=r or b-d!=0 and abs(b-d)!=r:print(-1) elif a==c:print(a-r,b,c-r,d) elif b==d:print(a,b-r,c,d-r) else:print(a,d,c,b) ```
91,282
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` s = list(map(int, input().split())) x = s[0], 1000, s[2] m = x.index(min(x)) x1, y1 = s[m], s[m+1] x2, y2 = s[2-m], s[2-m+1] if x2 - x1 == y2 - y1: L = x2-x1 print(x1+L, y1, x1, y1+L) elif x2 - x1 == y1 - y2: L = x2 - x1 print(x1, y1-L, x1+L, y2+L) elif x1 == x2: L = y2 - y1 print(x1+L, y1, x1+L, y2) elif y1 == y2: L = x2 - x1 print(x1, y1+L, x2, y2+L) else: print(-1) ``` Yes
91,283
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` x1,y1,x2,y2 = map(int,input().split()) if x1!=x2 and y1!=y2 and (abs(x1-x2)!=abs(y1-y2)): print(-1) elif x1==x2: print(x1+abs(y1-y2),y1,x2+abs(y1-y2),y2) elif y1==y2: print(x1,y1+abs(x1-x2),x2,y2+abs(x1-x2)) else: print(x1,y2,x2,y1) ``` Yes
91,284
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` l=list(map(int,input().split())) x1=l[0] x2=l[2] y1=l[1] y2=l[3] if x1 != x2 and y1 != y2 and abs(x1 - x2) != abs(y1 - y2): print('-1') elif (x1 == x2): print(x1 + abs(y1 - y2),y1,x2 + abs(y1 - y2),y2,sep=' ') elif(y1 == y2): print(x1,y1 + abs(x1 - x2),x2,y2 + abs(x1 - x2),sep=' ') else: print(x1,y2,x2,y1,sep=' ') ``` Yes
91,285
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` x1,y1,x2,y2 = map(int, input().split()) if x1 == x2: x3 = x1 + abs(y1-y2) print (x3,y1,x3,y2) elif y1 == y2: y3 = y1 + abs(x1 - x2) print (x1,y3,x2,y3) else: if abs(x1 - x2) == abs(y1 - y2): print (x1,y2,x2,y1) else: print (-1) ``` Yes
91,286
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` a,b,c,d=map(int,input().split()) if abs(c-a)>0 and abs(d-b)>0 and (c-a)==(d-b): print(c,b,a,d) elif (abs(c-a)>0 and abs(d-b)==0) or (abs(c-a)==0 and abs(d-b)>0): if abs(c-a)>0: print(a,b+(c-a),c,d+(c-a)) else: print(a+(d-b),b,c+(d-b),d) else: print("-1") ``` No
91,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` import math x1,y1,x2,y2 = map(int,input().split()) if x1==x2: x3 = x1+abs(y2-y1) print(x3,y1,x3,y2) elif y1==y2: y3 = y1+abs(x2-x1) print(x1,y3,x2,y3) else: if abs((y2-y1)//(x2-x1)) == 1: s = math.sqrt(pow(x2-x1,2)+pow(y2-y1,2))//(math.sqrt(2)) if x1>x2: print(int(x2+s),y2,int(x1-s),y1) else: print(int(x1+s),y1,int(x2-s),y2) else: print(-1) ``` No
91,288
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` a,b,c,d = map(int,input().split()) e=0 f=0 g=0 h=0 if a==c: e = a+(b-d) g = a+(b-d) h = d f = b print(e, f, g, h) elif b==d: f = b+(b-d) h = b+(b-d) e = a g = c print(e, f, g, h) else: if abs(a-c)==abs(b-d): e = c f = b g = a h = d print(e,f,g,h) else: print(-1) ``` No
91,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. Input The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct. Output If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000). Examples Input 0 0 0 1 Output 1 0 1 1 Input 0 0 1 1 Output 0 1 1 0 Input 0 0 1 2 Output -1 Submitted Solution: ``` x1,y1,x2,y2=map(int,input().split()) length1= x2-x1 length2= y2-y1 s='' if length1==0 or length2==0: if length1==0: s+=str(x1+y2-y1)+' '+str(y1) s+=' '+str(x1+y2-y1)+' '+str(y2) if length2==0: s+=str(x1)+' '+str(x2-x1+y1) s+=' '+str(x2-x1+y1)+' '+str(x2) print(s) else: if length1==length2: s+=str(x1)+' '+str(x2-x1) s+=' '+str(x2)+' '+str(x1) print(s) else: print(-1) ``` No
91,290
Provide tags and a correct Python 3 solution for this coding contest problem. Bertown is under siege! The attackers have blocked all the ways out and their cannon is bombarding the city. Fortunately, Berland intelligence managed to intercept the enemies' shooting plan. Let's introduce the Cartesian system of coordinates, the origin of which coincides with the cannon's position, the Ox axis is directed rightwards in the city's direction, the Oy axis is directed upwards (to the sky). The cannon will make n more shots. The cannon balls' initial speeds are the same in all the shots and are equal to V, so that every shot is characterized by only one number alphai which represents the angle at which the cannon fires. Due to the cannon's technical peculiarities this angle does not exceed 45 angles (π / 4). We disregard the cannon sizes and consider the firing made from the point (0, 0). The balls fly according to the known physical laws of a body thrown towards the horizon at an angle: vx(t) = V·cos(alpha) vy(t) = V·sin(alpha) – g·t x(t) = V·cos(alpha)·t y(t) = V·sin(alpha)·t – g·t2 / 2 Think of the acceleration of gravity g as equal to 9.8. Bertown defends m walls. The i-th wall is represented as a vertical segment (xi, 0) - (xi, yi). When a ball hits a wall, it gets stuck in it and doesn't fly on. If a ball doesn't hit any wall it falls on the ground (y = 0) and stops. If the ball exactly hits the point (xi, yi), it is considered stuck. Your task is to find for each ball the coordinates of the point where it will be located in the end. Input The first line contains integers n and V (1 ≤ n ≤ 104, 1 ≤ V ≤ 1000) which represent the number of shots and the initial speed of every ball. The second line contains n space-separated real numbers alphai (0 < alphai < π / 4) which represent the angles in radians at which the cannon will fire. The third line contains integer m (1 ≤ m ≤ 105) which represents the number of walls. Then follow m lines, each containing two real numbers xi and yi (1 ≤ xi ≤ 1000, 0 ≤ yi ≤ 1000) which represent the wall’s coordinates. All the real numbers have no more than 4 decimal digits. The walls may partially overlap or even coincide. Output Print n lines containing two real numbers each — calculate for every ball the coordinates of its landing point. Your answer should have the relative or absolute error less than 10 - 4. Examples Input 2 10 0.7853 0.3 3 5.0 5.0 4.0 2.4 6.0 1.9 Output 5.000000000 2.549499369 4.000000000 0.378324889 Input 2 10 0.7853 0.3 2 4.0 2.4 6.0 1.9 Output 10.204081436 0.000000000 4.000000000 0.378324889 Tags: data structures, geometry, sortings Correct Solution: ``` import sys from array import array # noqa: F401 from math import pi, sin, cos from bisect import bisect_left def input(): return sys.stdin.buffer.readline().decode('utf-8') n, v = map(int, input().split()) v = float(v) alpha = [float(input()) for _ in range(n)] m = int(input()) wall = sorted(tuple(map(float, input().split())) for _ in range(m)) + [(1e9, 1e9)] max_angle = pi / 4 eps = 1e-9 a = [0.0] * m + [max_angle + eps] for i in range(m): ng_angle, ok_angle = 0.0, max_angle + eps for _ in range(50): mid_angle = (ok_angle + ng_angle) / 2 t = wall[i][0] / (v * cos(mid_angle)) if (v * sin(mid_angle) * t - 9.8 * t**2 / 2) - eps <= wall[i][1]: ng_angle = mid_angle else: ok_angle = mid_angle a[i] = max(a[i], ng_angle) a[i + 1] = max(a[i], a[i + 1]) ans = [''] * n for i in range(n): wi = bisect_left(a, alpha[i]) ok, ng = 0.0, 1e7 sin_a = sin(alpha[i]) for _ in range(50): t = (ok + ng) / 2 if v * sin_a * t - 9.8 * t**2 / 2 >= 0.0: ok = t else: ng = t x = v * cos(alpha[i]) * ok if x < wall[wi][0]: ans[i] = f'{x:.8f} {0:.8f}' else: ok, ng = 0.0, 1e7 cos_a = cos(alpha[i]) for _ in range(50): t = (ok + ng) / 2 if v * cos_a * t <= wall[wi][0]: ok = t else: ng = t y = v * sin_a * ok - 9.8 * ok**2 / 2 ans[i] = f'{wall[wi][0]:.8f} {y:.8f}' print('\n'.join(ans)) ```
91,291
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` s = input() pos = len(s) + 1 print(26*(pos) - len(s)) ```
91,292
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` s = input() l = [] li = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] for c in li: for i in range(0, len(s)+2): str = s[0:i] + c + s[i:len(s)] if str in l: continue else: l.append(str) print(len(l)) ```
91,293
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` letters = ['a', 'b', 'c','d', 'e', 'f', 'g', 'h','i', 'j', 'k','l', 'm', 'n','o', 'p', 'q', 'r', 's','t', 'u', 'v', 'w', 'x', 'y', 'z'] string = input() result = set() first = '' second = '' for i in range(len(string)): first = string[:i] second = string[i:] for j in range(len(letters)): value = letters[j] + first + second result.add(value) value = first + letters[j] + second result.add(value) value = first + second + letters[j] result.add(value) print(len(result)) ```
91,294
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` s=input() tedad = 26*(1+len(s))-len(s) print(tedad) ```
91,295
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` s = input() d = set() for i in range(len(s)): for a in range(26): c = chr(ord('a') + a) d.add(s[:i] + c + s[i:]) for a in range(26): c = chr(ord('a') + a) d.add(s + c) print(len(d)) ```
91,296
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` a=input() b=[0]*26 for i in range(len(a)): b[ord(a[i])-97]+=1 c=0 r=0 for i in range(26): if b[i]==0: c+=1 else: r+=(len(a)+1-b[i]) #print(r) r+=(c*(len(a)+1)) print(r) ```
91,297
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` l = list(map(str, input())) aux = list(l) s = set() for i in range(len(l)+1): for j in range(97, 123): aux.insert(i, chr(j)) s.add(str(aux)) aux = list(l) print(len(s)) ```
91,298
Provide tags and a correct Python 3 solution for this coding contest problem. Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. Output Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Examples Input a Output 51 Input hi Output 76 Note In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. Tags: brute force, math, strings Correct Solution: ``` n=input() print(25*len(n)+26) ```
91,299