message
stringlengths
2
59.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
37
108k
cluster
float64
20
20
__index_level_0__
int64
74
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0). Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that. Input The first line contains a single integer T (1≤ T≤ 1 000) denoting the number of test cases. The only line of each test case contains a single integer n (1≤ n≤ 10^{18}) denoting the number to be represented. Output For each test case, output the minimum number of 2050-numbers in one line. If n cannot be represented as the sum of 2050-numbers, output -1 instead. Example Input 6 205 2050 4100 20500 22550 25308639900 Output -1 1 2 1 2 36 Note In the third case, 4100 = 2050 + 2050. In the fifth case, 22550 = 20500 + 2050. Submitted Solution: ``` # def SieveOfEratosthenes(n): # prime = [True for i in range(n+1)] # p = 2 # while (p * p <= n): # if (prime[p] == True): # for i in range(p * p, n+1, p): # prime[i] = False # p += 1 # for p in range(2, n+1): # if prime[p]: # l.append(p) # l=[] # SieveOfEratosthenes(2*19999909) def solve(): n=int(input()) #a,b=list(map (int,input ().split())) #a=list(map (int,input ().split())) #b=list(map (int,input ().split())) if n%2050==0: num=n//2050 res=num%10 num=num//10 while(num>0): res += (num%10) num= num//10 print(res) return print(-1) for _ in range (int(input())): solve() ```
instruction
0
73,585
20
147,170
Yes
output
1
73,585
20
147,171
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0). Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that. Input The first line contains a single integer T (1≤ T≤ 1 000) denoting the number of test cases. The only line of each test case contains a single integer n (1≤ n≤ 10^{18}) denoting the number to be represented. Output For each test case, output the minimum number of 2050-numbers in one line. If n cannot be represented as the sum of 2050-numbers, output -1 instead. Example Input 6 205 2050 4100 20500 22550 25308639900 Output -1 1 2 1 2 36 Note In the third case, 4100 = 2050 + 2050. In the fifth case, 22550 = 20500 + 2050. Submitted Solution: ``` for _ in range(int(input())): n = int(input()) s=0 if n < 2050 or n%2050!=0: print(-1) else: n = n//2050 while(n!=0): s+=n%10 n=n//10 print(s) ```
instruction
0
73,586
20
147,172
Yes
output
1
73,586
20
147,173
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0). Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that. Input The first line contains a single integer T (1≤ T≤ 1 000) denoting the number of test cases. The only line of each test case contains a single integer n (1≤ n≤ 10^{18}) denoting the number to be represented. Output For each test case, output the minimum number of 2050-numbers in one line. If n cannot be represented as the sum of 2050-numbers, output -1 instead. Example Input 6 205 2050 4100 20500 22550 25308639900 Output -1 1 2 1 2 36 Note In the third case, 4100 = 2050 + 2050. In the fifth case, 22550 = 20500 + 2050. Submitted Solution: ``` import math a=205 c=len(str(a)) b=len(str(a))-3 x=0 for i in range(c-3): for j in range(math.floor(a/int('205'+('0'*(b-i))))): if a>=2050: a=a-int('205'+('0'*(b-i))) x+=1 if a==0: print(x) else: print(-1) ```
instruction
0
73,589
20
147,178
No
output
1
73,589
20
147,179
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0). Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that. Input The first line contains a single integer T (1≤ T≤ 1 000) denoting the number of test cases. The only line of each test case contains a single integer n (1≤ n≤ 10^{18}) denoting the number to be represented. Output For each test case, output the minimum number of 2050-numbers in one line. If n cannot be represented as the sum of 2050-numbers, output -1 instead. Example Input 6 205 2050 4100 20500 22550 25308639900 Output -1 1 2 1 2 36 Note In the third case, 4100 = 2050 + 2050. In the fifth case, 22550 = 20500 + 2050. Submitted Solution: ``` import math from collections import Counter, defaultdict import sys # sys.setrecursionlimit(10**6) # input = sys.stdin.readline readInt = lambda : int(input().strip()) readfloat = lambda : float(input().strip()) readStr = lambda : input().strip() intList = lambda : list(map(int, input().strip().split())) intMap = lambda : map(int, input().strip().split()) floatList = lambda : list(map(float, input().strip().split())) floatMap = lambda : map(float, input().strip().split()) strList = lambda : list(input().strip().split()) """ def print(*args): for i in args: sys.stdout.write(str(i)) sys.stdout.write(' ') sys.stdout.write('\n') """ def solve(n): res = n/2050 if res != int(res): return -1 res = int(res) total = 0 k = 2050 * 10**(len(str(n))-3) while k >= 2050: total += n//k n = n%k k //= 10 return total for _ in range(readInt()): n = readInt() print(solve(n)) ```
instruction
0
73,590
20
147,180
No
output
1
73,590
20
147,181
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A number is called 2050-number if it is 2050, 20500, ..., (2050 ⋅ 10^k for integer k ≥ 0). Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that. Input The first line contains a single integer T (1≤ T≤ 1 000) denoting the number of test cases. The only line of each test case contains a single integer n (1≤ n≤ 10^{18}) denoting the number to be represented. Output For each test case, output the minimum number of 2050-numbers in one line. If n cannot be represented as the sum of 2050-numbers, output -1 instead. Example Input 6 205 2050 4100 20500 22550 25308639900 Output -1 1 2 1 2 36 Note In the third case, 4100 = 2050 + 2050. In the fifth case, 22550 = 20500 + 2050. Submitted Solution: ``` import sys,math,bisect inf = float('inf') # input = sys.stdin.readline mod = (inf)+7 def lcm(a,b): return int((a/math.gcd(a,b))*b) def gcd(a,b): return int(math.gcd(a,b)) def binarySearch(a,x): i = bisect.bisect_left(a,x) if i!=len(a) and a[i]==x: return i else: return -1 def lowerBound(a, x): i = bisect.bisect_left(a, x) if i: return (i-1) else: return -1 def upperBound(a,x): i = bisect.bisect_right(a,x) if i!= len(a)+1 and a[i-1]==x: return (i-1) else: return -1 def freq(a,x): z = upperBound(a,x) - lowerBound(a,x) if z<=0: return 0 return z """ n = int(input()) n,k = map(int,input().split()) arr = list(map(int,input().split())) """ for _ in range(int(input())): s = int(input()) count = 0 ans = [2050] for i in range(14): ans.append(ans[-1]*10) n = len(ans) for i in range(n-1,-1,-1): while s>=ans[i]: s -= ans[i] count+=1 if count==0: print(-1) else: print(count) ```
instruction
0
73,591
20
147,182
No
output
1
73,591
20
147,183
Provide tags and a correct Python 3 solution for this coding contest problem. Input The only line of input contains three integers a1, a2, a3 (1 ≤ a1, a2, a3 ≤ 20), separated by spaces. Output Output a single integer. Examples Input 2 3 2 Output 5 Input 13 14 1 Output 14 Input 14 5 9 Output 464 Input 17 18 3 Output 53
instruction
0
73,597
20
147,194
Tags: *special Correct Solution: ``` #!/usr/bin/env python from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from io import BytesIO, IOBase from itertools import * from collections import * # sys.setrecursionlimit(10**5) if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip # sys.setrecursionlimit(10**6) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input def out(var): sys.stdout.write(str(var)) # for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) def fsep(): return map(float, inp().split()) def inpu(): return int(inp()) # ----------------------------------------------------------------- def regularbracket(t): p = 0 for i in t: if i == "(": p += 1 else: p -= 1 if p < 0: return False else: if p > 0: return False else: return True # ------------------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left) / 2) # Check if middle element is # less than or equal to key if (arr[mid] <= key): count = mid + 1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # ------------------------------reverse string(pallindrome) def reverse1(string): pp = "" for i in string[::-1]: pp += i if pp == string: return True return False # --------------------------------reverse list(paindrome) def reverse2(list1): l = [] for i in list1[::-1]: l.append(i) if l == list1: return True return False def mex(list1): # list1 = sorted(list1) p = max(list1) + 1 for i in range(len(list1)): if list1[i] != i: p = i break return p def sumofdigits(n): n = str(n) s1 = 0 for i in n: s1 += int(i) return s1 def perfect_square(n): s = math.sqrt(n) if s == int(s): return True return False # -----------------------------roman def roman_number(x): if x > 15999: return value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1] symbol = ["F", "MF", "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] roman = "" i = 0 while x > 0: div = x // value[i] x = x % value[i] while div: roman += symbol[i] div -= 1 i += 1 return roman def soretd(s): for i in range(1, len(s)): if s[i - 1] > s[i]: return False return True # print(soretd("1")) # --------------------------- def countRhombi(h, w): ct = 0 for i in range(2, h + 1, 2): for j in range(2, w + 1, 2): ct += (h - i + 1) * (w - j + 1) return ct def countrhombi2(h, w): return ((h * h) // 4) * ((w * w) // 4) # --------------------------------- def binpow(a, b): if b == 0: return 1 else: res = binpow(a, b // 2) if b % 2 != 0: return res * res * a else: return res * res # ------------------------------------------------------- def binpowmodulus(a, b, m): a %= m res = 1 while (b > 0): if (b & 1): res = res * a % m a = a * a % m b >>= 1 return res # ------------------------------------------------------------- def coprime_to_n(n): result = n i = 2 while (i * i <= n): if (n % i == 0): while (n % i == 0): n //= i result -= result // i i += 1 if (n > 1): result -= result // n return result # -------------------prime def prime(x): if x == 1: return False else: for i in range(2, int(math.sqrt(x)) + 1): if (x % i == 0): return False else: return True def luckynumwithequalnumberoffourandseven(x, n, a): if x >= n and str(x).count("4") == str(x).count("7"): a.append(x) else: if x < 1e12: luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a) luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a) return a def luckynuber(x, n, a): p = set(str(x)) if len(p) <= 2: a.append(x) if x < n: luckynuber(x + 1, n, a) return a #------------------------------------------------------interactive problems def interact(type, x): if type == "r": inp = input() return inp.strip() else: print(x, flush=True) #------------------------------------------------------------------zero at end of factorial of a number def findTrailingZeros(n): # Initialize result count = 0 # Keep dividing n by # 5 & update Count while (n >= 5): n //= 5 count += n return count #-----------------------------------------------merge sort # Python program for implementation of MergeSort def mergeSort(arr): if len(arr) > 1: # Finding the mid of the array mid = len(arr) // 2 # Dividing the array elements L = arr[:mid] # into 2 halves R = arr[mid:] # Sorting the first half mergeSort(L) # Sorting the second half mergeSort(R) i = j = k = 0 # Copy data to temp arrays L[] and R[] while i < len(L) and j < len(R): if L[i] < R[j]: arr[k] = L[i] i += 1 else: arr[k] = R[j] j += 1 k += 1 # Checking if any element was left while i < len(L): arr[k] = L[i] i += 1 k += 1 while j < len(R): arr[k] = R[j] j += 1 k += 1 #-----------------------------------------------lucky number with two lucky any digits res = set() def solve(p, l, a, b,n):#given number if p > n or l > 10: return if p > 0: res.add(p) solve(p * 10 + a, l + 1, a, b,n) solve(p * 10 + b, l + 1, a, b,n) # problem """ n = int(input()) for a in range(0, 10): for b in range(0, a): solve(0, 0) print(len(res)) """ #----------------------------------------------- # endregion------------------------------ """ def main(): n = inpu() cnt=0 c = n if n % 7 == 0: print("7" * (n // 7)) else: while(c>0): c-=4 cnt+=1 if c%7==0 and c>=0: #print(n,n%4) print("4"*(cnt)+"7"*(c//7)) break else: if n % 4 == 0: print("4" * (n // 4)) else: print(-1) if __name__ == '__main__': main() """ """ def main(): n,t = sep() arr = lis() i=0 cnt=0 min1 = min(arr) while(True): if t>=arr[i]: cnt+=1 t-=arr[i] i+=1 else: i+=1 if i==n: i=0 if t<min1: break print(cnt) if __name__ == '__main__': main() """ # Python3 program to find all subsets # by backtracking. # In the array A at every step we have two # choices for each element either we can # ignore the element or we can include the # element in our subset def subsetsUtil(A, subset, index,d): print(*subset) s = sum(subset) d.append(s) for i in range(index, len(A)): # include the A[i] in subset. subset.append(A[i]) # move onto the next element. subsetsUtil(A, subset, i + 1,d) # exclude the A[i] from subset and # triggers backtracking. subset.pop(-1) return d def subsetSums(arr, l, r,d, sum=0): if l > r: d.append(sum) return subsetSums(arr, l + 1, r,d, sum + arr[l]) # Subset excluding arr[l] subsetSums(arr, l + 1, r,d, sum) return d """ def main(): t = inpu() for _ in range(t): n = inpu() arr=[] subset=[] i=0 l=[] for j in range(26): arr.append(3**j) if __name__ == '__main__': main() """ """ def main(): n = int(input()) cnt=1 if n==1: print(1) else: for i in range(1,n): cnt+=i*12 print(cnt) if __name__ == '__main__': main() """ def main(): a, s, n = map(int, input().split()) for i in range(n): a, s = s, a + s print(a) if __name__ == '__main__': main() ```
output
1
73,597
20
147,195
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109). Output Print the requested sum for each of t integers n given in the input. Examples Input 2 4 1000000000 Output -4 499999998352516354 Note The answer for the first sample is explained in the statement.
instruction
0
73,742
20
147,484
Tags: math Correct Solution: ``` def imprime(n): b = format(n, 'b') m = len(b) #última potência de 2 cheia #soma PA1 - somaPG1 - somaPG2 print(int((1+n)*n//2 - (2**m - 1)*2)) t = int(input()) n = [0]*t for i in range(t): n[i] = int(input()) for i in range(t): imprime(n[i]) ```
output
1
73,742
20
147,485
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109). Output Print the requested sum for each of t integers n given in the input. Examples Input 2 4 1000000000 Output -4 499999998352516354 Note The answer for the first sample is explained in the statement.
instruction
0
73,743
20
147,486
Tags: math Correct Solution: ``` n = int(input()) result = '' for i in range(n): t = int(input()) s = (t + 1) * t // 2 cur2 = 1 #curstepen2 = 1 while cur2<=t: s -= cur2 * 2 cur2*=2 result+=str(s)+'\n' print(result) ```
output
1
73,743
20
147,487
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109). Output Print the requested sum for each of t integers n given in the input. Examples Input 2 4 1000000000 Output -4 499999998352516354 Note The answer for the first sample is explained in the statement.
instruction
0
73,745
20
147,490
Tags: math Correct Solution: ``` n = int(input()) for i in range(n): t = int(input()) bint = str(bin(t))[2:] pows = len(bint) - 1 print((1 + t) * t // 2 - (-1 + 2 ** (pows + 1)) * 2) ```
output
1
73,745
20
147,491
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109). Output Print the requested sum for each of t integers n given in the input. Examples Input 2 4 1000000000 Output -4 499999998352516354 Note The answer for the first sample is explained in the statement.
instruction
0
73,747
20
147,494
Tags: math Correct Solution: ``` import math t = int(input()) for _ in range(t): num=int(input()) gpn=math.floor((math.log(num)/math.log(2))+1) #print(num,gpn) nsum=(num*(num+1))//2 gpsum=(pow(2,gpn)-1) print(int(nsum-2*(gpsum))) #print(nsum,gpsum) ```
output
1
73,747
20
147,495
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109). Output Print the requested sum for each of t integers n given in the input. Examples Input 2 4 1000000000 Output -4 499999998352516354 Note The answer for the first sample is explained in the statement.
instruction
0
73,748
20
147,496
Tags: math Correct Solution: ``` t = int(input()) while t: f = int(input()) n = 1 t_total = 0 n_total = (((1 + f)*(f))//2) while n < f+1: t_total += n n = n * 2 t_total = t_total print(n_total - 2* t_total ) t-=1 ```
output
1
73,748
20
147,497
Provide tags and a correct Python 3 solution for this coding contest problem. In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for t values of n. Input The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109). Output Print the requested sum for each of t integers n given in the input. Examples Input 2 4 1000000000 Output -4 499999998352516354 Note The answer for the first sample is explained in the statement.
instruction
0
73,749
20
147,498
Tags: math Correct Solution: ``` p=int(input()) for q in range(p): n=int(input()) sum=n*(n+1)//2 b=bin(n)[2:] l=len(b) t=0 for i in range(l): t+=int(('1'+"0"*i),2) print(sum-2*t) ```
output
1
73,749
20
147,499
Provide tags and a correct Python 3 solution for this coding contest problem. The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal. However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools! Input The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). Output Output one number. Examples Input 8 5 1 1 1 1 1 1 1 1 Output 5 Input 10 3 16 8 2 4 512 256 32 128 64 1 Output 7 Input 5 1 20 10 50 30 46 Output 10 Input 6 6 6 6 6 6 6 6 Output 36 Input 1 1 100 Output 100
instruction
0
73,829
20
147,658
Tags: greedy, sortings Correct Solution: ``` a = input() n, k = map(int, a.split()) b = input() numbers = list(map(int, b.split())) print(sum(sorted(numbers)[0:k])) ```
output
1
73,829
20
147,659
Provide tags and a correct Python 3 solution for this coding contest problem. The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal. However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools! Input The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). Output Output one number. Examples Input 8 5 1 1 1 1 1 1 1 1 Output 5 Input 10 3 16 8 2 4 512 256 32 128 64 1 Output 7 Input 5 1 20 10 50 30 46 Output 10 Input 6 6 6 6 6 6 6 6 Output 36 Input 1 1 100 Output 100
instruction
0
73,831
20
147,662
Tags: greedy, sortings Correct Solution: ``` f = lambda: map(int, input().split()) n, k = f() print(sum(sorted(f())[:k])) ```
output
1
73,831
20
147,663
Provide tags and a correct Python 3 solution for this coding contest problem. The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal. However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools! Input The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). Output Output one number. Examples Input 8 5 1 1 1 1 1 1 1 1 Output 5 Input 10 3 16 8 2 4 512 256 32 128 64 1 Output 7 Input 5 1 20 10 50 30 46 Output 10 Input 6 6 6 6 6 6 6 6 Output 36 Input 1 1 100 Output 100
instruction
0
73,832
20
147,664
Tags: greedy, sortings Correct Solution: ``` n,k=map(int,input().split()) print(sum(sorted(list(map(int,input().split())))[:k])) ```
output
1
73,832
20
147,665
Provide tags and a correct Python 3 solution for this coding contest problem. The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal. However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools! Input The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). Output Output one number. Examples Input 8 5 1 1 1 1 1 1 1 1 Output 5 Input 10 3 16 8 2 4 512 256 32 128 64 1 Output 7 Input 5 1 20 10 50 30 46 Output 10 Input 6 6 6 6 6 6 6 6 Output 36 Input 1 1 100 Output 100
instruction
0
73,833
20
147,666
Tags: greedy, sortings Correct Solution: ``` n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) print (sum(a[:k])) ```
output
1
73,833
20
147,667
Provide tags and a correct Python 3 solution for this coding contest problem. The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal. However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools! Input The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). Output Output one number. Examples Input 8 5 1 1 1 1 1 1 1 1 Output 5 Input 10 3 16 8 2 4 512 256 32 128 64 1 Output 7 Input 5 1 20 10 50 30 46 Output 10 Input 6 6 6 6 6 6 6 6 Output 36 Input 1 1 100 Output 100
instruction
0
73,835
20
147,670
Tags: greedy, sortings Correct Solution: ``` n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] a.sort() s = 0 for i in range(k): s += a[i] print(s) ```
output
1
73,835
20
147,671
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,912
20
147,824
Tags: binary search, bitmasks, brute force Correct Solution: ``` lucky=[] def func(number,fours,sevens): if(number>1e10): return elif(fours==sevens): lucky.append(number) func(10*number+7,fours,sevens+1) func(10*number+4,fours+1,sevens) func(4,1,0) func(7,0,1) n=int(input()) lucky.sort() for x in lucky: if(x>=n): print(x) break ```
output
1
73,912
20
147,825
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,913
20
147,826
Tags: binary search, bitmasks, brute force Correct Solution: ``` n = int(input()) Q = [0] i = 0 while True: t = Q[i] if t>=n: if str(t).count('4') == str(t).count('7'): print(t) break Q+=[t*10+4,t*10+7] i+=1 ```
output
1
73,913
20
147,827
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,914
20
147,828
Tags: binary search, bitmasks, brute force Correct Solution: ``` from itertools import permutations def solve(x): for d in range(1, 6): for p in permutations([4]*d + [7]*d): y = 0 for e in p: y = 10 * y + e if y >= x: return y print(solve(int(input()))) ```
output
1
73,914
20
147,829
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,915
20
147,830
Tags: binary search, bitmasks, brute force Correct Solution: ``` n=int(input()) l=[] def lucky(x): if x>=n and str(x).count('4')==str(x).count('7'): l.append(x) if x<10**12: lucky(x*10+4) lucky(x*10+7) lucky(0) l.sort() print(l[0]) ```
output
1
73,915
20
147,831
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,916
20
147,832
Tags: binary search, bitmasks, brute force Correct Solution: ``` import math, re, sys, string, operator, functools, fractions, collections sys.setrecursionlimit(10**7) RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] mod=int(1e9+7) eps=1e-6 pi=math.acos(-1.0) MAX=10**5+10 ################################################# n=RI()[0] def check(n): cnt=[0,0] while n: if n%10==4: cnt[0]+=1 else: cnt[1]+=1 n//=10 return (cnt[0]==cnt[1]) for l in range(2,11,2): for i in range(1<<l): num=i v=0 for j in range(l-1,-1,-1): v*=10 if (num>>j)&1: v+=7 else: v+=4 if v>=n and check(v): print(v) exit(0) ```
output
1
73,916
20
147,833
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,917
20
147,834
Tags: binary search, bitmasks, brute force Correct Solution: ``` n=int(input()) l=[0] i=0 while True: t=l[i] if t>=n: if str(t).count('7')==str(t).count('4'): print(t);break l+=[t*10+4,t*10+7] i+=1 ```
output
1
73,917
20
147,835
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,918
20
147,836
Tags: binary search, bitmasks, brute force Correct Solution: ``` def check(m): if (m>=n) and str(m).count('4') == str(m).count('7'): a.append(m) if (m<10**12): check(m*10+4) check(m*10+7) n = int(input()) a=[] check(0) a.sort() print(a[0]) ```
output
1
73,918
20
147,837
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47
instruction
0
73,919
20
147,838
Tags: binary search, bitmasks, brute force Correct Solution: ``` z=[] for i in range(1,11): for j in range(1<<i): s=bin(j) s=s[2:] if s.count("1")==s.count("0"):z+=[int(s.replace("1","4").replace("0","7"))]+[int(s.replace("1","7").replace("0","4"))] z.sort() a=int(input()) for i in z: if a<=i:print(i);break ```
output
1
73,919
20
147,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` from itertools import permutations as p def ck(num,arr): for i in arr: if i>=num: print(i) return x = input() z = len(x) if z == 1: print(47) elif z == 2 : if int(x) <= 74: arr = [47,74] ck(int(x),arr) else: print(4477) elif z == 3: print(4477) elif z == 4: if int(x) <= 7744: arr4 = sorted([int("".join(i)) for i in p("4477")]) ck(int(x),arr4) else: print(444777) elif z == 5: print(444777) elif z == 6: if int(x) <= 777444: arr6 = sorted([int("".join(i)) for i in p("444777")]) ck(int(x),arr6) else: print(44447777) elif z ==7: print(44447777) elif z==8: if int(x)<=77774444: arr8 = sorted([int("".join(i)) for i in p("44447777")]) ck(int(x),arr8) else: print(4444477777) else: print(4444477777) ```
instruction
0
73,920
20
147,840
Yes
output
1
73,920
20
147,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` lucky_numbers=[] def fun(a,count4,count7): if a>10**10: return None if count4==count7: lucky_numbers.append(a) fun(a*10+4,count4+1,count7) fun(a*10+7,count4,count7+1) fun(4,1,0) fun(7,0,1) n=int(input()) lucky_numbers.sort() for item in lucky_numbers: if item>=n: print(item) break ```
instruction
0
73,921
20
147,842
Yes
output
1
73,921
20
147,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` gh=set() def rep(n,four,seven): global gh if n>10000000000 :return if (four==seven):gh|={n} rep(n*10+4,four+1,seven) rep(n*10+7,four,seven+1) rep(0,0,0) gh=sorted(gh) def bin_s(a): lo=0;hi=len(gh);ans=0 while lo<=hi: mid=(lo+hi)//2 if gh[mid]>=a:ans=gh[mid];hi=mid-1 else:lo=mid+1 return ans print(bin_s(int(input()))) ```
instruction
0
73,922
20
147,844
Yes
output
1
73,922
20
147,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` import math R = lambda: map(int, input().split()) n = int(input()) q, res = ['4', '7'], math.inf while q: s = q.pop(0) if s.count('4') == s.count('7') and int(s) >= n: res = min(res, int(s)) if len(s) < 10: q.append(s + '4') q.append(s + '7') print(res) ```
instruction
0
73,923
20
147,846
Yes
output
1
73,923
20
147,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` a=input() n=list(a) if n.count('4')==n.count('7'): print(a) else: if n.count('4')>n.count('7'): print("4"+(len(a)//2)*"7"+(len(a)-1)//2*"4") else: print("7"+(len(a)//2)*"4"+(len(a)-1)//2*"7") ```
instruction
0
73,924
20
147,848
No
output
1
73,924
20
147,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) n = STR() cnt1 = 0 cnt2 = 0 k1 = len(n) // 2 for i in range(k1): if n[i] == '4': cnt1 +=1 if n[i] == '7': cnt2 += 1 for i in range(k1 , len(n)): if n[i] == '4': cnt1 += 1 if n[i] == '7': cnt2 += 1 #print(cnt1 , cnt2) if cnt1 == cnt2 : print(''.join(n)) exit(0) x = len(n) // 2 - cnt1 y = len(n) // 2 - cnt2 for i in range(k1): if n[i] == '4' or n[i] == '7':continue else: if int(n[i]) > 4 : if y > 0 : n[i] = '7' y -=1 else: if x > 0 : n[i] = '4' x -=1 else: if x > 0 : n[i] = '4' x -=1 else: if y >0 : n[i] = '7' y -=1 for i in range(k1 , len(n)): if n[i] == '4' or n[i] == '7':continue else: if int(n[i]) > 4: if y > 0: n[i] = '7' y -= 1 else: if x > 0: n[i] = '4' x -= 1 else: if x > 0: n[i] = '4' x -= 1 else: if y > 0: n[i] = '7' y -= 1 print(''.join(n)) ```
instruction
0
73,925
20
147,850
No
output
1
73,925
20
147,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` n = int(input()) for i in range(1, 10 + 1): for j in range(1 << i): k = ''.join(['4' if j&l else '7' for l in range(i)][::-1]) if (k.count('4') == k.count('7') and int(k) > n): print (k) exit() ```
instruction
0
73,926
20
147,852
No
output
1
73,926
20
147,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 109). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Examples Input 4500 Output 4747 Input 47 Output 47 Submitted Solution: ``` def f1(x): if not x: return x n = len(x) for i in range(n - 1, -1, -1): if not x[i - 1] >= x[i]: break k = i - 1 if k == -1: return [] for i in range(n - 1, k, -1): if not x[k] >= x[i]: x[i], x[k] = x[k], x[i] break x[k + 1 :] = reversed(x[k + 1 :]) return x def f2(A): A = sorted(A) result = list() while True: result.append(A.copy()) A = f1(A) if not A: break return result n=list(input()) num=int("".join(n)) flag=True h=int(len(n)/2) if len(n) != 1: l=[4]*h+[7]*h t=f2(l) for i in t: j="" for a in i: j+=str(a) jj=int(j) if jj >= num: print(jj) flag=False break if flag: h=int(len(n)/2)+1 print("4"*h+"7"*h) else: if 4>num: print(4) elif 7>num: print(7) else: print(44) ```
instruction
0
73,927
20
147,854
No
output
1
73,927
20
147,855
Provide tags and a correct Python 3 solution for this coding contest problem. Petya and Vasya are competing with each other in a new interesting game as they always do. At the beginning of the game Petya has to come up with an array of N positive integers. Sum of all elements in his array should be equal to S. Then Petya has to select an integer K such that 0 ≤ K ≤ S. In order to win, Vasya has to find a non-empty subarray in Petya's array such that the sum of all selected elements equals to either K or S - K. Otherwise Vasya loses. You are given integers N and S. You should determine if Petya can win, considering Vasya plays optimally. If Petya can win, help him to do that. Input The first line contains two integers N and S (1 ≤ N ≤ S ≤ 10^{6}) — the required length of the array and the required sum of its elements. Output If Petya can win, print "YES" (without quotes) in the first line. Then print Petya's array in the second line. The array should contain N positive integers with sum equal to S. In the third line print K. If there are many correct answers, you can print any of them. If Petya can't win, print "NO" (without quotes). You can print each letter in any register (lowercase or uppercase). Examples Input 1 4 Output YES 4 2 Input 3 4 Output NO Input 3 8 Output YES 2 1 5 4
instruction
0
74,312
20
148,624
Tags: constructive algorithms, math Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Mon Aug 24 07:01:34 2020 @author: Dark Soul """ [n,s]=list(map(int, input().split())) if 2*n>s: print('NO') else: print('YES') sol=[1]*(n-1) sol.append(s-n+1) print(*sol) print(n) ```
output
1
74,312
20
148,625
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,572
20
149,144
Tags: implementation, strings Correct Solution: ``` # your code goes here a = (input()) b = (input()) j = 0 for i in range(len(a)): if a[i] == '0': j+=1 else: break a = a[j:] j = 0 for i in range(len(b)): if b[i] == '0': j+=1 else: break b = b[j:] flag = 0 if len(a)> len(b): print (">") elif len(a)<len(b): print ("<") else: for i in range(len(a)): if (a[i]>b[i]): flag = 1 break elif (a[i]<b[i]): flag = 2 break else: continue if (flag == 0): print ("=") elif (flag == 1): print (">") else: print ("<") ```
output
1
74,572
20
149,145
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,573
20
149,146
Tags: implementation, strings Correct Solution: ``` aa = input() bb = input() cta = 0 ctb = 0 start = False for let in aa: if let == "0": cta += 1 if let != "0": break for let in bb: if let == "0": ctb += 1 if let != "0": break start = False a = aa[cta:] b = bb[ctb:] if len(a) > len(b): print(">") elif len(a) < len(b): print("<") elif a == b: print("=") else: if a > b: print(">") else: print("<") ```
output
1
74,573
20
149,147
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,574
20
149,148
Tags: implementation, strings Correct Solution: ``` first_integer = input() second_integer = input() len_first = len(first_integer) len_second = len(second_integer) max_len = max(len_first, len_second) if len_first < len_second: first_integer = '0' * (len_second - len_first) + first_integer elif len_first > len_second: second_integer = '0' * (len_first - len_second) + second_integer for i in range(max_len): if first_integer[i] < second_integer[i]: print('<') exit(0) elif first_integer[i] > second_integer[i]: print('>') exit(0) print('=') ```
output
1
74,574
20
149,149
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,575
20
149,150
Tags: implementation, strings Correct Solution: ``` a = input().lstrip('0') b = input().lstrip('0') ans = '=' if len(a) > len(b): ans = '>' elif len(a) < len(b): ans = '<' else: for i in range(len(a)): if int(a[i]) > int(b[i]): ans = '>' break elif int(a[i]) < int(b[i]): ans = '<' break print(ans) ```
output
1
74,575
20
149,151
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,576
20
149,152
Tags: implementation, strings Correct Solution: ``` import sys inst=lambda: sys.stdin.readline().rstrip('\n\r') inin=lambda: int(sys.stdin.buffer.readline()) inar=lambda: list(map(int,sys.stdin.buffer.readline().split())) a=input().lstrip('0') b=input().lstrip('0') if len(a)<len(b): print('<') elif len(a)>len(b): print('>') else: if a<b: print('<') elif a>b: print('>') else: print('=') ```
output
1
74,576
20
149,153
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,577
20
149,154
Tags: implementation, strings Correct Solution: ``` from sys import stdin, stdout, exit a = stdin.readline() b = stdin.readline() i1 = len(a) i2 = len(b) for i in range(len(a)): if a[i] != '0': i1 = i break for i in range(len(b)): if b[i] != '0': i2 = i break if len(a) - i1 < len(b) - i2: stdout.write('<') exit(0) elif len(a) - i1 > len(b) - i2: stdout.write('>') exit(0) while i1 < len(a) - 1: if int(a[i1]) < int(b[i2]): stdout.write('<') exit(0) elif int(a[i1]) > int(b[i2]): stdout.write('>') exit(0) i1 += 1 i2 += 1 print('=') ```
output
1
74,577
20
149,155
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,578
20
149,156
Tags: implementation, strings Correct Solution: ``` a=input() b=input() if a.count('0')==len(a) and b.count('0')==len(b): print('=') exit() a=a.lstrip('0') b=b.lstrip('0') if len(a)>len(b): print('>') elif len(b)>len(a): print('<') else: for i in range(len(a)): if int(a[i])>int(b[i]): print('>') break elif int(a[i])<int(b[i]): print('<') break elif i==len(a)-1: print('=') break ```
output
1
74,578
20
149,157
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. Output Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". Examples Input 9 10 Output &lt; Input 11 10 Output &gt; Input 00012345 12345 Output = Input 0123 9 Output &gt; Input 0123 111 Output &gt;
instruction
0
74,579
20
149,158
Tags: implementation, strings Correct Solution: ``` a = input().lstrip('0') b = input().lstrip('0') if len(a) == len(b): if a == b: print("=") elif a < b: print("<") else: print(">") else: if len(a) < len(b): print("<") else: print(">") ```
output
1
74,579
20
149,159
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem AOR Ika-chan, who loves feasts, defined "the number of feasts". A feast number is a natural number that includes "$ 51-3 $" in $ 10 $ decimal notation. $? $ Can be any number from $ 0 $ to $ 9 $. Find the number of feasts out of the natural numbers below $ N $. input $ N $ output Output the number of feasts in one line. Also, output a line break at the end. Example Input 5124 Output 3 Submitted Solution: ``` def usa(x): if x <= 5000: return False sx = str(x) return sx[0] == '5' and sx[1] == '1' and sx[3] == '3' def rec(k, tight, prev, ok, x, dp): if len(x) == k: # print(prev) return 1 if ok else 0 if dp[k][tight][prev] != -1: return dp[k][tight][prev] if ok: return int(10 ** (len(x) - k)) upper = int(x[k]) if tight == 1 else 9 ret = 0 for i in range(0, upper + 1): newPrev = prev newPrev *= 10 newPrev %= 10000 newPrev += i newTight = tight if newTight == 1 and i != int(x[k]): newTight = 0 ret += rec(k + 1, newTight, newPrev, ok or usa(newPrev), x, dp) dp[k][tight][prev] = ret return ret def solve(N): Dp = [[[-1 for k in range(10000)] for j in range(2)] for i in range(len(str(N)))] ans = rec(0, 1, 0, False, str(N), Dp) return ans # print(ans) if __name__ == '__main__': N = int(input()) print(solve(N)) ```
instruction
0
74,918
20
149,836
No
output
1
74,918
20
149,837
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem AOR Ika-chan, who loves feasts, defined "the number of feasts". A feast number is a natural number that includes "$ 51-3 $" in $ 10 $ decimal notation. $? $ Can be any number from $ 0 $ to $ 9 $. Find the number of feasts out of the natural numbers below $ N $. input $ N $ output Output the number of feasts in one line. Also, output a line break at the end. Example Input 5124 Output 3 Submitted Solution: ``` def usa(x): if x <= 5000: return False sx = str(x) return sx[0] == '5' and sx[1] == '1' and sx[3] == '3' def rec(k, tight, prev, ok, x, dp): if len(x) == k: # print(prev) return 1 if ok else 0 if dp[k][tight][prev] != -1: return dp[k][tight][prev] upper = int(x[k]) if tight == 1 else 9 ret = 0 for i in range(0, upper + 1): newPrev = prev newPrev *= 10 newPrev %= 10000 newPrev += i newTight = tight if newTight == 1 and i != int(x[k]): newTight = 0 ret += rec(k + 1, newTight, newPrev, ok or usa(newPrev), x, dp) dp[k][tight][prev] = ret return ret if __name__ == '__main__': N = int(input()) Dp = [[[-1 for k in range(10000)] for j in range(2)] for i in range(len(str(N)))] ans = rec(0, 1, 0, False, str(N), Dp) print(ans) ```
instruction
0
74,919
20
149,838
No
output
1
74,919
20
149,839
Provide a correct Python 3 solution for this coding contest problem. Problem Let $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary. Given a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $. Example of calculating the function $ f (5) $: When 5 is expressed in binary, it is 101 and the sum of each digit is 1 + 0 + 1 = 2 Therefore, $ f (5) = 2 $. Note: https://ja.wikipedia.org/wiki/ Binary Ouput Outputs the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $ on one line. Constraints The input satisfies the following conditions. * $ 1 \ le N \ le 10 ^ 9 $ Input The input is given in the following format. $ N $ A positive integer $ N $ is given on one line. Examples Input 2 Output 1 Input 9 Output 3
instruction
0
74,924
20
149,848
"Correct Solution: ``` from math import * print(floor(log2(1+int(input())))) ```
output
1
74,924
20
149,849
Provide a correct Python 3 solution for this coding contest problem. Problem Let $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary. Given a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $. Example of calculating the function $ f (5) $: When 5 is expressed in binary, it is 101 and the sum of each digit is 1 + 0 + 1 = 2 Therefore, $ f (5) = 2 $. Note: https://ja.wikipedia.org/wiki/ Binary Ouput Outputs the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $ on one line. Constraints The input satisfies the following conditions. * $ 1 \ le N \ le 10 ^ 9 $ Input The input is given in the following format. $ N $ A positive integer $ N $ is given on one line. Examples Input 2 Output 1 Input 9 Output 3
instruction
0
74,926
20
149,852
"Correct Solution: ``` import math print((int)(math.log2(int(input())+1))) ```
output
1
74,926
20
149,853
Provide tags and a correct Python 3 solution for this coding contest problem. A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number. Input The first line contains the single number n (1 ≤ n ≤ 500) — the given integer. Output If the given integer is a triangular number output YES, otherwise output NO. Examples Input 1 Output YES Input 2 Output NO Input 3 Output YES
instruction
0
75,419
20
150,838
Tags: brute force, math Correct Solution: ``` # A. Triangular numbers n = int(input()) s = 0 for i in range(1, n+1): s += i if s == n: print('YES') break elif s > n: print('NO') break ```
output
1
75,419
20
150,839
Provide tags and a correct Python 3 solution for this coding contest problem. A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number. Input The first line contains the single number n (1 ≤ n ≤ 500) — the given integer. Output If the given integer is a triangular number output YES, otherwise output NO. Examples Input 1 Output YES Input 2 Output NO Input 3 Output YES
instruction
0
75,420
20
150,840
Tags: brute force, math Correct Solution: ``` n = int(input()) check = int(-0.5 + ((8*n+1)/4)**0.5) if check * (check+1) // 2 == n: print('YES') else: print('NO') ```
output
1
75,420
20
150,841
Provide tags and a correct Python 3 solution for this coding contest problem. A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number. Input The first line contains the single number n (1 ≤ n ≤ 500) — the given integer. Output If the given integer is a triangular number output YES, otherwise output NO. Examples Input 1 Output YES Input 2 Output NO Input 3 Output YES
instruction
0
75,421
20
150,842
Tags: brute force, math Correct Solution: ``` n=int(input()) c=0 for i in range(1,n+1): if(n==(i*(i+1))//2): c=1 break if(c): print("YES") else: print("NO") ```
output
1
75,421
20
150,843
Provide tags and a correct Python 3 solution for this coding contest problem. A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The n-th triangular number is the number of dots in a triangle with n dots on a side. <image>. You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number). Your task is to find out if a given integer is a triangular number. Input The first line contains the single number n (1 ≤ n ≤ 500) — the given integer. Output If the given integer is a triangular number output YES, otherwise output NO. Examples Input 1 Output YES Input 2 Output NO Input 3 Output YES
instruction
0
75,422
20
150,844
Tags: brute force, math Correct Solution: ``` x = int(input()) Check = False for i in range (x+1): if (i*(i+1))/2 == x : print("YES") exit() print("NO") ```
output
1
75,422
20
150,845