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
Provide a correct Python 3 solution for this coding contest problem. Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to perform a very large number of calculations to improve the calculation power and raise awareness. Exponentiation is an operation that easily produces large numbers. There are N non-negative integers A1, A2, ..., AN. We would like to find the sorts B1, B2, ..., BN that maximize B1B2 ... BN -1BN. Of course, it is common sense for rabbits, but this calculation is performed in order from the upper right. We also promise that 00 = 1. There may be multiple types of B1, B2, ..., and BN that satisfy the maximum conditions. In such a case, let's choose the smallest column in the dictionary order. Input N A1 ... AN Satisfy 1 ≀ N ≀ 100, 0 ≀ Ai ≀ 1,000,000,000. Output The output consists of N lines. Output Bi on line i. Examples Input 4 7 5 10 6 Output 5 6 7 10 Input 3 0 0 1000000000 Output 1000000000 0 0
instruction
0
81,661
20
163,322
"Correct Solution: ``` from collections import Counter import sys readline = sys.stdin.readline write = sys.stdout.write def check(N, A): if N == 1: return A A.sort() C = Counter(A) c0 = C.get(0, 0) if c0 == N: return A c1 = C.get(1, 0) rest = A[c0+c1:] back = [] if c0 > 0: if c0 % 2 == 0: back = [0]*c0 + [1]*c1 else: if c1 > 0: x = 1 c1 -= 1 else: x, *rest = rest back = [0]*(c0 ^ 1) + [x] + [0] + [1]*c1 else: back = [1]*c1 if len(rest) >= 2 and rest[-1] == 3 and rest[-2] == 2: rest[-1], rest[-2] = rest[-2], rest[-1] return rest + back def solve(): N, *A = map(int, open(0).read().split()) ans = check(N, A) write("\n".join(map(str, ans))) write("\n") solve() ```
output
1
81,661
20
163,323
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,753
20
163,506
Tags: brute force, implementation Correct Solution: ``` if __name__ == '__main__': n = int(input()) flag = False num4 = num7 = 0 while n >= 0: if n % 4 == 0: num4 = n // 4 break else: n -= 7 num7 += 1 if n < 0: print('-1') else: ex = num4 // 7 num4 -= 7 * ex num7 += 4 * ex print('4' * num4 + '7' * num7) ```
output
1
81,753
20
163,507
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,754
20
163,508
Tags: brute force, implementation Correct Solution: ``` n = int(input()) for x in range(n//7,-1,-1): if (n-x*7)%4 == 0: print ('4'*((n-x*7)//4 )+ '7'*x) break else: print (-1) ```
output
1
81,754
20
163,509
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,755
20
163,510
Tags: brute force, implementation Correct Solution: ``` # pylint: disable=unused-variable # pylint: enable=too-many-lines #* Just believe in yourself #@ Author @CAP import os import sys from io import BytesIO, IOBase import math as M import itertools as ITR from collections import defaultdict as D from collections import Counter as C from collections import deque as Q import threading from functools import lru_cache, reduce from functools import cmp_to_key as CMP from bisect import bisect_left as BL from bisect import bisect_right as BR import random as R import string import cmath,time enum=enumerate start_time = time.time() #? Variables MOD=1_00_00_00_007; MA=float("inf"); MI=float("-inf") #? Stack increment def increase_stack(): sys.setrecursionlimit(2**32//2-1) threading.stack_size(1 << 27) #sys.setrecursionlimit(10**6) #threading.stack_size(10**8) t = threading.Thread(target=main) t.start() t.join() #? Region Funtions def prints(a): print(a,end=" ") def binary(n): return bin(n)[2:] def decimal(s): return (int(s, 2)) def pow2(n): p = 0 while (n > 1): n //= 2 p += 1 return (p) def maxfactor(n): q = [] for i in range(1,int(n ** 0.5) + 1): if n % i == 0: q.append(i) if q: return q[-1] def factors(n): q = [] for i in range(1,int(n ** 0.5) + 1): if n % i == 0: q.append(i); q.append(n // i) return(list(sorted(list(set(q))))) def primeFactors(n): l=[] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(M.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n / i if n > 2: l.append(int(n)) l.sort() return (l) def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) def seive(n): a = [1] prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p ** 2,n + 1,p): prime[i] = False p = p + 1 for p in range(2,n + 1): if prime[p]: a.append(p) return(a) def maxPrimeFactors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(M.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime) def countchar(s,i): c=0 ch=s[i] for i in range(i,len(s)): if(s[i]==ch): c+=1 else: break return(c) def str_counter(a): q = [0] * 26 for i in range(len(a)): q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1 return(q) def lis(arr): n = len(arr) lis = [1] * n maximum=0 for i in range(1, n): for j in range(0, i): if arr[i] > arr[j] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 maximum=max(maximum,lis[i]) return maximum def lcm(arr): a=arr[0]; val=arr[0] for i in range(1,len(arr)): gcd=gcd(a,arr[i]) a=arr[i]; val*=arr[i] return val//gcd def ncr(n,r): return M.factorial(n) // (M.factorial(n - r) * M.factorial(r)) def npr(n,r): return M.factorial(n) // M.factorial(n - r) #? Region Taking Input def inint(): return int(inp()) def inarr(): return list(map(int,inp().split())) def invar(): return map(int,inp().split()) def instr(): s=inp() return list(s) def insarr(): return inp().split() #? 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") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) inp = lambda: sys.stdin.readline().rstrip("\r\n") #<==================================== Write The Useful Code Here ============================ #< Make it one if there is some test cases TestCases=0 #<===================== #< ======================================= """ > Sometimes later becomes never. Do it now. ! Be Better than yesterday. * Your limitationβ€”it’s only your imagination. > Push yourself, because no one else is going to do it for you. ? The harder you work for something, the greater you’ll feel when you achieve it. ! Great things never come from comfort zones. * Don’t stop when you’re tired. Stop when you’re done. > Do something today that your future self will thank you for. ? It’s going to be hard, but hard does not mean impossible. ! Sometimes we’re tested not to show our weaknesses, but to discover our strengths. """ #@ Goal is to get Candidate Master def solve(): n=inint() #total no 4 q = M.ceil(n/4) #no of sevens needed y = (q*4)-n #no of seven contributors w = q//2 #print(q,y,w) #if no pairs if y > w: print(-1); return #if exactly same pairs elif y==w and q%2==0: print(y*'7'); return res=[] rem=q-(2*y) re=rem//7 y+=(re*4) rem=rem%7 print("4"*rem+"7"*y) #! This is the Main Function def main(): flag=0 #! Checking we are offline or not try: sys.stdin = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt","r") sys.stdout = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt","w") except: flag=1 t=1 if TestCases: t = inint() for _ in range(1,t + 1): solve() if not flag: print("Time: %.4f sec"%(time.time() - start_time)) localtime = time.asctime( time.localtime(time.time()) ) print(localtime) sys.stdout.close() #? End Region if __name__ == "__main__": #? Incresing Stack Limit #increase_stack() #! Calling Main Function main() ```
output
1
81,755
20
163,511
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,756
20
163,512
Tags: brute force, implementation Correct Solution: ``` n=int(input()) count=n//7 ans=float('inf') val=None for i in range(count,-1,-1): remaining=n-7*i if remaining%4==0: if ans>i+remaining//4: ans=i+remaining//4 val=(remaining//4,i) #print(val) if val: print("4"*val[0]+"7"*val[1]) else: print(-1) ```
output
1
81,756
20
163,513
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,757
20
163,514
Tags: brute force, implementation Correct Solution: ``` n = int(input()) s = list() k = -1 f = False while n > 0: if -k > len(s) and n%4 != 0 and f: print(-1) break if n >= 7 and not f: n -= 7 s += ['7'] elif n % 4 == 0: t = n//4 s += ['4'] * t n = 0 elif len(s) > 0: s[k] = '4' n += 3 k -= 1 f = True else: f = True else: for i in reversed(s): print(i, end='') ```
output
1
81,757
20
163,515
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,758
20
163,516
Tags: brute force, implementation Correct Solution: ``` def main(n): get = lambda i: (i+(n-4*i)//7,(n-4*i)//7) ans=(float('inf'),float('inf')) for i in range(n//4+1,-1,-1): if n-4*i>=0 and (n-4*i)%7==0 : if ans>get(i): ans=get(i) print('-1' if ans==(float('inf'),float('inf')) else ("".join(['4']*(ans[0]-ans[1])+['7']*ans[1]))) main(int(input())) ''' global mem mem={} s=set({1,2,3}) def f(n): if n in mem: return mem[n] elif n in s or n<0: return '',False elif n==0: return '',True else: ret=None a=f(n-4) b=f(n-7) if a[1]: ret='4'+a[0],True elif b[1]: ret='7'+b[0],True else: ret='',False mem[n]=ret return mem[n] ''' ```
output
1
81,758
20
163,517
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,759
20
163,518
Tags: brute force, implementation Correct Solution: ``` # Author : raj1307 - Raj Singh # Date : 14.05.2021 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def msi(): return map(str,input().strip().split(" ")) def li(): return list(mi()) def dmain(): sys.setrecursionlimit(1000000) threading.stack_size(1024000) thread = threading.Thread(target=main) thread.start() #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace #from math import log,sqrt,factorial,cos,tan,sin,radians #from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right #from decimal import * #import threading #from itertools import permutations #Copy 2D list m = [x[:] for x in mark] .. Avoid Using Deepcopy abc='abcdefghijklmnopqrstuvwxyz' abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def getKey(item): return item[1] def sort2(l):return sorted(l, key=getKey,reverse=True) def d2(n,m,num):return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo (x): return (x and (not(x & (x - 1))) ) def decimalToBinary(n): return bin(n).replace("0b","") def ntl(n):return [int(i) for i in str(n)] def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1))) def ceil(x,y): if x%y==0: return x//y else: return x//y+1 def powerMod(x,y,p): res = 1 x %= p while y > 0: if y&1: res = (res*x)%p y = y>>1 x = (x*x)%p return res def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def main(): #for _ in range(ii()): n=ii() f={} for i in range(n,-1,-1): x=i*4 if x>n: continue y=n-i*4 if y%7==0: l=i+y//7 if f.get(l,0)==0: f[l]=i else: f[l]=min(f[l],i) for i in range(1,n+1): if f.get(i,-1)!=-1: print('4'*f[i],end='') print('7'*((n-(4*f[l]))//7)) return print(-1) # region fastio # template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py 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") # endregion if __name__ == "__main__": #read() main() #dmain() # Comment Read() ```
output
1
81,759
20
163,519
Provide tags and a correct Python 3 solution for this coding contest problem. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1
instruction
0
81,760
20
163,520
Tags: brute force, implementation Correct Solution: ``` x = int(input()) def luck(n): a = 0 b = 0 while(n > 0): if(n % 7 == 0): b = b+1 n = n-7 elif(n % 4 == 0): a = a+1 n = n-4 else: a = a+1 n = n-4 s = "" if(n < 0): s = "-1" return s else: s = s + "4"*a s = s + "7"*b return s print(int(luck(x))) ```
output
1
81,760
20
163,521
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` n = int(input()) x = 0 done = False while (n - 4*x)/7 >= 0 : if (n - 4*x)/7 == int((n - 4*x)/7 ) : print("4"*x + "7"*int((n - 4*x)/7 ) ) done = True break else : x += 1 if not done : print(-1) ```
instruction
0
81,761
20
163,522
Yes
output
1
81,761
20
163,523
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` n=int(input()) if(n%7==1 and n>1):print('44'+'7'*int((n-8)/7)) elif(n%7==2 and n>9):print('4444'+'7'*int((n-16)/7)) elif(n%7==3 and n>17):print('444444'+'7'*int((n-24)/7)) elif(n%7==4):print('4'+'7'*int((n-4)/7)) elif(n%7==5 and n>5):print('444'+'7'*int((n-12)/7)) elif(n%7==6 and n>6):print('44444'+'7'*int((n-20)/7)) elif(n%7==0):print('7'*int(n/7)) else:print(-1) ```
instruction
0
81,762
20
163,524
Yes
output
1
81,762
20
163,525
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` # https://codeforces.com/problemset/problem/109/A import sys import math def main(): # sys.stdin = open('E:\\Sublime\\in.txt', 'r') # sys.stdout = open('E:\\Sublime\\out.txt', 'w') # sys.stderr = open('E:\\Sublime\\err.txt', 'w') n = int(sys.stdin.readline().strip()) a, b = n//7, n % 7 c, d = b//4, b % 4 print(-1if a < d else'4'*(c+2*d)+'7'*(a-d)) if __name__ == '__main__': main() # hajj # γ€€γ€€γ€€γ€€γ€€γ€€ οΌΏοΌΏ # γ€€γ€€γ€€γ€€γ€€οΌοΌžγ€€γ€€γƒ• # γ€€γ€€γ€€γ€€γ€€| γ€€_γ€€ _ l # γ€€    /` γƒŸοΌΏxγƒŽ # γ€€γ€€ γ€€ /γ€€γ€€γ€€ γ€€ | # γ€€γ€€γ€€ /γ€€ ヽ   οΎ‰ # γ€€ γ€€ β”‚γ€€γ€€|γ€€|γ€€| #  / ̄|γ€€γ€€ |γ€€|γ€€| # γ€€| ( ̄ヽ__ヽ_)__) # γ€€οΌΌδΊŒγ€ ```
instruction
0
81,763
20
163,526
Yes
output
1
81,763
20
163,527
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` m=int(input()) n=m fours=0 sevens=0 while True: if m%7==0 : sevens+=m//7 m-=sevens*7 break elif m<=0: break else : fours+=1 m-=4 if((4*fours)+(7*sevens)==n): print("4"*fours+"7"*sevens) else: print(-1) ```
instruction
0
81,764
20
163,528
Yes
output
1
81,764
20
163,529
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` class Solution109A: def __init__(self): self.result = "-1" self.n = 0 def parse_input(self): self.n = int(input()) def solve(self): result_builder = "" num = 0 while num < self.n: if num + 4 == self.n or num + 7 < self.n > num + 14: num += 4 result_builder += "4" else: num += 7 result_builder += "7" if num == self.n: self.result = "".join(sorted(result_builder)) def get_result(self): return self.result if __name__ == "__main__": solution = Solution109A() solution.parse_input() solution.solve() print(solution.get_result()) ```
instruction
0
81,765
20
163,530
No
output
1
81,765
20
163,531
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` # pylint: disable=unused-variable # pylint: enable=too-many-lines #* Just believe in yourself #@ Author @CAP import os import sys from io import BytesIO, IOBase import math as M import itertools as ITR from collections import defaultdict as D from collections import Counter as C from collections import deque as Q import threading from functools import lru_cache, reduce from functools import cmp_to_key as CMP from bisect import bisect_left as BL from bisect import bisect_right as BR import random as R import string import cmath,time enum=enumerate start_time = time.time() #? Variables MOD=1_00_00_00_007; MA=float("inf"); MI=float("-inf") #? Stack increment def increase_stack(): sys.setrecursionlimit(2**32//2-1) threading.stack_size(1 << 27) #sys.setrecursionlimit(10**6) #threading.stack_size(10**8) t = threading.Thread(target=main) t.start() t.join() #? Region Funtions def prints(a): print(a,end=" ") def binary(n): return bin(n)[2:] def decimal(s): return (int(s, 2)) def pow2(n): p = 0 while (n > 1): n //= 2 p += 1 return (p) def maxfactor(n): q = [] for i in range(1,int(n ** 0.5) + 1): if n % i == 0: q.append(i) if q: return q[-1] def factors(n): q = [] for i in range(1,int(n ** 0.5) + 1): if n % i == 0: q.append(i); q.append(n // i) return(list(sorted(list(set(q))))) def primeFactors(n): l=[] while n % 2 == 0: l.append(2) n = n / 2 for i in range(3, int(M.sqrt(n)) + 1, 2): while n % i == 0: l.append(i) n = n / i if n > 2: l.append(int(n)) l.sort() return (l) def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) def seive(n): a = [1] prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p ** 2,n + 1,p): prime[i] = False p = p + 1 for p in range(2,n + 1): if prime[p]: a.append(p) return(a) def maxPrimeFactors(n): maxPrime = -1 while n % 2 == 0: maxPrime = 2 n >>= 1 for i in range(3, int(M.sqrt(n)) + 1, 2): while n % i == 0: maxPrime = i n = n / i if n > 2: maxPrime = n return int(maxPrime) def countchar(s,i): c=0 ch=s[i] for i in range(i,len(s)): if(s[i]==ch): c+=1 else: break return(c) def str_counter(a): q = [0] * 26 for i in range(len(a)): q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1 return(q) def lis(arr): n = len(arr) lis = [1] * n maximum=0 for i in range(1, n): for j in range(0, i): if arr[i] > arr[j] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 maximum=max(maximum,lis[i]) return maximum def lcm(arr): a=arr[0]; val=arr[0] for i in range(1,len(arr)): gcd=gcd(a,arr[i]) a=arr[i]; val*=arr[i] return val//gcd def ncr(n,r): return M.factorial(n) // (M.factorial(n - r) * M.factorial(r)) def npr(n,r): return M.factorial(n) // M.factorial(n - r) #? Region Taking Input def inint(): return int(inp()) def inarr(): return list(map(int,inp().split())) def invar(): return map(int,inp().split()) def instr(): s=inp() return list(s) def insarr(): return inp().split() #? 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") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) inp = lambda: sys.stdin.readline().rstrip("\r\n") #<==================================== Write The Useful Code Here ============================ #< Make it one if there is some test cases TestCases=0 #<===================== #< ======================================= """ > Sometimes later becomes never. Do it now. ! Be Better than yesterday. * Your limitationβ€”it’s only your imagination. > Push yourself, because no one else is going to do it for you. ? The harder you work for something, the greater you’ll feel when you achieve it. ! Great things never come from comfort zones. * Don’t stop when you’re tired. Stop when you’re done. > Do something today that your future self will thank you for. ? It’s going to be hard, but hard does not mean impossible. ! Sometimes we’re tested not to show our weaknesses, but to discover our strengths. """ #@ Goal is to get Candidate Master def solve(): n=inint() #total no 4 q = M.ceil(n/4) #no of sevens needed y = (q*4)-n #no of seven contributors w = q//2 #print(q,y,w) #if no pairs if y > w: print(-1); return #if exactly same pairs elif y==w and q%2==0: print(y*'7'); return res=[] rem=q-(2*y) print("4"*rem+"7"*y) #! This is the Main Function def main(): flag=0 #! Checking we are offline or not try: sys.stdin = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/input.txt","r") sys.stdout = open("c:/Users/Manoj Chowdary/Documents/python/CodeForces/contest-div-2/output.txt","w") except: flag=1 t=1 if TestCases: t = inint() for _ in range(1,t + 1): solve() if not flag: print("Time: %.4f sec"%(time.time() - start_time)) localtime = time.asctime( time.localtime(time.time()) ) print(localtime) sys.stdout.close() #? End Region if __name__ == "__main__": #? Incresing Stack Limit #increase_stack() #! Calling Main Function main() ```
instruction
0
81,766
20
163,532
No
output
1
81,766
20
163,533
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` n=int(input()) f=0 y=0 while(1): if (n-7*y)<0: break x=((n-(7*y))/4) if x==int(x): f=1 break y+=1 if f==0: print(-1) else: x=int(x) for i in range(x): print(4,end="") for i in range(y): print(7,end="") ```
instruction
0
81,767
20
163,534
No
output
1
81,767
20
163,535
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. Input The single line contains an integer n (1 ≀ n ≀ 106) β€” the sum of digits of the required lucky number. Output Print on the single line the result β€” the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. Examples Input 11 Output 47 Input 10 Output -1 Submitted Solution: ``` n=int(input()) k, flag = 0, True while(k<=n//4): if((n-4*k)%7==0): print('4'*k+'7'*((n-4*k)//7)) flag = False k+=1 if(flag): print(-1) ```
instruction
0
81,768
20
163,536
No
output
1
81,768
20
163,537
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,015
20
164,030
Tags: greedy, math Correct Solution: ``` n=input() l=len(n) for idx in range(l): if(n[idx]=='0'): break print(n[:idx]+n[idx+1:]) ```
output
1
82,015
20
164,031
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,016
20
164,032
Tags: greedy, math Correct Solution: ``` s = input() ans = "" checked=False for i in s: if i=='0' and not(checked): checked=True else: ans+=i print(ans if checked else ans[0:-1]) ```
output
1
82,016
20
164,033
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,017
20
164,034
Tags: greedy, math Correct Solution: ``` from functools import reduce from collections import Counter import time import datetime def time_t(): print("Current date and time: " , datetime.datetime.now()) print("Current year: ", datetime.date.today().strftime("%Y")) print("Month of year: ", datetime.date.today().strftime("%B")) print("Week number of the year: ", datetime.date.today().strftime("%W")) print("Weekday of the week: ", datetime.date.today().strftime("%w")) print("Day of year: ", datetime.date.today().strftime("%j")) print("Day of the month : ", datetime.date.today().strftime("%d")) print("Day of week: ", datetime.date.today().strftime("%A")) def ip(): return int(input()) def sip(): return input() def mip(): return map(int,input().split()) def mips(): return map(str,input().split()) def lip(): return list(map(int,input().split())) def matip(n,m): lst=[] for i in range(n): arr = lip() lst.append(arr) return lst def factors(n): # find the factors of a number return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps jumps = [0 for i in range(n)] if (n == 0) or (arr[0] == 0): return float('inf') jumps[0] = 0 for i in range(1, n): jumps[i] = float('inf') for j in range(i): if (i <= j + arr[j]) and (jumps[j] != float('inf')): jumps[i] = min(jumps[i], jumps[j] + 1) break return jumps[n-1] def dic(arr): # converting list into dict of count return Counter(arr) n = sip() if n.count('0')==0: print(int(n)-int(10**(len(n)-1))) else: n = n.replace('0','',1) print(n) ```
output
1
82,017
20
164,035
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,018
20
164,036
Tags: greedy, math Correct Solution: ``` n=input() ind=n.find('0') if ind<0: print(n[:len(n)-1]) else: print(n[:ind]+n[ind+1:]) ```
output
1
82,018
20
164,037
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,019
20
164,038
Tags: greedy, math Correct Solution: ``` a=input() x=len(a) x-=1 stat=False l='' for i in a: if i=='1': l=l+i elif i=='0' and not stat: stat=True else: l=l+i for i in range(0,x): print(l[i],end='') ```
output
1
82,019
20
164,039
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,020
20
164,040
Tags: greedy, math Correct Solution: ``` t = input() if t.count("1") == len(t): print(t[:len(t)-1]) exit() n = t.index("0") print(t[:n]+t[n+1:]) ```
output
1
82,020
20
164,041
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,021
20
164,042
Tags: greedy, math Correct Solution: ``` a=str(input()) s=list(a) l=len(s) if(s.count("1")==l): print(a[1:]) else: for i in range(l): if(s[i]=='0'): s.pop(i) print("".join(map(str,s))) break ```
output
1
82,021
20
164,043
Provide tags and a correct Python 3 solution for this coding contest problem. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610.
instruction
0
82,022
20
164,044
Tags: greedy, math Correct Solution: ``` s = input() for i in range(len(s)): if(s[i] == '0'): print(s[:i]+s[i+1:]) exit() print(s[1:]) ```
output
1
82,022
20
164,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` s = list(input()) if '0' in s: s.remove('0') else: s.pop() for i in s: print(i,end = '') ```
instruction
0
82,023
20
164,046
Yes
output
1
82,023
20
164,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` s=input() n=len(s) for i in range(n): if s[i]=="0": print(s[:i]+s[i+1:]) break else: print(s[1:]) ```
instruction
0
82,024
20
164,048
Yes
output
1
82,024
20
164,049
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` def main(): s=input() found=0 l=len(s) for i in range(l): if (s[i]=='0' or i==l-1) and not found: found=1 continue print(s[i],end='') if __name__=='__main__': main() ```
instruction
0
82,025
20
164,050
Yes
output
1
82,025
20
164,051
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` a = input() z = max(0,a.find('0')) print(a[:z]+a[z+1:]) ```
instruction
0
82,026
20
164,052
Yes
output
1
82,026
20
164,053
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` bin_num = input() bin_num = list(bin_num) while bin_num[0] == '0': bin_num.remove('0') flag = True try: bin_num.remove(bin_num[bin_num.index("0")]) bin_num = "".join(bin_num) except ValueError: bin_num = "".join(bin_num) print(bin_num) ```
instruction
0
82,027
20
164,054
No
output
1
82,027
20
164,055
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` a = input() c = False s= "" for i in a[::-1]: if c==False and i=="1": c=True if c and i=="0": c=False continue s+=i print(s[::-1]) ```
instruction
0
82,028
20
164,056
No
output
1
82,028
20
164,057
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` st=input() n=len(st) if n<3: print(st[0]) else: i=0 res=list(st) pt=n-1 while i<n-1: if res[i]=="0": pt=i # res.pop(i) # break i+=1 res.pop(pt) print("".join(res)) ```
instruction
0
82,029
20
164,058
No
output
1
82,029
20
164,059
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input The single line contains integer a, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Examples Input 101 Output 11 Input 110010 Output 11010 Note In the first sample the best strategy is to delete the second digit. That results in number 112 = 310. In the second sample the best strategy is to delete the third or fourth digits β€” that results in number 110102 = 2610. Submitted Solution: ``` ll=lambda:map(int,input().split()) t=lambda:int(input()) ss=lambda:input() lx=lambda x:map(int,input().split(x)) #from math import log10 ,log2,ceil,factorial as fac,gcd #from itertools import combinations_with_replacement as cs #from functools import reduce #from bisect import bisect_right as br,bisect_left as bl #from collections import Counter #for _ in range(t()): def f(): s=list(ss()) x=len(s)-s[::-1].index('1')-1 p="" for i in range(len(s)): if i+1 ==x: continue p+=s[i] print(p) ''' ''' f() ```
instruction
0
82,030
20
164,060
No
output
1
82,030
20
164,061
Provide tags and a correct Python 3 solution for this coding contest problem. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1. Input The first line contains two integers, p and n (2 ≀ p, n ≀ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≀ xi ≀ 109). Output Output a single integer β€” the answer to the problem. Examples Input 10 5 0 21 53 41 53 Output 4 Input 5 5 0 1 2 3 4 Output -1
instruction
0
82,066
20
164,132
Tags: implementation Correct Solution: ``` p, n = [int(x) for x in input().split()] s = set() f = True answer = -1 for i in range(n): x = int(input()) if x%p not in s: s.add(x%p) elif f: answer = i+1 f = False print(answer) ```
output
1
82,066
20
164,133
Provide tags and a correct Python 3 solution for this coding contest problem. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1. Input The first line contains two integers, p and n (2 ≀ p, n ≀ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≀ xi ≀ 109). Output Output a single integer β€” the answer to the problem. Examples Input 10 5 0 21 53 41 53 Output 4 Input 5 5 0 1 2 3 4 Output -1
instruction
0
82,067
20
164,134
Tags: implementation Correct Solution: ``` p, n = map(int, input().split()) result_dict = {} a = [int(input()) for _ in range(n)] index = 0 while index < len(a): if a[index] % p in result_dict: print(index + 1) break else: result_dict[a[index] % p] = a[index] index += 1 if index == len(a): print(-1) ```
output
1
82,067
20
164,135
Provide tags and a correct Python 3 solution for this coding contest problem. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1. Input The first line contains two integers, p and n (2 ≀ p, n ≀ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≀ xi ≀ 109). Output Output a single integer β€” the answer to the problem. Examples Input 10 5 0 21 53 41 53 Output 4 Input 5 5 0 1 2 3 4 Output -1
instruction
0
82,069
20
164,138
Tags: implementation Correct Solution: ``` n,k = map(int,input().split()) d=0 l=[] c=[] for i in range(k): x=int(input()) l.append(x) for i in range(k): j=l[i]%n if j not in c: c.append(j) else: d=i+1 break if d==0: print(-1) else: print(d) ```
output
1
82,069
20
164,139
Provide tags and a correct Python 3 solution for this coding contest problem. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1. Input The first line contains two integers, p and n (2 ≀ p, n ≀ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≀ xi ≀ 109). Output Output a single integer β€” the answer to the problem. Examples Input 10 5 0 21 53 41 53 Output 4 Input 5 5 0 1 2 3 4 Output -1
instruction
0
82,071
20
164,142
Tags: implementation Correct Solution: ``` p,n=map(int,input().split()) ans=[] for i in range(n): x=int(input()) ans.append(x%p) z=[] for i in range(0,n-1): for j in range(i+1,n): if ans[i]==ans[j]: z.append(j+1) else: continue if len(z)==0: print("-1") else: print(min(z)) ```
output
1
82,071
20
164,143
Provide tags and a correct Python 3 solution for this coding contest problem. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b. However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1. Input The first line contains two integers, p and n (2 ≀ p, n ≀ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≀ xi ≀ 109). Output Output a single integer β€” the answer to the problem. Examples Input 10 5 0 21 53 41 53 Output 4 Input 5 5 0 1 2 3 4 Output -1
instruction
0
82,072
20
164,144
Tags: implementation Correct Solution: ``` if __name__ == '__main__': p, n = str(input()).split() p = int(p) n = int(n) line = list() flag = True mark = 0 for i in range(n): if flag: c = int(input()) % p if c in line: mark = i + 1 flag = False line.append(c) if flag: print(-1) else: print(mark) ```
output
1
82,072
20
164,145
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,331
20
164,662
Tags: brute force, greedy Correct Solution: ``` n=int(input()) l=(list(str(n)))[::-1] g=[] def verif(l): if l[-1]!='0':return(0) else: return(1+verif(l[:-1])) def permut(l,c,c1): i=l.copy() k=0 while(True): if i.index(c)==0:break else: j=i.index(c) i[j],i[j-1]=i[j-1],i[j] k+=1 m=i[1:] while(True): if m.index(c1)==0:break else: j=m.index(c1) m[j],m[j-1]=m[j-1],m[j] k+=1 k+=verif(i) return(k) if (('2'in l) and ('5' in l)): g.append(permut(l,'5','2')) if (('5'in l) and ('0' in l)): g.append(permut(l,'0','5')) if (('7'in l) and ('5' in l)): g.append(permut(l,'5','7')) if l.count('0')>1: g.append(permut(l,'0','0')) if g==[]:print(-1) else:print(min(g)) ```
output
1
82,331
20
164,663
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,332
20
164,664
Tags: brute force, greedy Correct Solution: ``` # Codeforces Round #486 (Div. 3) from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import sys def getIntList(): return list(map(int, input().split())) s0 = input() def work(s0, st): x = s0.rfind(st[1]) if x<0: return 10000 r = 0 r += len(s0) - x -1 s0 = s0[:x] + s0[x+1:] x = s0.rfind(st[0]) if x<0: return 10000 r += len(s0) - x -1 s0 = s0[:x] + s0[x+1:] if not s0: return r if s0 == '0' * len(s0) : return 10000 for i in range(len(s0)): if s0[i] != '0': return r+ i return 10000 sz = ['00', '25', '50', '75'] z = [work(s0,s) for s in sz] r = min(z) if r>1000: r = -1 print(r) ```
output
1
82,332
20
164,665
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,333
20
164,666
Tags: brute force, greedy Correct Solution: ``` s=input()[::-1] m=I=41 f=s.find('5')+1 i=s.find('0')+1 t=len(s) if i: j=min(s.find('0',i)+1or I,f or I) if j<I: m=i+j-3 if j<i:m+=1 if f: j=min(s.find('2')+1or I,s.find('7')+1or I) if j<I: l=f+j-3 if j<f:l+=1 if f==t: i=t-1 while s[i-1]=='0': l+=1;i-=1 m=min(m,l) print((-1,m)[m<I]) ```
output
1
82,333
20
164,667
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,334
20
164,668
Tags: brute force, greedy Correct Solution: ``` s = input()[::-1] ans = 10 ** 9 mp = {'0': '05', '5': '27'} for i in range(len(s)): if s[i] not in mp: continue rem = s[:i] + s[i + 1:] for j in range(len(rem)): if rem[j] not in mp[s[i]]: continue rem2 = rem[:j] + rem[j + 1:] if rem2: lastnz = -1 while lastnz >= -len(rem2) and rem2[lastnz] == '0': lastnz -= 1 if lastnz < -len(rem2): continue lastnz = -lastnz - 1 else: lastnz = 0 ans = min(ans, i + j + lastnz) print(-1 if ans == 10 ** 9 else ans) ```
output
1
82,334
20
164,669
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,335
20
164,670
Tags: brute force, greedy Correct Solution: ``` import sys,math from collections import deque,defaultdict import operator as op from functools import reduce from itertools import permutations import heapq #sys.setrecursionlimit(10**6) #OneDrive\Documents\codeforces I=sys.stdin.readline alpha="abcdefghijklmnopqrstuvwxyz" """ x_move=[-1,0,1,0,-1,1,1,-1] y_move=[0,1,0,-1,1,1,-1,-1] """ def ii(): return int(I().strip()) def li(): return list(map(int,I().strip().split())) def mi(): return map(int,I().strip().split()) def ncr(n, r): r = min(r, n-r) numer = reduce(op.mul, range(n, n-r, -1), 1) denom = reduce(op.mul, range(1, r+1), 1) return numer // denom def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n): if n<=1: return False elif n<=2: return True else: for i in range(2,int(n**.5)+1): if n%i==0: return False return True #print("Case #"+str(_+1)+":",abs(cnt-k)) def f(s,a,b,c): arr=list(s) cost1=c l=len(arr)-1 f=0 for need in [b,a]: for i in range(l,-1,-1): if arr[i]==need: f+=1 x=i while x!=l: cost1+=1 arr[x],arr[x+1]=arr[x+1],arr[x] x+=1 break l-=1 if f!=2 or arr[0]=="0": cost1=math.inf return cost1 def main(): n=ii() ans=math.inf s=str(n) i=0 while i<len(s): if s[i]!="0": tmp=list(s) x=i c=0 while x!=0: tmp[x],tmp[x-1]=tmp[x-1],tmp[x] x-=1 c+=1 tmp="".join(tmp) ans=min(ans,f(tmp,"0","0",c),f(tmp,"2","5",c),f(tmp,"5","0",c),f(tmp,"7","5",c)) i+=1 if ans==math.inf: print(-1) else: print(ans) if __name__ == '__main__': main() ```
output
1
82,335
20
164,671
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,336
20
164,672
Tags: brute force, greedy Correct Solution: ``` def swipe(s, i): return s[:i] + s[i + 1] + s[i] + (s[i + 2:] if i + 2 < len(s) else "") def nazis(s): m = float("inf") for i in range(9): if s.find(str(i + 1)) > -1: m = min(s.find(str(i + 1)), m) return m n = input() c = float("inf") if n.count("0") >= 2 or "5" in n and "0" in n or "2" in n and "5" in n or "7" in n and "5" in n: s = n if n.count("0") >= 2: a = n.rfind("0") b = n.rfind("0", 0, a) c = 2 * len(n) - a - b - 3 if "5" in n and "0" in n: cc = 0 a = n.rfind("0") while n[-1] != "0": n = swipe(n, a) a += 1 cc += 1 b = n.rfind("5") while n[-2] != "5": n = swipe(n, b) b += 1 cc += 1 if n[0] == "0": cc += nazis(n) c = min(c, cc) if "2" in n and "5" in n: n = s cc = 0 b = n.rfind("5") while n[-1] != "5": n = swipe(n, b) b += 1 cc += 1 a = n.rfind("2") while n[-2] != "2": n = swipe(n, a) a += 1 cc += 1 if n[0] == "0": cc += nazis(n) c = min(c, cc) if "7" in n and "5" in n: n = s cc = 0 b = n.rfind("5") while n[-1] != "5": n = swipe(n, b) b += 1 cc += 1 a = n.rfind("7") while n[-2] != "7": n = swipe(n, a) a += 1 cc += 1 if n[0] == "0": cc += nazis(n) c = min(c, cc) print(c) else: print(-1) ```
output
1
82,336
20
164,673
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,337
20
164,674
Tags: brute force, greedy Correct Solution: ``` n = input() #if int(n) % 25 == 0: # print(0) # quit() n = list(n) if (not("5" in n)) and (not("0" in n)) and (not("7" in n)) and (not("2" in n)): print(-1) quit() wkn = [] wkn[:] = n ans = -1 for i in reversed(range(len(n))): if (n[i] == "0"): wk1 = n[:i] + n[i + 1:] + [n[i]] ans = len(n) - i - 1 if wk1[0] != "0": n[:] = wk1 break else: count = 0 f1 = True for j in wk1: count += 1 if j != "0": f1 = False break if f1: ans = -1 break ans += count - 1 wk1 = [wk1[count - 1]] + wk1[:count - 1] + wk1[count:] n[:] = wk1 break if ans != -1: f = True for i in reversed(range(len(n) - 1)): if (n[i] == "0") or (n[i] == "5"): wk1 = n[:i] + n[i + 1:-1] + [n[i]] ans += len(n) - i - 2 if wk1[0] != "0": f = False break else: count = 0 f1 = True for j in wk1: count += 1 if j != "0": f1 = False break if f1: ans = -1 break ans += count - 1 f = False break if f: ans = -1 wkans = ans ans = -1 n = wkn for i in reversed(range(len(n))): if (n[i] == "5"): wk1 = n[:i] + n[i + 1:] + [n[i]] ans = len(n) - i - 1 if wk1[0] != "0": n[:] = wk1 break else: count = 0 f1 = True for j in wk1: count += 1 if j != "0": f1 = False break if f1: ans = -1 break ans += count - 1 wk1 = [wk1[count - 1]] + wk1[:count - 1] + wk1[count:] n[:] = wk1 break if ans != -1: f = True for i in reversed(range(len(n) - 1)): if (n[i] == "7") or (n[i] == "2"): wk1 = n[:i] + n[i + 1: -1] + [n[i]] ans += len(n) - i - 2 if wk1[0] != "0": f = False break else: count = 0 f1 = True for j in wk1: count += 1 if j != "0": f1 = False break if f1: ans = -1 break ans += count - 1 f = False break if f: ans = -1 if (wkans == -1): print(ans) quit() if (ans == -1): print(wkans) quit() print(min(ans, wkans)) ```
output
1
82,337
20
164,675
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150.
instruction
0
82,338
20
164,676
Tags: brute force, greedy Correct Solution: ``` maxint = 2147483647 class mylist(list): def index(self, obj, *args): try: if len(args) == 0: return super(mylist, self).index(obj) if len(args) == 1: return super(mylist, self).index(obj,args[0]) return super(mylist, self).index(obj,args[0],args[1]) except ValueError: return -1 def cost(target,index1, index2): if index1 == -1 or index2 == -1: return maxint if target == '00': return index1 + index2 -1 else: return index1 + index2 -1 if index2<index1 else index1+index2 def calcCosts(rn): i0 = rn.index('0') i00 = rn.index('0',i0+1) i2 = rn.index('2') i5 = rn.index('5') i7 = rn.index('7') costs = [('00',cost('00',i0,i00)),('50',cost('50',i5,i0)),('25',cost('25',i2,i5)),('75',cost('75',i7,i5))] costs.sort(key=lambda tup:tup[1]) return costs def swapCritical(rn,i): if i == len(rn)-1: for index in range(i-1,-1,-1): if rn[index] != '0': break else: index = i-1 rn[index],rn[index+1] = rn[index+1], rn[index] return rn def swap(rn,typ): if typ == '00': i0 = rn.index('0') i00 = rn.index('0',i0+1) if i0 != 0: rn[i0-1], rn[i0] = rn[i0], rn[i0-1] return rn, 1 if i00 == 1: return rn, 0 rn[i00-1], rn[i00] = rn[i00], rn[i00-1] return rn, 1 if typ == '50': i0 = rn.index('0') i5 = rn.index('5') if i0 != 0: if i0<i5 or i5 == 0: rn[i0-1], rn[i0] = rn[i0], rn[i0-1] return rn, 1 rn[i5-1], rn[i5] = rn[i5], rn[i5-1] return rn, 1 if i5 == 1: return rn, 0 if i5 != len(rn)-1: rn[i5-1], rn[i5] = rn[i5], rn[i5-1] return rn, 1 rn = swapCritical(rn,i5) return rn, 1 if typ == '25': i2 = rn.index('2') i5 = rn.index('5') if i5 != 0: if i5<i2 or i2 == 0: swapCritical(rn,i5) return rn, 1 rn[i2-1], rn[i2] = rn[i2], rn[i2-1] return rn, 1 if i2 == 1: return rn, 0 if i2 != len(rn)-1: rn[i2-1], rn[i2] = rn[i2], rn[i2-1] return rn, 1 rn = swapCritical(rn,i2) return rn, 1 if typ == '75': i7 = rn.index('7') i5 = rn.index('5') if i5 != 0: if i5<i7 or i7 == 0: swapCritical(rn,i5) return rn, 1 rn[i7-1], rn[i7] = rn[i7], rn[i7-1] return rn, 1 if i7 == 1: return rn, 0 if i7 != len(rn)-1: rn[i7-1], rn[i7] = rn[i7], rn[i7-1] return rn, 1 rn = swapCritical(rn,i7) return rn, 1 def realCost(rn,maximum): costs = calcCosts(rn) bestCost = maximum for cost in costs: if cost[1] >= bestCost: return bestCost newrn = mylist(rn) newrn,tempcost = swap(newrn,cost[0]) if tempcost == 0: return 0 thiscost = tempcost + realCost(newrn,bestCost-1) if thiscost < bestCost: bestCost = thiscost n = input() rn = n[::-1] rn = mylist(rn) rcost = realCost(rn,maxint) print(rcost if rcost<maxint else -1) ```
output
1
82,338
20
164,677
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150. Submitted Solution: ``` n=input() #25 if('2' not in n or '5' not in n):a=10**18 else: a=0 i=len(n)-1 while n[i]!='5': i-=1 a+=1 updated_n=n[0:i]+n[i+1:] i=len(n)-2 while updated_n[i]!='2': i-=1 a+=1 updated_n=updated_n[0:i]+updated_n[i+1:] for i in range(len(updated_n)): if(updated_n[i]!='0'): break a+=i #75 if('7' not in n or '5' not in n):b=10**18 else: b=0 i=len(n)-1 while n[i]!='5': i-=1 b+=1 updated_n=n[0:i]+n[i+1:] i=len(n)-2 while updated_n[i]!='7': i-=1 b+=1 updated_n=updated_n[0:i]+updated_n[i+1:] for i in range(len(updated_n)): if(updated_n[i]!='0'): break b+=i #50 if('5' not in n or '0' not in n):c=10**18 else: c=0 i=len(n)-1 while n[i]!='0': i-=1 c+=1 updated_n=n[0:i]+n[i+1:] i=len(n)-2 while updated_n[i]!='5': i-=1 c+=1 updated_n=updated_n[0:i]+updated_n[i+1:] for i in range(len(updated_n)): if(updated_n[i]!='0'): break c+=i #00 if(n.count('0')<2):d=10**18 else: d=0 i=len(n)-1 while n[i]!='0': i-=1 d+=1 updated_n=n[0:i]+n[i+1:] i=len(n)-2 while updated_n[i]!='0': i-=1 d+=1 updated_n=updated_n[0:i]+updated_n[i+1:] for i in range(len(updated_n)): if(updated_n[i]!='0'): break d+=i ans=min(a,b,c,d) if(ans==10**18):print(-1) else:print(ans) ```
instruction
0
82,339
20
164,678
Yes
output
1
82,339
20
164,679
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150. Submitted Solution: ``` def digits(n): return len(str(n)) def digit(n, i): if i < digits(n): return int(str(n)[digits(n) - i - 1]) return 0 def swap_digits(n, i, j): return n + digit(n, i) * (10**j - 10**i) + digit(n, j) * (10**i - 10**j) n = int(input()) if n % 25 == 0: print(0) exit() ans = [] for i in range(digits(n)): for j in range(digits(n)): if i == j: continue x, y, cur, cur_ans = i, j, n, 0 if y > x: x += 1 while y > 0: cur = swap_digits(cur, y, y - 1) y -= 1 cur_ans += 1 while x > 1: cur = swap_digits(cur, x, x - 1) x -= 1 cur_ans += 1 for k in range(digits(n), -1, -1): if digit(cur, k) != 0: cur_ans += (digits(n) - 1) - k break if cur % 25 == 0: ans.append(cur_ans) print(min(ans) if len(ans) != 0 else -1) ```
instruction
0
82,340
20
164,680
Yes
output
1
82,340
20
164,681
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150. Submitted Solution: ``` def swap(ar,ind1,ind2): if ind2 > ind1: for i in range(ind1,ind2): temp = ar[i] ar[i] = ar[i+1] ar[i+1] = temp else: for i in range(ind1,ind2,-1): temp = ar[i] ar[i] = ar[i-1] ar[i-1] = temp n = list(input()) n2 = len(n) ans = 100 for i in range(n2): for j in range(n2): nc = [0]*n2 for i2 in range(n2): nc[i2] = n[i2] swap(nc,i,n2-1) swap(nc,j,n2-2) num = 0 for z in range(n2): if nc[z] != "0": num = z break swap(nc,0,num) if int("".join(nc)) % 25 == 0: ans = min(ans,abs(n2-2-j)+abs(n2-1-i)+num) if ans == 100: print(-1) else: print(ans) ```
instruction
0
82,341
20
164,682
Yes
output
1
82,341
20
164,683
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an integer n from 1 to 10^{18} without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the minimum number of moves you have to make to obtain a number that is divisible by 25? Print -1 if it is impossible to obtain a number that is divisible by 25. Input The first line contains an integer n (1 ≀ n ≀ 10^{18}). It is guaranteed that the first (left) digit of the number n is not a zero. Output If it is impossible to obtain a number that is divisible by 25, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number. Examples Input 5071 Output 4 Input 705 Output 1 Input 1241367 Output -1 Note In the first example one of the possible sequences of moves is 5071 β†’ 5701 β†’ 7501 β†’ 7510 β†’ 7150. Submitted Solution: ``` # https://codeforces.com/problemset/problem/988/E INF = float('inf') def count_min_steps(num_str): result = INF for i, c1 in enumerate(num_str): suffix = num_str[:i] + num_str[i + 1:] for j, c2 in enumerate(suffix): swap_str = suffix[:j] + suffix[j + 1:] + c2 + c1 if swap_str[0] != '0' and int(swap_str) % 25 == 0: result = min(result, len(num_str) + len(suffix) - i - j - 2) return result def solve(num_str): result = INF for i, c in enumerate(num_str): swap_str = num_str[i] + num_str[:i] + num_str[i + 1:] result = min(result, count_min_steps(swap_str) + i) return result if __name__ == '__main__': number_str = input() result = solve(number_str) print(-1 if result == INF else result) ```
instruction
0
82,342
20
164,684
Yes
output
1
82,342
20
164,685