message
stringlengths
2
22.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
145
109k
cluster
float64
9
9
__index_level_0__
int64
290
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets are numbered with integers from 1 to n and the avenues are numbered with integers from 1 to m. The cost of dinner in the restaurant at the intersection of the i-th street and the j-th avenue is cij. Jack and Emma decide to choose the restaurant in the following way. Firstly Emma chooses the street to dinner and then Jack chooses the avenue. Emma and Jack makes their choice optimally: Emma wants to maximize the cost of the dinner, Jack wants to minimize it. Emma takes into account that Jack wants to minimize the cost of the dinner. Find the cost of the dinner for the couple in love. Input The first line contains two integers n, m (1 ≤ n, m ≤ 100) — the number of streets and avenues in Munhattan. Each of the next n lines contains m integers cij (1 ≤ cij ≤ 109) — the cost of the dinner in the restaurant on the intersection of the i-th street and the j-th avenue. Output Print the only integer a — the cost of the dinner for Jack and Emma. Examples Input 3 4 4 1 3 5 2 2 2 2 5 4 5 1 Output 2 Input 3 3 1 2 3 2 3 1 3 1 2 Output 1 Note In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2. In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the dinner 1. Submitted Solution: ``` hola="hola" ```
instruction
0
54,407
9
108,814
No
output
1
54,407
9
108,815
Provide tags and a correct Python 3 solution for this coding contest problem. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A.
instruction
0
54,931
9
109,862
Tags: binary search, constructive algorithms, greedy, implementation Correct Solution: ``` from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # 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) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa=ifa[::-1] def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def lowbit(n): return n&-n def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans ''' class SMT: def __init__(self,arr): self.n=len(arr)-1 self.arr=[0]*(self.n<<2) self.lazy=[0]*(self.n<<2) def Build(l,r,rt): if l==r: self.arr[rt]=arr[l] return m=(l+r)>>1 Build(l,m,rt<<1) Build(m+1,r,rt<<1|1) self.pushup(rt) Build(1,self.n,1) def pushup(self,rt): self.arr[rt]=self.arr[rt<<1]+self.arr[rt<<1|1] def pushdown(self,rt,ln,rn):#lr,rn表区间数字数 if self.lazy[rt]: self.lazy[rt<<1]+=self.lazy[rt] self.lazy[rt<<1|1]+=self.lazy[rt] self.arr[rt<<1]+=self.lazy[rt]*ln self.arr[rt<<1|1]+=self.lazy[rt]*rn self.lazy[rt]=0 def update(self,L,R,c,l=1,r=None,rt=1):#L,R表示操作区间 if r==None: r=self.n if L<=l and r<=R: self.arr[rt]+=c*(r-l+1) self.lazy[rt]+=c return m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) if L<=m: self.update(L,R,c,l,m,rt<<1) if R>m: self.update(L,R,c,m+1,r,rt<<1|1) self.pushup(rt) def query(self,L,R,l=1,r=None,rt=1): if r==None: r=self.n #print(L,R,l,r,rt) if L<=l and R>=r: return self.arr[rt] m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) ans=0 if L<=m: ans+=self.query(L,R,l,m,rt<<1) if R>m: ans+=self.query(L,R,m+1,r,rt<<1|1) return ans ''' class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]<self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)] class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break #print(flag) return flag def dij(s,graph): d={} d[s]=0 heap=[(0,s)] seen=set() while heap: dis,u=heappop(heap) if u in seen: continue for v in graph[u]: if v not in d or d[v]>d[u]+graph[u][v]: d[v]=d[u]+graph[u][v] heappush(heap,(d[v],v)) return d def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj @bootstrap def gdfs(r,p): if len(g[r])==1 and p!=-1: yield None for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None t=0 for i in range(t): n=N() a=RLL() b=RLL() if n==1: if a==b: print('small') print('0') print() else: print('impossible') elif n==2: if a==b: print('small') print('0') print() elif a==b[::-1]: print('small') print('1') print('r') else: x,y=min(a),max(a) ans='' p,q=min(b),max(b) c=0 while p>x: c+=(q//p) if c<=2*10**5: ans+='p'*(q//p) p,q=q%p,p ans+='r' #print(x,y,p,q,ans) if p<x: print('impossible') else: if q<y or (q-y)%x: print('impossible') else: c+=(q-y)//x if c>2*10**5: print('big') print(c) else: ans+='p'*((q-y)//x) print('small') res='' if a==[y,x]: res+='r' res+=ans[::-1] if b==[q,p]: res+='r' print(len(res)) print(res) else: ans='' c=0 f=False while True: if b==a: f=True break elif b==a[::-1]: ans+='r' f=True break else: if all(b[i]<b[i+1] for i in range(n-1)): b=[b[i]-b[i-1] if i else b[i] for i in range(n)] ans+='p' c+=1 elif all(b[i]>b[i+1] for i in range(n-1)): ans+='r' b.reverse() b=[b[i]-b[i-1] if i else b[i] for i in range(n)] ans+='p' c+=1 else: break if not f: print('impossible') else: if c>2*10**5: print('big') print(c) else: print('small') print(len(ans)) print(ans[::-1]) def is_asc(arr): a = arr[0] for b in arr[1:]: if a < b: a = b else: return False return True def is_des(arr): a = arr[0] for b in arr[1:]: if a > b: a = b else: return False return True N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) # print(N, A, B) result = [] count = 0 found = False if N == 1: if A[0] == B[0]: found = True elif N == 2: while True: if B[1] == 0: break if A[1] == B[1] and B[0] == A[0]: found = True break if A[0] == B[1] and B[0] == A[1]: result.append('R') found = True break if B[0] > B[1]: result.append('R') B.reverse() if B[0] < B[1]: if A[0] <= A[1]: if A[0] == B[0] and (B[1] - A[1]) % A[0] == 0: c = (B[1] - A[1]) // A[0] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c found = True break else: if A[1] == B[0] and (B[1] - A[0]) % A[1] == 0: c = (B[1] - A[0]) // A[1] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c result.append('R') found = True break c = B[1] // B[0] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c B[1] = B[1] % B[0] else: break # print(B,result) else: while True: for a, b in zip(A, B): if a != b: eq = False break else: found = True break B.reverse() for a, b in zip(A, B): if a != b: eq = False break else: found = True result.append('R') break B.reverse() if is_des(B): B.reverse() result.append('R') count += 1 result.append('P') for i in range(len(B) - 1, 0, -1): B[i] = B[i] - B[i - 1] elif is_asc(B): result.append('P') count += 1 for i in range(len(B) - 1, 0, -1): B[i] = B[i] - B[i - 1] else: break # print(B, result) if found: if count <= 2 * 10 ** 5: print('SMALL') print(len(result)) result.reverse() print(''.join(result)) else: print('BIG') print(count) else: print('IMPOSSIBLE') ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ```
output
1
54,931
9
109,863
Provide tags and a correct Python 3 solution for this coding contest problem. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A.
instruction
0
54,932
9
109,864
Tags: binary search, constructive algorithms, greedy, implementation Correct Solution: ``` from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import BytesIO, IOBase # 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) input = lambda: sys.stdin.readline().rstrip("\r\n") #------------------------------------------------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def RLL(): return list(map(int, sys.stdin.readline().rstrip().split())) def N(): return int(input()) #------------------------------------------------------------------------ from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc farr=[1] ifa=[] def fact(x,mod=0): if mod: while x>=len(farr): farr.append(farr[-1]*len(farr)%mod) else: while x>=len(farr): farr.append(farr[-1]*len(farr)) return farr[x] def ifact(x,mod): global ifa ifa.append(pow(farr[-1],mod-2,mod)) for i in range(x,0,-1): ifa.append(ifa[-1]*i%mod) ifa=ifa[::-1] def per(i,j,mod=0): if i<j: return 0 if not mod: return fact(i)//fact(i-j) return farr[i]*ifa[i-j]%mod def com(i,j,mod=0): if i<j: return 0 if not mod: return per(i,j)//fact(j) return per(i,j,mod)*ifa[j]%mod def catalan(n): return com(2*n,n)//(n+1) def isprime(n): for i in range(2,int(n**0.5)+1): if n%i==0: return False return True def lowbit(n): return n&-n def inverse(a,m): a%=m if a<=1: return a return ((1-inverse(m,a)*m)//a)%m class BIT: def __init__(self,arr): self.arr=arr self.n=len(arr)-1 def update(self,x,v): while x<=self.n: self.arr[x]+=v x+=x&-x def query(self,x): ans=0 while x: ans+=self.arr[x] x&=x-1 return ans ''' class SMT: def __init__(self,arr): self.n=len(arr)-1 self.arr=[0]*(self.n<<2) self.lazy=[0]*(self.n<<2) def Build(l,r,rt): if l==r: self.arr[rt]=arr[l] return m=(l+r)>>1 Build(l,m,rt<<1) Build(m+1,r,rt<<1|1) self.pushup(rt) Build(1,self.n,1) def pushup(self,rt): self.arr[rt]=self.arr[rt<<1]+self.arr[rt<<1|1] def pushdown(self,rt,ln,rn):#lr,rn表区间数字数 if self.lazy[rt]: self.lazy[rt<<1]+=self.lazy[rt] self.lazy[rt<<1|1]+=self.lazy[rt] self.arr[rt<<1]+=self.lazy[rt]*ln self.arr[rt<<1|1]+=self.lazy[rt]*rn self.lazy[rt]=0 def update(self,L,R,c,l=1,r=None,rt=1):#L,R表示操作区间 if r==None: r=self.n if L<=l and r<=R: self.arr[rt]+=c*(r-l+1) self.lazy[rt]+=c return m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) if L<=m: self.update(L,R,c,l,m,rt<<1) if R>m: self.update(L,R,c,m+1,r,rt<<1|1) self.pushup(rt) def query(self,L,R,l=1,r=None,rt=1): if r==None: r=self.n #print(L,R,l,r,rt) if L<=l and R>=r: return self.arr[rt] m=(l+r)>>1 self.pushdown(rt,m-l+1,r-m) ans=0 if L<=m: ans+=self.query(L,R,l,m,rt<<1) if R>m: ans+=self.query(L,R,m+1,r,rt<<1|1) return ans ''' class DSU:#容量+路径压缩 def __init__(self,n): self.c=[-1]*n def same(self,x,y): return self.find(x)==self.find(y) def find(self,x): if self.c[x]<0: return x self.c[x]=self.find(self.c[x]) return self.c[x] def union(self,u,v): u,v=self.find(u),self.find(v) if u==v: return False if self.c[u]<self.c[v]: u,v=v,u self.c[u]+=self.c[v] self.c[v]=u return True def size(self,x): return -self.c[self.find(x)] class UFS:#秩+路径 def __init__(self,n): self.parent=[i for i in range(n)] self.ranks=[0]*n def find(self,x): if x!=self.parent[x]: self.parent[x]=self.find(self.parent[x]) return self.parent[x] def union(self,u,v): pu,pv=self.find(u),self.find(v) if pu==pv: return False if self.ranks[pu]>=self.ranks[pv]: self.parent[pv]=pu if self.ranks[pv]==self.ranks[pu]: self.ranks[pu]+=1 else: self.parent[pu]=pv def Prime(n): c=0 prime=[] flag=[0]*(n+1) for i in range(2,n+1): if not flag[i]: prime.append(i) c+=1 for j in range(c): if i*prime[j]>n: break flag[i*prime[j]]=prime[j] if i%prime[j]==0: break #print(flag) return flag def dij(s,graph): d={} d[s]=0 heap=[(0,s)] seen=set() while heap: dis,u=heappop(heap) if u in seen: continue for v in graph[u]: if v not in d or d[v]>d[u]+graph[u][v]: d[v]=d[u]+graph[u][v] heappush(heap,(d[v],v)) return d def GP(it): return [[ch,len(list(g))] for ch,g in groupby(it)] class DLN: def __init__(self,val): self.val=val self.pre=None self.next=None def nb(i,j): for ni,nj in [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]: if 0<=ni<n and 0<=nj<m: yield ni,nj @bootstrap def gdfs(r,p): if len(g[r])==1 and p!=-1: yield None for ch in g[r]: if ch!=p: yield gdfs(ch,r) yield None t=1 for i in range(t): n=N() a=RLL() b=RLL() if n==1: if a==b: print('small') print('0') print() else: print('impossible') elif n==2: if a==b: print('small') print('0') print() elif a==b[::-1]: print('small') print('1') print('r') else: x,y=min(a),max(a) ans='' p,q=min(b),max(b) c=0 while p>x: c+=(q//p) if c<=2*10**5: ans+='p'*(q//p) p,q=q%p,p ans+='r' #print(x,y,p,q,ans) if p<x: print('impossible') else: if q<y or (q-y)%x: print('impossible') else: c+=(q-y)//x if c>2*10**5: print('big') print(c) else: ans+='p'*((q-y)//x) print('small') res='' if a==[y,x]: res+='r' res+=ans[::-1] if b[0]>b[1]: res+='r' print(len(res)) print(res) else: ans=[] c=0 f=True ar=a[::-1] while b!=a and b!=ar: if b[1]<b[0]: b.reverse() ans.append('R') b=[b[i]-b[i-1] if i else b[i] for i in range(n)] if min(b)<=0: f=False break ans.append('P') c+=1 if not f: print('impossible') else: if c>2*10**5: print('big') print(c) else: if b==ar: ans.append('R') ans.reverse() print('small') print(len(ans)) print(''.join(ans)) ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ''' sys.setrecursionlimit(200000) import threading threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ''' ```
output
1
54,932
9
109,865
Provide tags and a correct Python 3 solution for this coding contest problem. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A.
instruction
0
54,933
9
109,866
Tags: binary search, constructive algorithms, greedy, implementation Correct Solution: ``` # from bisect import bisect_left def is_asc(arr): a = arr[0] for b in arr[1:]: if a < b: a = b else: return False return True def is_des(arr): a = arr[0] for b in arr[1:]: if a > b: a = b else: return False return True N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) # print(N, A, B) result = [] count = 0 found = False if N == 1: if A[0] == B[0]: found = True elif N == 2: while True: if B[1] == 0: break if A[1] == B[1] and B[0] == A[0]: found = True break if A[0] == B[1] and B[0] == A[1]: result.append('R') found = True break if B[0] > B[1]: result.append('R') B.reverse() if B[0] < B[1]: if A[0] <= A[1]: if A[0] == B[0] and (B[1] - A[1]) % A[0] == 0: c = (B[1] - A[1]) // A[0] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c found = True break else: if A[1] == B[0] and (B[1] - A[0]) % A[1] == 0: c = (B[1] - A[0]) // A[1] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c result.append('R') found = True break c = B[1] // B[0] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c B[1] = B[1] % B[0] else: break # print(B,result) else: while True: for a, b in zip(A, B): if a != b: eq = False break else: found = True break B.reverse() for a, b in zip(A, B): if a != b: eq = False break else: found = True result.append('R') break B.reverse() if is_des(B): B.reverse() result.append('R') count += 1 result.append('P') for i in range(len(B) - 1, 0, -1): B[i] = B[i] - B[i - 1] elif is_asc(B): result.append('P') count += 1 for i in range(len(B) - 1, 0, -1): B[i] = B[i] - B[i - 1] else: break # print(B, result) if found: if count <= 2 * 10 ** 5: print('SMALL') print(len(result)) result.reverse() print(''.join(result)) else: print('BIG') print(count) else: print('IMPOSSIBLE') # for tc in range(TC): # N, X = map(int, input().split()) # A = list(map(int, input().split())) # result = 0 # print('Case #{}: {}'.format(tc + 1, result)) ```
output
1
54,933
9
109,867
Provide tags and a correct Python 3 solution for this coding contest problem. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A.
instruction
0
54,934
9
109,868
Tags: binary search, constructive algorithms, greedy, implementation Correct Solution: ``` n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if n == 1: if A[0] == B[0]: print("SMALL") print(0) print() else: print("IMPOSSIBLE") elif n == 2: out = [] prefCount = 0 works = True while (B[0] + B[1] > A[0] + A[1]) and B[0] and B[1]: if B[1] < B[0]: B[0], B[1] = B[1], B[0] out.append(('R',1)) lim1 = B[1] // B[0] lim2 = (B[0] + B[1] - A[0] - A[1]) // B[0] do = min(lim1, lim2) if do == 0: do = 1 B[1] -= do * B[0] out.append(('P',do)) prefCount += do if A == B: pass elif A == B[::-1]: out.append(('R',1)) else: works = False if works: if prefCount > 2 * 10 ** 5: print('BIG') print(prefCount) else: print('SMALL') out = list(map(lambda x: x[0] * x[1], out)) outS = ''.join(out[::-1]) print(len(outS)) print(outS) else: print('IMPOSSIBLE') else: out = [] prefCount = 0 flipped = False works = True while (B[0] + B[-1] > A[0] + A[-1]) and works: if B[0] < B[-1]: for i in range(n - 1, 0, -1): if B[i] <= B[i - 1]: works = False break else: B[i] -= B[i - 1] if flipped: out.append('R') flipped = False out.append('P') prefCount += 1 else: for i in range(n - 1): if B[i] <= B[i + 1]: works = False break else: B[i] -= B[i + 1] if not flipped: out.append('R') flipped = True out.append('P') prefCount += 1 if flipped: B = B[::-1] if A == B: pass elif A == B[::-1]: out.append('R') else: works = False if works: if prefCount > 2 * 10 ** 5: print('BIG') print(prefCount) else: print('SMALL') print(len(out)) print(''.join(out[::-1])) else: print('IMPOSSIBLE') ```
output
1
54,934
9
109,869
Provide tags and a correct Python 3 solution for this coding contest problem. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A.
instruction
0
54,935
9
109,870
Tags: binary search, constructive algorithms, greedy, implementation Correct Solution: ``` from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): n = int(input()) aa = [int(a) for a in input().split()] bb = [int(a) for a in input().split()] if n == 1: if aa == bb: print("SMALL") print(0) else: print("IMPOSSIBLE") elif n == 2: pcount = 0 res = [] irev = False if aa[0] > aa[1]: aa.reverse() irev = True if bb[0] > bb[1]: bb.reverse() res.append('R') while bb[0] > aa[0]: pcount += (bb[1]//bb[0]) if pcount <= 200000: res += ['P']*(bb[1]//bb[0])+['R'] bb[0], bb[1] = bb[1]%bb[0], bb[0] if bb[0] == aa[0] and (bb[1] - aa[1]) % bb[0] == 0: pcount += ((bb[1] - aa[1])//bb[0]) if pcount <= 200000: res += ['P']*((bb[1] - aa[1])//bb[0]) if irev: res.append('R') if pcount > 200000: print("BIG") print(pcount) else: print("SMALL") print(len(res)) print(''.join(res[::-1])) else: print("IMPOSSIBLE") else: res = [] pcount = 0 raa = list(reversed(aa)) while bb != aa and bb != raa: if bb[1] < bb[0]: bb.reverse() res+=['R'] bb = [bb[0]] + list(map(lambda x, y: y-x, bb[:-1], bb[1:])) if min(bb) <= 0: print("IMPOSSIBLE") return res += ['P'] pcount+=1 if pcount > 200000: print("BIG") print(pcount) else: print("SMALL") if bb != aa: res.append('R') print(len(res)) print(''.join(res[::-1])) if __name__ == "__main__": main() ```
output
1
54,935
9
109,871
Provide tags and a correct Python 3 solution for this coding contest problem. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A.
instruction
0
54,936
9
109,872
Tags: binary search, constructive algorithms, greedy, implementation Correct Solution: ``` import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): n=II() aa=LI() raa=aa[::-1] bb=LI() if n==1: if aa==bb: print("SMALL") print(0) else: print("IMPOSSIBLE") exit() if n==2: mna=min(aa) cntp=0 x,y=bb if x>y:x,y=y,x while mna<x: c=y//x cntp+=c y-=c*x if x>y:x,y=y,x d=y-max(aa) if mna!=x or d%x: print("IMPOSSIBLE") exit() cntp+=d//x if cntp>200000: print("BIG") print(cntp) exit() ans="" cntp=0 while 1: if aa==bb: if cntp > 200000: print("BIG") print(cntp) else: print("SMALL") print(len(ans)) if ans:print(ans[::-1]) exit() if raa==bb: if cntp > 200000: print("BIG") print(cntp) else: ans+="R" print("SMALL") print(len(ans)) if ans:print(ans[::-1]) exit() if bb[0]<=bb[-1]: if cntp<=200000:ans+="P" cntp+=1 for i in range(n-2,-1,-1): bb[i+1]-=bb[i] if bb[i+1]<=0: print("IMPOSSIBLE") exit() else: if cntp<=200000:ans+="R" bb.reverse() main() ```
output
1
54,936
9
109,873
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A. Submitted Solution: ``` n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) if n == 1: if A[0] == B[0]: print("SMALL") print(0) print() else: print("IMPOSSIBLE") elif n == 2: out = [] prefCount = 0 works = True while (B[0] + B[1] > A[0] + A[1]): if B[1] < B[0]: B[0], B[1] = B[1], B[0] out.append('R') lim1 = B[1] // B[0] lim2 = (B[0] + B[1] - A[0] - A[1]) // B[0] do = min(lim1, lim2) if do == 0: do = 1 B[1] -= do * B[0] out.append('P'*do) prefCount += do if A == B: pass elif A == B[::-1]: out.append('R') else: works = False if works: if prefCount > 2 * 10 ** 5: print('BIG') print(prefCount) else: print('SMALL') out = ''.join(out[::-1]) print(len(out)) print(out) else: print('IMPOSSIBLE') else: out = [] prefCount = 0 flipped = False works = True while (B[0] + B[-1] > A[0] + A[-1]) and works: if B[0] < B[-1]: for i in range(n - 1, 0, -1): if B[i] <= B[i - 1]: works = False break else: B[i] -= B[i - 1] if flipped: out.append('R') flipped = False out.append('P') prefCount += 1 else: for i in range(n - 1): if B[i] <= B[i + 1]: works = False break else: B[i] -= B[i + 1] if not flipped: out.append('R') flipped = True out.append('P') prefCount += 1 if A == B: pass elif A == B[::-1]: out.append('R') else: works = False if works: if prefCount > 2 * 10 ** 5: print('BIG') print(prefCount) else: print('SMALL') print(len(out)) print(''.join(out[::-1])) else: print('IMPOSSIBLE') ```
instruction
0
54,937
9
109,874
No
output
1
54,937
9
109,875
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A. Submitted Solution: ``` # from bisect import bisect_left def is_asc(arr): a = arr[0] for b in arr[1:]: if a < b: a = b else: return False return True def is_des(arr): a = arr[0] for b in arr[1:]: if a > b: a = b else: return False return True N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) # print(N, A, B) result = [] count = 0 found = False if N == 1: if A[0] == B[0]: found = True elif N == 2: while True: if B[1] == 0: break if B[0] > B[1]: if A[1] == B[1]: if B[0] == A[0]: found = True break elif (B[0] - A[0]) % A[1] == 0: c = (B[0] - A[0]) // A[1] count += c if count <= 2 * 10 ** 5: result.append('R') result = result + ['P'] * c result.append('R') found = True break B.reverse() result.append('R') if B[0] < B[1]: if A[0] == B[0]: if B[1] == A[1]: found = True break elif (B[1] - A[1]) % A[0] == 0: c = (B[1] - A[1]) // A[0] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c found = True break else: c = B[1] // B[0] count += c if count <= 2 * 10 ** 5: result = result + ['P'] * c B[1] = B[1] % B[0] else: break print(B,result) else: while True: for a, b in zip(A, B): if a != b: eq = False break else: found = True break B.reverse() for a, b in zip(A, B): if a != b: eq = False break else: found = True result.append('R') break B.reverse() if is_des(B): B.reverse() result.append('R') count += 1 result.append('P') for i in range(len(B) - 1, 0, -1): B[i] = B[i] - B[i - 1] elif is_asc(B): result.append('P') count += 1 for i in range(len(B) - 1, 0, -1): B[i] = B[i] - B[i - 1] else: break # print(B, result) if found: if count <= 2 * 10 ** 5: print('SMALL') print(len(result)) result.reverse() print(''.join(result)) else: print('BIG') print(count) else: print('IMPOSSIBLE') # for tc in range(TC): # N, X = map(int, input().split()) # A = list(map(int, input().split())) # result = 0 # print('Case #{}: {}'.format(tc + 1, result)) ```
instruction
0
54,938
9
109,876
No
output
1
54,938
9
109,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A. Submitted Solution: ``` #!/usr/bin/env python #pyrival orz import os import sys from io import BytesIO, IOBase def solve(a,b): ans=[] fl=True op,op2=0,0 for ct in range(500000): # if ct*len(a) > 1000000: # break # print(b) if len(ans)>200000: fl=False ans=[] if a==b: break if a[::-1]==b: op2+=1 op+=1 b=b[::-1] if fl: ans.append('R') break if a[0]>b[0] and a[0]>b[-1]: break if b[0]>b[-1]: b=b[::-1] op+=1 if fl: ans.append('R') continue for i in range(1,len(b)): if b[i-1]>b[i]: # return -10,-10,[] print("IMPOSSIBLE") exit(0) op+=1 op2+=1 if fl: ans.append('P') for i in reversed(range(1,len(b))): b[i]-=b[i-1] # print(a,b) if a!=b: print("IMPOSSIBLE") exit(0) if op2>200000: # return -10,op2,[] print("BIG") print(op2) exit(0) print("SMALL") print(op) ans=ans[::-1] print("".join(ans)) # return op,op2,ans def main(): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] bb = [x for x in b] if a==b: print("SMALL") print("0") print("") exit(0) solve(a,b) # solve for n<=10 # 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) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
instruction
0
54,939
9
109,878
No
output
1
54,939
9
109,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size n. You can do operations of two types with array A: * Reverse array A. That is the array [A_1,\ A_2,\ …,\ A_n] transformes into [A_n,\ A_{n-1},\ …,\ A_1]. * Replace A with an array of its prefix sums. That is, the array [A_1,\ A_2,\ …,\ A_n] goes to [A_1,\ (A_1+A_2),\ …,\ (A_1+A_2+…+A_n)]. You need to understand if you can get an array B from the array A. If it is possible, you will have to restore the order of these operations by minimizing the number of operations of the second type. Fortunately, the coronavirus is good today, so he has allowed you not to restore actions if the minimum number of second type operations is more than 2⋅ 10^5. But coronavirus resents you, so if you restore the answer, the total number of operations should not exceed 5⋅ 10^5. Solve this problem and get the cookie, or the coronavirus will extend the quarantine for five years and make the whole economy collapse! Input The first line contains a single integer n (1≤ n ≤ 2⋅ 10^5). The second line contains n integers A_1, A_2, …, A_n (1 ≤ A_i ≤ 10 ^ {12}). The third line contains n integers B_1, B_2, …, B_n (1 ≤ B_i ≤ 10 ^ {12}). Output If you cannot get B from the A array, print "IMPOSSIBLE" (without quotes) on a single line. If the minimum number of operations of the second type exceeds 2⋅ 10^5, print "BIG" (without quotes). In the second line print the number of operations of the second type, that needs to be applied to get array B from A. Otherwise, in the first line print "SMALL" (without quotes). In the second line print the total number of operations of the first and second types m ≤ 5⋅ 10^5 (it is guaranteed that in this case there is such a sequence of actions). In the third line print a line of length m, consisting of characters 'R"and 'P' (without quotes). The i-th character should be 'R', if the i-th action is of the first type, and should be 'P', otherwise. If there are several such sequences, you can print any of them. You can print each character in the uppercase or in the lowercase. Examples Input 2 5 7 5 7 Output SMALL 0 Input 2 1 1 300000 1 Output BIG 299999 Input 2 10 1 13 14 Output SMALL 6 RPPPRP Input 3 1 2 1 2 1 2 Output IMPOSSIBLE Note In the first example, the arrays A and B already equal, so the number of required operations =0. In the second example, we need to replace A with the prefix sums 299999 times and then reverse the array. Since 299999>2⋅ 10^5, there is no need to restore the answer. In the fourth example, you cannot get B from the A. Submitted Solution: ``` from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): n = int(input()) aa = [int(a) for a in input().split()] bb = [int(a) for a in input().split()] if n == 1: if aa == bb: print("SMALL") print(0) else: print("IMPOSSIBLE") elif n == 2: pcount = 0 res = [] irev = False if aa[0] > aa[1]: aa.reverse() bb.reverse() if bb[0] > bb[1]: bb.reverse() irev = True while bb[0] > aa[0]: res += ['P']*(bb[1]//bb[0])+['R'] pcount += (bb[1]//bb[0]) bb[0], bb[1] = bb[1]%bb[0], bb[0] if bb[0] == aa[0] and (bb[1] - aa[1]) % bb[0] == 0: res += ['P']*((bb[1] - aa[1])//bb[0]) if irev: res.insert(0, 'R') pcount += ((bb[1] - aa[1])//bb[0]) if pcount > 200000: print("BIG") print(pcount) else: print("SMALL") print(len(res)) print(''.join(res[::-1])) else: print("IMPOSSIBLE") else: res = [] pcount = 0 while bb != aa: if bb[1] < bb[0]: bb.reverse() res+=['R'] bb = [bb[0]] + list(map(lambda x, y: y-x, bb[:-1], bb[1:])) if min(bb) <= 0: print("IMPOSSIBLE") return res += ['P'] pcount+=1 if pcount > 200000: print("BIG") print(pcount) else: print("SMALL") print(pcount) print(''.join(res[::-1])) if __name__ == "__main__": main() ```
instruction
0
54,940
9
109,880
No
output
1
54,940
9
109,881
Provide tags and a correct Python 3 solution for this coding contest problem. Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe, the m friends found n different kinds of milk on the menu, that's why they ordered n bottles — one bottle of each kind. We know that the volume of milk in each bottle equals w. When the bottles were brought in, they decided to pour all the milk evenly among the m cups, so that each got a cup. As a punishment for not passing the test Igor was appointed the person to pour the milk. He protested that he was afraid to mix something up and suggested to distribute the drink so that the milk from each bottle was in no more than two different cups. His friends agreed but they suddenly faced the following problem — and what is actually the way to do it? Help them and write the program that will help to distribute the milk among the cups and drink it as quickly as possible! Note that due to Igor K.'s perfectly accurate eye and unswerving hands, he can pour any fractional amount of milk from any bottle to any cup. Input The only input data file contains three integers n, w and m (1 ≤ n ≤ 50, 100 ≤ w ≤ 1000, 2 ≤ m ≤ 50), where n stands for the number of ordered bottles, w stands for the volume of each of them and m stands for the number of friends in the company. Output Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO". If there is a solution, then print m more lines, where the i-th of them describes the content of the i-th student's cup. The line should consist of one or more pairs that would look like "b v". Each such pair means that v (v > 0) units of milk were poured into the i-th cup from bottle b (1 ≤ b ≤ n). All numbers b on each line should be different. If there are several variants to solve the problem, print any of them. Print the real numbers with no less than 6 digits after the decimal point. Examples Input 2 500 3 Output YES 1 333.333333 2 333.333333 2 166.666667 1 166.666667 Input 4 100 5 Output YES 3 20.000000 4 60.000000 1 80.000000 4 40.000000 2 40.000000 3 80.000000 2 60.000000 1 20.000000 Input 4 100 7 Output NO Input 5 500 2 Output YES 4 250.000000 5 500.000000 2 500.000000 3 500.000000 1 500.000000 4 250.000000
instruction
0
55,368
9
110,736
Tags: greedy Correct Solution: ``` #!/usr/bin/python3 n, w, m = map(int, input().split()) if n > m: print("YES") i = 0 cur = w for j in range(m): milk = 0 while milk < (w * n) / m - 1e-8: amount = min(cur, (w * n) / m - milk) print(i + 1, amount, end=' ') milk += amount cur -= amount if abs(cur) < 1e-8: i += 1 cur = w print() else: ans = [[] for i in range(m)] sums = [0 for i in range(m)] left = [w for i in range(n)] for i in range(m): while sums[i] < (w * n) / m - 1e-8: mx = 0 for j in range(n): if left[j] > left[mx]: mx = j amount = min(left[mx], (w * n) / m - sums[i]) if left[mx] < w and amount < left[mx] - 1e-8: print("NO") exit(0) sums[i] += amount left[mx] -= amount ans[i].append((mx, amount)) print("YES") for i in range(m): for a, b in ans[i]: print(a + 1, b, end=' ') print() ```
output
1
55,368
9
110,737
Provide tags and a correct Python 3 solution for this coding contest problem. Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe, the m friends found n different kinds of milk on the menu, that's why they ordered n bottles — one bottle of each kind. We know that the volume of milk in each bottle equals w. When the bottles were brought in, they decided to pour all the milk evenly among the m cups, so that each got a cup. As a punishment for not passing the test Igor was appointed the person to pour the milk. He protested that he was afraid to mix something up and suggested to distribute the drink so that the milk from each bottle was in no more than two different cups. His friends agreed but they suddenly faced the following problem — and what is actually the way to do it? Help them and write the program that will help to distribute the milk among the cups and drink it as quickly as possible! Note that due to Igor K.'s perfectly accurate eye and unswerving hands, he can pour any fractional amount of milk from any bottle to any cup. Input The only input data file contains three integers n, w and m (1 ≤ n ≤ 50, 100 ≤ w ≤ 1000, 2 ≤ m ≤ 50), where n stands for the number of ordered bottles, w stands for the volume of each of them and m stands for the number of friends in the company. Output Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO". If there is a solution, then print m more lines, where the i-th of them describes the content of the i-th student's cup. The line should consist of one or more pairs that would look like "b v". Each such pair means that v (v > 0) units of milk were poured into the i-th cup from bottle b (1 ≤ b ≤ n). All numbers b on each line should be different. If there are several variants to solve the problem, print any of them. Print the real numbers with no less than 6 digits after the decimal point. Examples Input 2 500 3 Output YES 1 333.333333 2 333.333333 2 166.666667 1 166.666667 Input 4 100 5 Output YES 3 20.000000 4 60.000000 1 80.000000 4 40.000000 2 40.000000 3 80.000000 2 60.000000 1 20.000000 Input 4 100 7 Output NO Input 5 500 2 Output YES 4 250.000000 5 500.000000 2 500.000000 3 500.000000 1 500.000000 4 250.000000
instruction
0
55,369
9
110,738
Tags: greedy Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, w, m = map(int, input().split()) w = float(w) eps = 1e-9 req = n * w / m cup = [req] * m ans = [[] for _ in range(m)] j = 0 for i in range(n): milk = w cnt = 0 while j < m and milk > eps: x = min(milk, cup[j]) milk -= x cup[j] -= x ans[j].append(f'{i+1} {x:.8f}') cnt += 1 if cup[j] < eps: j += 1 if cnt > 2: print('NO') exit() print('YES') print('\n'.join(' '.join(line) for line in ans)) ```
output
1
55,369
9
110,739
Provide tags and a correct Python 3 solution for this coding contest problem. Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe, the m friends found n different kinds of milk on the menu, that's why they ordered n bottles — one bottle of each kind. We know that the volume of milk in each bottle equals w. When the bottles were brought in, they decided to pour all the milk evenly among the m cups, so that each got a cup. As a punishment for not passing the test Igor was appointed the person to pour the milk. He protested that he was afraid to mix something up and suggested to distribute the drink so that the milk from each bottle was in no more than two different cups. His friends agreed but they suddenly faced the following problem — and what is actually the way to do it? Help them and write the program that will help to distribute the milk among the cups and drink it as quickly as possible! Note that due to Igor K.'s perfectly accurate eye and unswerving hands, he can pour any fractional amount of milk from any bottle to any cup. Input The only input data file contains three integers n, w and m (1 ≤ n ≤ 50, 100 ≤ w ≤ 1000, 2 ≤ m ≤ 50), where n stands for the number of ordered bottles, w stands for the volume of each of them and m stands for the number of friends in the company. Output Print on the first line "YES" if it is possible to pour the milk so that the milk from each bottle was in no more than two different cups. If there's no solution, print "NO". If there is a solution, then print m more lines, where the i-th of them describes the content of the i-th student's cup. The line should consist of one or more pairs that would look like "b v". Each such pair means that v (v > 0) units of milk were poured into the i-th cup from bottle b (1 ≤ b ≤ n). All numbers b on each line should be different. If there are several variants to solve the problem, print any of them. Print the real numbers with no less than 6 digits after the decimal point. Examples Input 2 500 3 Output YES 1 333.333333 2 333.333333 2 166.666667 1 166.666667 Input 4 100 5 Output YES 3 20.000000 4 60.000000 1 80.000000 4 40.000000 2 40.000000 3 80.000000 2 60.000000 1 20.000000 Input 4 100 7 Output NO Input 5 500 2 Output YES 4 250.000000 5 500.000000 2 500.000000 3 500.000000 1 500.000000 4 250.000000
instruction
0
55,370
9
110,740
Tags: greedy Correct Solution: ``` #!/usr/bin/python3 from fractions import Fraction N,W,M = [int(x) for x in input().strip().split()] P = Fraction(N*W,M) volume = [W]*N counts = [0]*N ans = [] idx = 0 for i in range(M): rem = P sel = [] while rem > 0: counts[idx] += 1 if volume[idx] > rem: sel.append((idx,rem)) volume[idx] -= rem rem = 0 else: sel.append((idx,volume[idx])) rem -= volume[idx] volume[idx] = 0 idx += 1 ans.append(sel) if max(counts) > 2: print("NO") else: print("YES") for sel in ans: for f in sel: print(f[0]+1,'{0:.9f}'.format(f[1].numerator/f[1].denominator),end=" ") print() ```
output
1
55,370
9
110,741
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,470
9
110,940
"Correct Solution: ``` N = int(input()) print(len(set(input() for n in range(N)))) ```
output
1
55,470
9
110,941
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,471
9
110,942
"Correct Solution: ``` n=int(input()); d=[int(input()) for i in range(n)] print(len(set(d))) ```
output
1
55,471
9
110,943
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,472
9
110,944
"Correct Solution: ``` n,*d=map(int,open(0).read().split()) print(len(set(d))) ```
output
1
55,472
9
110,945
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,473
9
110,946
"Correct Solution: ``` _, *d = open(0).read().split() print(len(set(d))) ```
output
1
55,473
9
110,947
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,474
9
110,948
"Correct Solution: ``` n = int(input()) print(len({int(input()) for _ in range(n)})) ```
output
1
55,474
9
110,949
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,475
9
110,950
"Correct Solution: ``` n = int(input()) m = set(input() for i in range(n)) print(len(m)) ```
output
1
55,475
9
110,951
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,476
9
110,952
"Correct Solution: ``` n = int(input()) print(len(set(input() for _ in range(n)))) ```
output
1
55,476
9
110,953
Provide a correct Python 3 solution for this coding contest problem. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4
instruction
0
55,477
9
110,954
"Correct Solution: ``` print(len({input() for i in range(int(input()))})) ```
output
1
55,477
9
110,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` N=int(input()) print(len(set(input() for i in range(N)))) ```
instruction
0
55,478
9
110,956
Yes
output
1
55,478
9
110,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` n = int(input()) d = len({int(input()) for i in range(n)}) print(d) ```
instruction
0
55,479
9
110,958
Yes
output
1
55,479
9
110,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` N = int(input()) D = set([input() for i in range(N)]) print(len(D)) ```
instruction
0
55,480
9
110,960
Yes
output
1
55,480
9
110,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` list=[int(input()) for i in range(int(input()))] print(len(set(list))) ```
instruction
0
55,481
9
110,962
Yes
output
1
55,481
9
110,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` n = int(input()) d = [0] * 100 for i in range(0, n): inp = int(input()) d[inp] += 1 count = 0 for i in d: if i > 0: count += 1 print(count) ```
instruction
0
55,482
9
110,964
No
output
1
55,482
9
110,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` N = int(input()) d = list(map(int, input().split())) x = sorted(d, reverse=True) ans = 1 for i in range(N-1): if x[i] - x[i+1] >0: ans += 1 else: continue print(ans) ```
instruction
0
55,483
9
110,966
No
output
1
55,483
9
110,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` N = input() a = [] for i in range(int(N)): a.append(input()) cnt = [] for i in range(int(N)): cnt.append(a.count(a[0])-1) a.remove(a[0]) su = sum(cnt) print(int(N)-su) ```
instruction
0
55,484
9
110,968
No
output
1
55,484
9
110,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi. Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have? Constraints * 1 ≤ N ≤ 100 * 1 ≤ d_i ≤ 100 * All input values are integers. Input Input is given from Standard Input in the following format: N d_1 : d_N Output Print the maximum number of layers in a kagami mochi that can be made. Examples Input 4 10 8 8 6 Output 3 Input 3 15 15 15 Output 1 Input 7 50 30 50 100 50 80 30 Output 4 Submitted Solution: ``` n = int(input()) l = [] for i in range(n): s0 = int(input()) l.append(s0) l.sort() ans = 1 for i in range(1,n-1): if l[i] != l[i-1]: ans += 1 print(ans) ```
instruction
0
55,485
9
110,970
No
output
1
55,485
9
110,971
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,503
9
111,006
"Correct Solution: ``` k, t = map(int, input().split()) a = list(map(int, input().split())) ma = max(a) print(max(ma - 1 - (k-ma), 0)) ```
output
1
55,503
9
111,007
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,504
9
111,008
"Correct Solution: ``` k,t=map(int,input().split()) a=list(map(int,input().split())) ans=max(2*max(a)-sum(a)-1,0) print(ans) ```
output
1
55,504
9
111,009
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,505
9
111,010
"Correct Solution: ``` k, t = map(int, input().split()) a = list(map(int, input().split())) print(max(0, 2 * max(a) - k - 1)) ```
output
1
55,505
9
111,011
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,506
9
111,012
"Correct Solution: ``` k,t=map(int,input().split()) d=list(map(int,input().split())) d.sort() print(max(0,2*d[-1]-sum(d)-1) if t!=1else k-1) ```
output
1
55,506
9
111,013
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,507
9
111,014
"Correct Solution: ``` K,T = map(int,input().split()) a = list(map(int,input().split())) x = max(a) print(max(x-1-(K-x),0)) ```
output
1
55,507
9
111,015
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,508
9
111,016
"Correct Solution: ``` k,t,*a=map(int,open(0).read().split()) print(max(2*max(a)-k-1,0)) ```
output
1
55,508
9
111,017
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,509
9
111,018
"Correct Solution: ``` k,t = map(int, input().split()) a = list(map(int, input().split())) b = max(a) s = sum(a) s -=b ans = max(b-s-1,0) print(ans) ```
output
1
55,509
9
111,019
Provide a correct Python 3 solution for this coding contest problem. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99
instruction
0
55,510
9
111,020
"Correct Solution: ``` K,T = list(map(int, input().split())) a = list(map(int, input().split())) m = max(a) o = sum(a)-m print(max(m-o-1, 0)) ```
output
1
55,510
9
111,021
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` K, T = map(int, input().split()) A = list(map(int,input().split())) Max = max(A) print(max(Max-1-(K-Max),0)) ```
instruction
0
55,511
9
111,022
Yes
output
1
55,511
9
111,023
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` k, t, *a = list(map(int, open(0).read().split())) 最大 = max(a) print(max(最大-(k-最大)-1, 0)) ```
instruction
0
55,512
9
111,024
Yes
output
1
55,512
9
111,025
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` k,t = map(int,input().split()) lis = list(map(int,input().split())) print(max((max(lis)-1)-(k-max(lis)),0)) ```
instruction
0
55,513
9
111,026
Yes
output
1
55,513
9
111,027
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` K, T = map(int, input().split()) a = list(map(int, input().split())) M = max(a) ans = max(M - 1 - (K - M), 0) print(ans) ```
instruction
0
55,514
9
111,028
Yes
output
1
55,514
9
111,029
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` import math K, T = map(int, input().split()) a = list(map(int, input().split())) c = max(a) if K == 1: print(0) elif T == 1: print(K-1) elif c > math.ceil(K/2): print(c-math.ceil(K/2)) else: print(0) ```
instruction
0
55,515
9
111,030
No
output
1
55,515
9
111,031
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` def read_input(): l_1 = input() day = int(l_1.split(" ")[0]) num_cake = [int(i) for i in input().split(" ")] return day, num_cake def get_max_index(target_list): return [i for i, j in enumerate(target_list) if j == max(target_list)] def get_second_max_index(target_list): return [i for i, j in enumerate(target_list) if j == list(sorted(set(target_list), reverse=True))[1]] def mog(day, num_cake): """ >>> mog(7, [3,2,2]) 0 >>> mog(6, [1,4,1]) 1 >>> mog(100, [100]) 99 """ printed = False previous_index = -1 for i in range(0, day): # print(num_cake) # print(previous_index) ate_flag = False mog_maybe_index = get_max_index(num_cake) # print("mog_maybe_index: {0}".format(mog_maybe_index)) for n in mog_maybe_index: if n == previous_index: continue else: num_cake[n] = num_cake[n] - 1 ate_flag = True previous_index = n break if ate_flag is False: try: mog_ext = get_second_max_index(num_cake) # print("mog_ext", mog_ext) except IndexError: print(max(num_cake)) printed = True break num_cake[mog_ext[0]] = num_cake[mog_ext[0]] - 1 previous_index = mog_ext[0] if printed is False: print(0) if __name__ == "__main__": day, num_cake = read_input() mog(day, num_cake) ```
instruction
0
55,516
9
111,032
No
output
1
55,516
9
111,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` k, t = map(int, input().split()) a = list(map(int, input().split())) if max(a)%2 == 1: print(max(a)-t) else: print(max(a)-1-t) ```
instruction
0
55,517
9
111,034
No
output
1
55,517
9
111,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten. Constraints * 1 ≤ K ≤ 10000 * 1 ≤ T ≤ 100 * 1 ≤ a_i ≤ 100 * a_1 + a_2 + ... + a_T = K Input The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T Output Print the minimum number of days on which the same type of cake as the previous day will be eaten. Examples Input 7 3 3 2 2 Output 0 Input 6 3 1 4 1 Output 1 Input 100 1 100 Output 99 Submitted Solution: ``` k,t = map(int,input().split()) A = list(map(int,input().split())) print(max(2*max(A) - sum(A) -1)) ```
instruction
0
55,518
9
111,036
No
output
1
55,518
9
111,037
Provide a correct Python 3 solution for this coding contest problem. Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can take, whether they are broken or not. Nikunishi understands binary numbers. Nikunishi-kun can count numbers by associating each finger with a binary digit. Nikunishi doesn't understand the logarithm. Find the minimum number of fingers needed to count the buns instead of Nishikun. input n Constraint * An integer * 0 ≤ n ≤ 1018 output Print the answer on one line, and print a newline at the end. sample Sample input 1 0 Sample output 1 0 Sample input 2 Four Sample output 2 3 Sample input 3 31 Sample output 3 Five Sample input 4 36028797018963968 Sample output 4 56 Example Input 0 Output 0
instruction
0
55,560
9
111,120
"Correct Solution: ``` # from sys import exit # A,B,C = [int(n) for n in input().split()] N = int(input()) # a = [int(input()) for _ in range(N)] # S = str(input()) # L = len(S) # T = str(input()) # exit() # print(bin(N)) print(len(bin(N))-2 if N > 0 else 0) ```
output
1
55,560
9
111,121
Provide a correct Python 3 solution for this coding contest problem. Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can take, whether they are broken or not. Nikunishi understands binary numbers. Nikunishi-kun can count numbers by associating each finger with a binary digit. Nikunishi doesn't understand the logarithm. Find the minimum number of fingers needed to count the buns instead of Nishikun. input n Constraint * An integer * 0 ≤ n ≤ 1018 output Print the answer on one line, and print a newline at the end. sample Sample input 1 0 Sample output 1 0 Sample input 2 Four Sample output 2 3 Sample input 3 31 Sample output 3 Five Sample input 4 36028797018963968 Sample output 4 56 Example Input 0 Output 0
instruction
0
55,561
9
111,122
"Correct Solution: ``` n = int(input()) print(len(bin(n)) - 2 if n else 0) ```
output
1
55,561
9
111,123
Provide a correct Python 3 solution for this coding contest problem. Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can take, whether they are broken or not. Nikunishi understands binary numbers. Nikunishi-kun can count numbers by associating each finger with a binary digit. Nikunishi doesn't understand the logarithm. Find the minimum number of fingers needed to count the buns instead of Nishikun. input n Constraint * An integer * 0 ≤ n ≤ 1018 output Print the answer on one line, and print a newline at the end. sample Sample input 1 0 Sample output 1 0 Sample input 2 Four Sample output 2 3 Sample input 3 31 Sample output 3 Five Sample input 4 36028797018963968 Sample output 4 56 Example Input 0 Output 0
instruction
0
55,562
9
111,124
"Correct Solution: ``` N = int(input()) ans = 0 while(N): N //= 2 ans += 1 print(ans) ```
output
1
55,562
9
111,125
Provide a correct Python 3 solution for this coding contest problem. Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can take, whether they are broken or not. Nikunishi understands binary numbers. Nikunishi-kun can count numbers by associating each finger with a binary digit. Nikunishi doesn't understand the logarithm. Find the minimum number of fingers needed to count the buns instead of Nishikun. input n Constraint * An integer * 0 ≤ n ≤ 1018 output Print the answer on one line, and print a newline at the end. sample Sample input 1 0 Sample output 1 0 Sample input 2 Four Sample output 2 3 Sample input 3 31 Sample output 3 Five Sample input 4 36028797018963968 Sample output 4 56 Example Input 0 Output 0
instruction
0
55,563
9
111,126
"Correct Solution: ``` n = int(input()) print(0 if n == 0 else len(str(bin(n))[2:])) ```
output
1
55,563
9
111,127