message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,348
14
116,696
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` n=int(input()) ls= sorted([int(input()) for _ in range(n)]) cnt=0 mid=n//2-1 right=n-1 # mated=0 # for _ in range(n//2): # if ls[right]>=2*ls[mid] and mid>=0: # cnt+=1 # mid-=1 # right-=1 # mated+=2 # else: # mid-=1 # print(cnt+n-mated) while mid>=0 and right>mid: if ls[mid]*2<=ls[right]: cnt+=1 right-=1 mid-=1 print(n-cnt) ```
output
1
58,348
14
116,697
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,349
14
116,698
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools,itertools,operator,bisect,fractions,statistics from collections import deque,defaultdict,OrderedDict,Counter from fractions import Fraction from decimal import Decimal from sys import stdout from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest # sys.setrecursionlimit(111111) INF=999999999999999999999999 alphabets="abcdefghijklmnopqrstuvwxyz" class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)] self._list_lens = [len(_list) for _list in _lists] self._mins = [_list[0] for _list in _lists] self._fen_tree = [] self._rebuild = True def _fen_build(self): """Build a fenwick tree instance.""" self._fen_tree[:] = self._list_lens _fen_tree = self._fen_tree for i in range(len(_fen_tree)): if i | i + 1 < len(_fen_tree): _fen_tree[i | i + 1] += _fen_tree[i] self._rebuild = False def _fen_update(self, index, value): """Update `fen_tree[index] += value`.""" if not self._rebuild: _fen_tree = self._fen_tree while index < len(_fen_tree): _fen_tree[index] += value index |= index + 1 def _fen_query(self, end): """Return `sum(_fen_tree[:end])`.""" if self._rebuild: self._fen_build() _fen_tree = self._fen_tree x = 0 while end: x += _fen_tree[end - 1] end &= end - 1 return x def _fen_findkth(self, k): """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`).""" _list_lens = self._list_lens if k < _list_lens[0]: return 0, k if k >= self._len - _list_lens[-1]: return len(_list_lens) - 1, k + _list_lens[-1] - self._len if self._rebuild: self._fen_build() _fen_tree = self._fen_tree idx = -1 for d in reversed(range(len(_fen_tree).bit_length())): right_idx = idx + (1 << d) if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]: idx = right_idx k -= _fen_tree[idx] return idx + 1, k def _delete(self, pos, idx): """Delete value at the given `(pos, idx)`.""" _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len -= 1 self._fen_update(pos, -1) del _lists[pos][idx] _list_lens[pos] -= 1 if _list_lens[pos]: _mins[pos] = _lists[pos][0] else: del _lists[pos] del _list_lens[pos] del _mins[pos] self._rebuild = True def _loc_left(self, value): """Return an index pair that corresponds to the first position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins lo, pos = -1, len(_lists) - 1 while lo + 1 < pos: mi = (lo + pos) >> 1 if value <= _mins[mi]: pos = mi else: lo = mi if pos and value <= _lists[pos - 1][-1]: pos -= 1 _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value <= _list[mi]: idx = mi else: lo = mi return pos, idx def _loc_right(self, value): """Return an index pair that corresponds to the last position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins pos, hi = 0, len(_lists) while pos + 1 < hi: mi = (pos + hi) >> 1 if value < _mins[mi]: hi = mi else: pos = mi _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value < _list[mi]: idx = mi else: lo = mi return pos, idx def add(self, value): """Add `value` to sorted list.""" _load = self._load _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len += 1 if _lists: pos, idx = self._loc_right(value) self._fen_update(pos, 1) _list = _lists[pos] _list.insert(idx, value) _list_lens[pos] += 1 _mins[pos] = _list[0] if _load + _load < len(_list): _lists.insert(pos + 1, _list[_load:]) _list_lens.insert(pos + 1, len(_list) - _load) _mins.insert(pos + 1, _list[_load]) _list_lens[pos] = _load del _list[_load:] self._rebuild = True else: _lists.append([value]) _mins.append(value) _list_lens.append(1) self._rebuild = True def discard(self, value): """Remove `value` from sorted list if it is a member.""" _lists = self._lists if _lists: pos, idx = self._loc_right(value) if idx and _lists[pos][idx - 1] == value: self._delete(pos, idx - 1) def remove(self, value): """Remove `value` from sorted list; `value` must be a member.""" _len = self._len self.discard(value) if _len == self._len: raise ValueError('{0!r} not in list'.format(value)) def pop(self, index=-1): """Remove and return value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) value = self._lists[pos][idx] self._delete(pos, idx) return value def bisect_left(self, value): """Return the first index to insert `value` in the sorted list.""" pos, idx = self._loc_left(value) return self._fen_query(pos) + idx def bisect_right(self, value): """Return the last index to insert `value` in the sorted list.""" pos, idx = self._loc_right(value) return self._fen_query(pos) + idx def count(self, value): """Return number of occurrences of `value` in the sorted list.""" return self.bisect_right(value) - self.bisect_left(value) def __len__(self): """Return the size of the sorted list.""" return self._len def __getitem__(self, index): """Lookup value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) return self._lists[pos][idx] def __delitem__(self, index): """Remove value at `index` from sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) self._delete(pos, idx) def __contains__(self, value): """Return true if `value` is an element of the sorted list.""" _lists = self._lists if _lists: pos, idx = self._loc_left(value) return idx < len(_lists[pos]) and _lists[pos][idx] == value return False def __iter__(self): """Return an iterator over the sorted list.""" return (value for _list in self._lists for value in _list) def __reversed__(self): """Return a reverse iterator over the sorted list.""" return (value for _list in reversed(self._lists) for value in reversed(_list)) def __repr__(self): """Return string representation of sorted list.""" return 'SortedList({0})'.format(list(self)) class SegTree: def __init__(self, n): self.N = 1 << n.bit_length() self.tree = [0] * (self.N<<1) def update(self, i, j, v): i += self.N j += self.N while i <= j: if i%2==1: self.tree[i] += v if j%2==0: self.tree[j] += v i, j = (i+1) >> 1, (j-1) >> 1 def query(self, i): v = 0 i += self.N while i > 0: v += self.tree[i] i >>= 1 return v def SieveOfEratosthenes(limit): """Returns all primes not greater than limit.""" isPrime = [True]*(limit+1) isPrime[0] = isPrime[1] = False primes = [] for i in range(2, limit+1): if not isPrime[i]:continue primes += [i] for j in range(i*i, limit+1, i): isPrime[j] = False return primes def main(): mod=1000000007 # InverseofNumber(mod) # InverseofFactorial(mod) # factorial(mod) starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") ###CODE tc = 1 for _ in range(tc): # LOGIC: # At most kangaroos can be paired is n//2 -1 # So the greedy approach will be # to pair the least sized n//2 -1 kangaroos # with the kangaroos of bigger size # Split kangaroos by sorting and first n//2 -1 are to be paired with rest # Yeah kangaroos in second group could pair with bigger kangaroos # but we dont care as we can pair some smaller kangaroo with that bigger kangaroo anyways n=ri() a=[] for i in range(n): a.append(ri()) a=sorted(a) l=(n//2)-1 r=n-1 p=0 while l>=0 and r>(n//2)-1: if 2*a[l]<=a[r]: r-=1 p+=1 l-=1 wi(n-p) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main() ```
output
1
58,349
14
116,699
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,350
14
116,700
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` import sys n = int(input()) a = list(sorted([int(next(sys.stdin)) for _ in range(n)])) i, j = 0, n // 2 cnt = 0 while j < n: if a[i] == -1: i += 1 if i == j: j += 1 elif a[i] * 2 <= a[j]: cnt += 1 a[j] = -1 i += 1 j += 1 print(n - cnt) ```
output
1
58,350
14
116,701
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,351
14
116,702
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` import os import sys from io import BytesIO, IOBase 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") n=int(input()) s=[0 for i in range(0,n)] for i in range(0,n): s[i]=int(input()) s.sort() # print (s) p=n//2+n%2 visible=n y=0 for i in range(p,p+n//2): if s[y]*2<=s[i]: visible-=1 y+=1 print (visible) ```
output
1
58,351
14
116,703
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,352
14
116,704
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` from sys import stdin import collections import os import sys from io import IOBase, BytesIO from sys import stdin, stdout from math import sqrt py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange def main(): n = int(input()) nn = n arr = [] while nn: nn -= 1 temp = int(input()) arr.append(temp) arr.sort() mid = n//2 - 1 b = n - 1 s = 0 while mid >= 0: if arr[mid]*2 <= arr[b]: b -= 1 s += 1 mid -= 1 print(n-s) BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO, self).read() def readline(self): while self.newlines == 0: s = self._fill() self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: 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) def input(): return sys.stdin.readline().rstrip('\r\n') class ostream: def __lshift__(self, a): sys.stdout.write(str(a)) return self cout = ostream() endl = '\n' if __name__ == "__main__": main() ```
output
1
58,352
14
116,705
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,353
14
116,706
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): pass # 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") n=int(input()) l=[] for i in range(0,n): l.append(int(input())) l.sort() i=n-1 ans=n j=n//2-1 while(j>=0 and i>=n//2): if((l[j]*2)<=l[i]): i-=1 ans-=1 j-=1 print(ans) ```
output
1
58,353
14
116,707
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,354
14
116,708
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` import os import sys from io import BytesIO, IOBase import math from decimal import * getcontext().prec = 25 MOD = pow(10, 9) + 7 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") # n, k = map(int, input().split(" ")) # l = list(map(int, input().split(" "))) n = int(input()) l = [int(input()) for i in range(n)] l.sort() a = l[-1] // 2 x = n//2 + n%2 i = 0 c = 0 while l[i] <= a and x < n: if l[i] <= l[x] // 2: c += 1 i += 1 x += 1 else: x += 1 # print(*l) # print(a) print(n-c) ```
output
1
58,354
14
116,709
Provide tags and a correct Python 3 solution for this coding contest problem. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5
instruction
0
58,355
14
116,710
Tags: binary search, greedy, sortings, two pointers Correct Solution: ``` import os import sys from io import BytesIO, IOBase 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") n = int(input()) arr = [0] * n for i in range(n): arr[i] = int(input()) arr.sort() small = 0 big = n // 2 hidden = 0 while small < n // 2 and big < n: if arr[big] >= arr[small] * 2: small += 1 big += 1 hidden += 1 else: big += 1 print(n - hidden) ```
output
1
58,355
14
116,711
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5 Submitted Solution: ``` n = int(input()) arr = sorted([int(input()) for _ in range(n)]) r = n-1 count = 0 for t in range((n//2) - 1,-1,-1): if arr[t] * 2 <= arr[r]: r -= 1 count += 1 print(n-count) ```
instruction
0
58,359
14
116,718
Yes
output
1
58,359
14
116,719
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5 Submitted Solution: ``` def main(): n=int(input()) array=[] for x in range(0,n): array.append(int(input())) array.sort() max=array[n-1] i=n-2 j=n-1 already=[] while(j>=0): if((array[j]>=2*array[i]) and not(already.__contains__(i))): already.append(i) j-=1 i=j-1 else: i-=1 if i<0: j-=1 i=j-1 print((n-len(already))) if __name__ == '__main__': main() ```
instruction
0
58,362
14
116,724
No
output
1
58,362
14
116,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input The first line contains a single integer β€” n (1 ≀ n ≀ 5Β·105). Each of the next n lines contains an integer si β€” the size of the i-th kangaroo (1 ≀ si ≀ 105). Output Output a single integer β€” the optimal number of visible kangaroos. Examples Input 8 2 5 7 6 9 8 4 2 Output 5 Input 8 9 1 6 2 6 5 8 3 Output 5 Submitted Solution: ``` import bisect import sys from collections import Counter from typing import List input = sys.stdin.readline def solve(n: int, a: List[int]) -> int: c = Counter(a) keys = [] for i in range(100_001): if i in c: keys.append(i) held_count = 0 for e in keys[::-1]: if e not in c: continue i = bisect.bisect_left(keys, e // 2) if keys[i] * 2 > e: i -= 1 while i >= 0 and c[e] > c[keys[i]]: if c[keys[i]] > 0: c[e] -= c[keys[i]] held_count += c[keys[i]] del c[keys[i]] i -= 1 if i < 0: break c[keys[i]] -= c[e] if c[keys[i]] == 0: del c[keys[i]] keys.pop(i) held_count += c[e] del c[e] return sum(c.values()) + held_count # assert solve(100, # [678, 771, 96, 282, 135, 749, 168, 668, 17, 658, 979, 446, 998, 331, 606, 756, 37, 515, 538, 205, 647, 547, # 904, 842, 647, 286, 774, 414, 267, 791, 595, 465, 8, 327, 855, 174, 339, 946, 184, 250, 807, 422, 679, # 980, 64, 530, 312, 351, 676, 911, 803, 991, 669, 50, 293, 841, 545, 598, 737, 894, 231, 754, 588, 83, 873, # 767, 833, 482, 905, 903, 970, 571, 715, 59, 777, 697, 537, 861, 339, 212, 149, 889, 905, 70, 970, 307, # 830, 465, 968, 291, 430, 317, 942, 944, 330, 235, 814, 880, 415, 76]) == 58 # assert solve(12, [3, 99, 24, 46, 75, 63, 57, 55, 10, 62, 34, 52]) == 7 # assert solve(8, [2, 5, 7, 6, 9, 8, 4, 2]) == 5 n = int(input()) a = [] for _ in range(n): a.append(int(input())) r = solve(n, a) print(r) ```
instruction
0
58,363
14
116,726
No
output
1
58,363
14
116,727
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,402
14
116,804
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` # cook your dish here n=int(input()) l1=[int(s) for s in input().split()] m=int(input()) l2=[int(s) for s in input().split()] l1.sort() l2.sort() i=j=c=0 while(i<n and j<m): if(abs(l1[i]-l2[j])<=1): c+=1 i+=1 j+=1 elif l1[i]<l2[j]: i+=1 else: j+=1 print(c) ```
output
1
58,402
14
116,805
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,403
14
116,806
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` from collections import deque from math import ceil def ii():return int(input()) def si():return input() def mi():return map(int,input().split()) def li():return list(mi()) abc="abcdefghijklmnopqrstuvwxyz" n=ii() a=li() m=ii() b=li() a.sort() b.sort() c=0 for i in range(n): x=a[i] for j in range(m): y=abs(x-b[j]) if(y<=1): b.remove(b[j]) c+=1 m-=1 break print(c) ```
output
1
58,403
14
116,807
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,404
14
116,808
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` import math input() lista_hombres = list(input().split()) for i in range(len(lista_hombres)): lista_hombres[i] = int(lista_hombres[i]) input() lista_mujeres = list(input().split()) for i in range(len(lista_mujeres)): lista_mujeres[i] = int(lista_mujeres[i]) lista_hombres.sort() lista_mujeres.sort() parejas = 0 for i in range(len(lista_hombres)): for j in range(len(lista_mujeres)): if abs(lista_hombres[i]-lista_mujeres[j]) <= 1: parejas += 1 lista_hombres[i] = math.inf lista_mujeres[j] = math.inf print(parejas) ```
output
1
58,404
14
116,809
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,405
14
116,810
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` def main(): from sys import stdin from itertools import islice tokens = map(int, stdin.read().split()) N = next(tokens) boys = sorted(islice(tokens, N)) M = next(tokens) girls = sorted(islice(tokens, M)) if len(boys) < len(girls): smallest_array = boys biggest_array = girls else: smallest_array = girls biggest_array = boys ans = 0 i = 0 for x in smallest_array: while i < len(biggest_array) and biggest_array[i] <= x - 2: i += 1 if i == len(biggest_array): break elif abs(biggest_array[i] - x) <= 1: ans += 1 i += 1 print(ans) main() ```
output
1
58,405
14
116,811
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,406
14
116,812
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` def foo(n,m): c=0 n.sort() m.sort() for i in range(len(n)): for j in range(len(m)): if(abs(n[i]-m[j])<=1): c+=1 m[j]=10000 break return(c) n=int(input()) a=input() a=a.split(" ") an=[int(i) for i in a] m= int(input()) b= input() b=b.split(" ") bm=[int(i) for i in b] print(foo(an,bm)) ```
output
1
58,406
14
116,813
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,407
14
116,814
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` n=int(input()) a=sorted(list(map(int,input().split()))) m=int(input()) b=sorted(list(map(int,input().split()))) i,j,cnt=0,0,0 while i<n and j<m: if abs(a[i]-b[j])<=1: cnt+=1 i+=1 j+=1 elif a[i]<b[j]: i+=1 else: j+=1 print(cnt) ```
output
1
58,407
14
116,815
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,408
14
116,816
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` def crear_lista(string): lista = [] cambio = False num = "" for letra in string+" ": if letra == " ": cambio = True lista.append(int(num)) num = "" if not cambio: num += letra cambio = False return lista n = input() hombres = input() k = input() mujeres = input() baile_hombres = crear_lista(hombres) baile_mujeres = crear_lista(mujeres) baile_hombres.sort() baile_mujeres.sort() contador = 0 for m in baile_mujeres: for n in baile_hombres: if int(m)-int(n) <-1: break elif int(m)-int(n) > 1: continue else: contador += 1 baile_hombres.remove(n) break #djsalkds print(contador) ```
output
1
58,408
14
116,817
Provide tags and a correct Python 3 solution for this coding contest problem. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2
instruction
0
58,409
14
116,818
Tags: dfs and similar, dp, graph matchings, greedy, sortings, two pointers Correct Solution: ``` # Velichko β™₯ n = int(input()) b = list (map(int,input().split())) m = int(input()) g = list (map(int,input().split())) i=int(0) j=int(0) ans=int(0) g.sort() b.sort() while i<n and j<m: if b[i]-1>g[j]: j+=1 else: if g[j]-1>b[i]: i+=1 else: i+=1 j+=1 ans+=1 print(ans) ```
output
1
58,409
14
116,819
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) l=[];a.sort();b.sort();k=0 for i in range(n): for j in range(m): if abs(a[i]-b[j])<=1 and j not in l: k+=1 l.append(j) break print(k) ```
instruction
0
58,410
14
116,820
Yes
output
1
58,410
14
116,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` n = int(input()) b = list(map(int,input().split())) m = int(input()) g = list(map(int,input().split())) b.sort() g.sort() count = 0 l = [] for i in range (n): for j in range (m): if (b[i] - g[j] == 0 or abs(b[i] - g[j]) == 1) and j not in l: count+=1 l.append(j) break print(count) ```
instruction
0
58,411
14
116,822
Yes
output
1
58,411
14
116,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` nb = int(input()) bs = input() ng = int(input()) gs = input() bs = [int(item) for item in bs.split()] gs = [int(item) for item in gs.split()] bs.sort() gs.sort() pairs = 0 b = 0 while b < len(bs): g = 0 paired = False while g < len(gs) and not paired: if abs(gs[g]-bs[b]) <= 1: paired = True pairs += 1 gs.pop(g) bs.pop(b) else: g += 1 if not paired: b += 1 print(pairs) ```
instruction
0
58,412
14
116,824
Yes
output
1
58,412
14
116,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` n=int(input()) s=input() l=s.split() d1={} for i in l: x=int(i) if x not in d1: d1[x]=1 else: d1[x]+=1 n=int(input()) s=input() l=s.split() d2={} for i in l: x=int(i) if x not in d2: d2[x]=1 else: d2[x]+=1 cnt=0 for i in d1: for j in d2: if j-i==1 and d2[j]!=0: d2[j]-=1 cnt+=1 if cnt==0: print(cnt) else: print(cnt+1) ```
instruction
0
58,414
14
116,828
No
output
1
58,414
14
116,829
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` input() hombres = input().split(" ") input() mujeres = input().split(" ") hombres.sort() mujeres.sort() emparejados = 0 if len(hombres) <= len(mujeres): for h in hombres: for m in mujeres: if int(h) == int(m) + 1 or int(h) == int(m) or int(h) == int(m) - 1: emparejados += 1 mujeres.remove(m) break else: for m in mujeres: for h in hombres: if int(m) == int(h) + 1 or int(m) == int(h) or int(m) == int(h) - 1: emparejados += 1 hombres.remove(h) break print(emparejados) ```
instruction
0
58,415
14
116,830
No
output
1
58,415
14
116,831
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` n = int(input()) boys = input().split() for i in range(n): boys[i] = int(boys[i]) m = int(input()) girls = input().split() for i in range(m): girls[i] = int(girls[i]) boys.sort() girls.sort() pairs = 0 while len(girls)>0 and len(boys)>0: if abs(girls[0] - boys[0])<=1: pairs+=1 del girls[0] del boys[0] else: del boys[0] del girls[0] print(pairs) ```
instruction
0
58,416
14
116,832
No
output
1
58,416
14
116,833
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves. We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one. For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls. Input The first line contains an integer n (1 ≀ n ≀ 100) β€” the number of boys. The second line contains sequence a1, a2, ..., an (1 ≀ ai ≀ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≀ m ≀ 100) β€” the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≀ bj ≀ 100), where bj is the j-th girl's dancing skill. Output Print a single number β€” the required maximum possible number of pairs. Examples Input 4 1 4 6 2 5 5 1 5 7 9 Output 3 Input 4 1 2 3 4 4 10 11 12 13 Output 0 Input 5 1 1 1 1 1 3 1 2 3 Output 2 Submitted Solution: ``` b=int(input()) x=list(map(int,input().split())) g=int(input()) y=list(map(int,input().split())) x.sort() y.sort() c=0 d=0 if(x[0]<=y[0]): for i in range(b): if (x[i] in y): y.remove(x[i]) c+=1 if(x[i]+1 in y): y.remove(x[i]+1) c+=1 if(x[i]-1 in y): y.remove(x[i]-1) c+=1 #print(c) else: for i in range(g): if (y[i] in x): x.remove(y[i]) c+=1 if(y[i]+1 in x): x.remove(y[i]+1) c+=1 if(y[i]-1 in x): x.remove(y[i]-1) c+=1 #print(c) print(c) ```
instruction
0
58,417
14
116,834
No
output
1
58,417
14
116,835
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,469
14
116,938
Tags: implementation Correct Solution: ``` n,k,q=input().split() rank=input().split() for i in range(len(rank)): rank[i]=int(rank[i]) li=[] names=[] for i in range(int(q)): query=input().split() if(query[0]=='1'): if(len(li)<int(k)): names.append(query[1]) li.append(rank[int(query[1])-1]) else: m=min(li) ind=li.index(m) if(rank[int(query[1])-1]>m): del li[ind] del names[ind] names.append(query[1]) li.append(rank[int(query[1])-1]) if(query[0]=='2'): if(query[1] in names): print("YES") else: print("NO") ```
output
1
58,469
14
116,939
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,470
14
116,940
Tags: implementation Correct Solution: ``` def Core(size, rate, data): online_rate = [] count = 0 for item in data: if item[0] == 1: if size > count: count += 1 online_rate.append(rate[item[1]]) online_rate.sort(key=lambda x: -x) elif online_rate[-1] < rate[item[1]]: online_rate[-1] = rate[item[1]] online_rate.sort(key=lambda x: -x) else: if rate[item[1]] in online_rate and online_rate.index(rate[item[1]]) < size: print("YES") else: print("NO") param1 = input().split(" ") param2 = [0] + [int(i) for i in input().split(" ")] param3 = [[int(j) for j in input().split(" ")] for i in range(int(param1[2]))] Core(int(param1[1]), param2, param3) ```
output
1
58,470
14
116,941
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,471
14
116,942
Tags: implementation Correct Solution: ``` import os import sys import math import heapq from decimal import * from io import BytesIO, IOBase from collections import defaultdict, deque def main(): n,k,q = rm() a = rl() b = [] for i in range(q): c,d=rm() if c==1: d-=1 b.append([a[d],d]) b.sort(reverse=True) b = b[:k] elif c==2: d-=1 ans = False for i in b: if i[1]==d: ans=True break if ans: print("YES") else: print("NO") # 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 def r(): return int(input()) def rm(): return map(int,input().split()) def rl(): return list(map(int,input().split())) main() ```
output
1
58,471
14
116,943
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,472
14
116,944
Tags: implementation Correct Solution: ``` n=input() b=[] b=n.split() n=int(b[0]) k=int(b[1]) q=int(b[2]) c=input() level=c.split() online=[] for i in range(q): c=input() z=c.split() if z[0]=='1': if len(online)<k: online.append(int(z[1])) else: min=int(level[int(z[1])-1]) number=-1 for j in range(k): if int(level[online[j]-1])<min: min=int(level[online[j]-1]) number=j if number>-1: online[number]=int(z[1]) else: if online.count(int(z[1]))>0: print('YES') else: print('NO') ```
output
1
58,472
14
116,945
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,473
14
116,946
Tags: implementation Correct Solution: ``` from heapq import * n, f, q = [int(s) for s in input().split()] loves = [int(s) for s in input().split()] k = [] onlines = set() for i in range(q): ind, num = [int(s) for s in input().split()] if ind == 1: onlines.add(num - 1) if len(k)<f: heappush(k, loves[num - 1]) else: heappushpop(k, loves[num-1]) else: if num-1 in onlines and k[0] <= loves[num-1]: print("YES") else: print("NO") ```
output
1
58,473
14
116,947
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,474
14
116,948
Tags: implementation Correct Solution: ``` n, k, q = [int(i) for i in input().split()] t = input().split() ID = {} online = [] for i in range(len(t)): ID[i+1] = t[i] for i in range(q): a = list(map(int,input().split())) if a[0] == 1: online.append([a[1],int(ID[a[1]])]) if len(online) > k: online.sort(key = lambda x:x[1]) del online[0] if a[0] == 2: if [a[1],int(ID[a[1]])] in online: print('YES') else: print('NO') ```
output
1
58,474
14
116,949
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,475
14
116,950
Tags: implementation Correct Solution: ``` def type1(idi): global mnoj, n, k, q, t if len(mnoj) < k: mnoj.add(t[idi]) else: mn = min(mnoj) if t[idi] > mn: mnoj.remove(mn) mnoj.add(t[idi]) def main(): global mnoj, n, k, q, t n, k, q = map(int, input().split()) t = list(map(int, input().split())) mnoj = set() for i in range(q): typei, idi = map(int, input().split()) idi -= 1 if typei == 1: type1(idi) else: if t[idi] in mnoj: print("YES") else: print("NO") main() ```
output
1
58,475
14
116,951
Provide tags and a correct Python 3 solution for this coding contest problem. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES".
instruction
0
58,476
14
116,952
Tags: implementation Correct Solution: ``` n, size, tasks = map(int, input().split()) friends = list(map(int, input().split())) online = list() for i in range(tasks): type, id = map(int, input().split()) id -= 1 if type == 1: adds = friends[id] online = sorted(online + [adds], reverse=True) if len(online) > size: del online[-1] else: flag_oh_my_god_why = False search = friends[id] for bear in online: if bear == search: flag_oh_my_god_why = True break if flag_oh_my_god_why == False: print('NO') else: print('YES') ```
output
1
58,476
14
116,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` n,k,q=map(int,input().split()) t=list(map(int,input().split())) ls=[] acti=[-1 for i in range(n)] while q>0: q-=1 a,b=map(int,input().split()) b-=1 if a==1 and acti[b]==-1 : acti[b]=1 ls.append([t[b],b]) ls.sort(reverse=True) if len(ls)>k: ls=ls[0:k] continue if a==2 : for j in ls: if j[1]==b: print("YES") break else : print("NO") ```
instruction
0
58,477
14
116,954
Yes
output
1
58,477
14
116,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` import sys window = set() n, k, q = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] for i in range(q): a, b = [int(x) for x in input().split()] if (a == 1): if (len(window) < k): window.add(arr[b - 1]) else: window.add(arr[b - 1]) m = min(window) window.remove(m) else: print("YES" if arr[b - 1] in window else "NO") ```
instruction
0
58,478
14
116,956
Yes
output
1
58,478
14
116,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` n, k, q = map(int, input().split()) data = list(map(int, input().split())) data1 = set() for i in range(q): typ, fr = map(int, input().split()) fr -= 1 if typ == 2: if data[fr] in data1: print("YES") else: print("NO") else: if len(list(data1)) < k: data1.add(data[fr]) elif data[fr] >= min(list(data1)): data1.add(data[fr]) data1.remove(min(list(data1))) ```
instruction
0
58,479
14
116,958
Yes
output
1
58,479
14
116,959
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` n, k, q = [int(x) for x in input().split()] T = [int(x) for x in input().split()] S = set() for i in range(q): t, _id = [int(x) for x in input().split()] if t == 1: m = min(S, default = 0) if len(S) == k: if m < T[_id-1]: S.remove(m) S.add(T[_id-1]) else: S.add(T[_id-1]) else: print('YES' if T[_id-1] in S else 'NO') ```
instruction
0
58,480
14
116,960
Yes
output
1
58,480
14
116,961
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` n, k, q = map(int, input().split()) rel = [int(x) for x in input().split()] display = [] num = 0 for i in range(q): type, id = map(int, input().split()) if type == 1: if num < k: display.append(id) num += 1 else: tmp = [] for num in display: tmp.append(rel[num-1]) m = min(tmp) ix = tmp.index(m) if rel[id-1] > m: display.append(id) display.pop(ix) elif type == 2: if id in display: print('YES') else: print('NO') ```
instruction
0
58,481
14
116,962
No
output
1
58,481
14
116,963
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` def bin(x): if (x in z) or (len(b) == 0) or (len(b) == 1 and b[0] != x): print('NO') return if b[min(len(b) - 1, k - 1)] <= x: print('YES') return else: print('NO') return b = [] n, k, q = map(int, input().split()) z = dict() a = [int(x) for x in input().split()] for i in range(q): x, y = map(int, input().split()) if x == 1: if len(b) != 0 and b[-1] > a[y - 1] and len(b) >= k: z[a[y - 1]] = 1 else: b.append(a[y - 1]) for j in range(len(b) - 1, 0, -1): if b[j] > b[j - 1]: b[j], b[j - 1] = b[j - 1], b[j] else: bin(a[y - 1]) ```
instruction
0
58,482
14
116,964
No
output
1
58,482
14
116,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` from sys import stdin as Si from operator import itemgetter as ig if __name__=='__main__': n,k,q = map(int,Si.readline().split()) T = tuple(map(int,Si.readline().split())) stack = {} for i in range(q): a,b = map(int,Si.readline().split()) #print(a,b,stack) if a==1: if len(stack)<k: stack[b]=T[b-1] else: while len(stack)>=k: x,y = min(stack.items(),key=ig(1)) del stack[x] stack[b] = T[b-1] elif a==2: if b in stack: print('YES') else: print('NO') ''' A. Bear and Reverse Radewoosh time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty β€” it's guaranteed that pi < pi + 1 and ti < ti + 1. A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,  pi - cΒ·x) points. Limak is going to solve problems in order 1, 2, ..., n (sorted increasingly by pi). Radewoosh is going to solve them in order n, n - 1, ..., 1 (sorted decreasingly by pi). Your task is to predict the outcome β€” print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie. You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems. Input The first line contains two integers n and c (1 ≀ n ≀ 50, 1 ≀ c ≀ 1000) β€” the number of problems and the constant representing the speed of loosing points. The second line contains n integers p1, p2, ..., pn (1 ≀ pi ≀ 1000, pi < pi + 1) β€” initial scores. The third line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 1000, ti < ti + 1) where ti denotes the number of minutes one needs to solve the i-th problem. Output Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. Examples Input 3 2 50 85 250 10 15 25 Output Limak Input 3 6 50 85 250 10 15 25 Output Radewoosh Input 8 1 10 20 30 40 50 60 70 80 8 10 58 63 71 72 75 76 Output Tie Note In the first sample, there are 3 problems. Limak solves them as follows: Limak spends 10 minutes on the 1-st problem and he gets 50 - cΒ·10 = 50 - 2Β·10 = 30 points. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2Β·25 = 35 points. He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2Β·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points. Radewoosh solves problem in the reversed order: Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2Β·25 = 200 points. He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2Β·40 = 5 points for this problem. He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets max(0, 50 - 2Β·50) = max(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins. In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6Β·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway. In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4. ''' ```
instruction
0
58,483
14
116,966
No
output
1
58,483
14
116,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti. Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time. The system displays friends who are online. On the screen there is space to display at most k friends. If there are more than k friends online then the system displays only k best of them β€” those with biggest ti. Your task is to handle queries of two types: * "1 id" β€” Friend id becomes online. It's guaranteed that he wasn't online before. * "2 id" β€” Check whether friend id is displayed by the system. Print "YES" or "NO" in a separate line. Are you able to help Limak and answer all queries of the second type? Input The first line contains three integers n, k and q (1 ≀ n, q ≀ 150 000, 1 ≀ k ≀ min(6, n)) β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains n integers t1, t2, ..., tn (1 ≀ ti ≀ 109) where ti describes how good is Limak's relation with the i-th friend. The i-th of the following q lines contains two integers typei and idi (1 ≀ typei ≀ 2, 1 ≀ idi ≀ n) β€” the i-th query. If typei = 1 then a friend idi becomes online. If typei = 2 then you should check whether a friend idi is displayed. It's guaranteed that no two queries of the first type will have the same idi becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (typei = 2) so the output won't be empty. Output For each query of the second type print one line with the answer β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. Examples Input 4 2 8 300 950 500 200 1 3 2 4 2 3 1 1 1 2 2 1 2 2 2 3 Output NO YES NO YES YES Input 6 3 9 50 20 51 17 99 24 1 3 1 4 1 5 1 2 2 4 2 2 1 1 2 4 2 3 Output NO YES NO YES Note In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3" β€” Friend 3 becomes online. 2. "2 4" β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 3. "2 3" β€” We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 4. "1 1" β€” Friend 1 becomes online. The system now displays both friend 1 and friend 3. 5. "1 2" β€” Friend 2 becomes online. There are 3 friends online now but we were given k = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (t1 < t2, t3) so friend 1 won't be displayed 6. "2 1" β€” Print "NO". 7. "2 2" β€” Print "YES". 8. "2 3" β€” Print "YES". Submitted Solution: ``` import sys def siftup(ind): global tree while (ind != 1) and (frendly[tree[ind]] < frendly[tree[ind // 2]]): tree[ind], tree[ind // 2] = tree[ind // 2], tree[ind] ind //= 2 def siftdown(ind): global tree while (ind * 2 + 1 <= len(tree) - 1) and (frendly[tree[ind]] > frendly[tree[ind * 2]] or frendly[tree[ind]] > frendly[tree[ind * 2 + 1]]): if frendly[tree[ind * 2]] > frendly[tree[ind * 2 + 1]]: tree[ind], tree[ind * 2 + 1] = tree[ind * 2 + 1], tree[ind] ind = ind * 2 + 1 else: tree[ind], tree[ind * 2] = tree[ind * 2], tree[ind] ind *= 2 if (ind * 2 <= len(tree) - 1) and (frendly[tree[ind]] > frendly[tree[ind * 2]]): tree[ind], tree[ind * 2] = tree[ind * 2], tree[ind] ind *= 2 n, k, q = map(int, sys.stdin.readline().split()) frendly = [0] + list(map(int, sys.stdin.readline().split())) bearsout = set([i for i in range(1, n + 1)]) tree = [0] for i in range(q): lab, b = map(int, sys.stdin.readline().split()) if lab == 1: if len(tree) > k: if frendly[b] > frendly[tree[1]]: bearsout.discard(b) bearsout.add(tree[1]) tree[1] = b siftdown(1) else: tree.append(b) bearsout.discard(b) siftup(len(tree) - 1) else: if b in bearsout: sys.stdout.write('NO') else: sys.stdout.write('YES') ```
instruction
0
58,484
14
116,968
No
output
1
58,484
14
116,969
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,533
14
117,066
Tags: implementation Correct Solution: ``` import sys try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass input = sys.stdin.readline n, q = map(int, input().split()) server = [-1]*n for _ in range(q): t, k, d = map(int, input().split()) cnt = 0 for i in range(n): if t >= server[i]: server[i] = -1 if server[i] == -1: cnt += 1 if k <= cnt: ans = 0 for i in range(n): if server[i] == -1: server[i] = t + d ans += i+1 k -= 1 if not k: break print(ans) else: print(-1) ```
output
1
58,533
14
117,067
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,534
14
117,068
Tags: implementation Correct Solution: ``` import heapq as pq from sys import stdin, stdout #Heap method written by Engineermind.cho #Testing if heap + fast IO can make python pass this question n, q = map(int, stdin.readline().split()) server = [i for i in range(1, n+1)] running = [] is_chg = False for x in stdin.readlines(): t, k, d = map(int, x.split()) while running: if t >= running[0][0]: server += pq.heappop(running)[1] is_chg = True else: break if is_chg: server = sorted(server) is_chg = False if len(server) < k: print(-1) continue else: print(sum(server[:k])) if d != 1: pq.heappush(running, (t+d, server[:k].copy())) server = server[k:] ```
output
1
58,534
14
117,069
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,535
14
117,070
Tags: implementation Correct Solution: ``` ''' 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 ''' p=input().rstrip().split(' ') n=int(p[0]) q=int(p[1]) L=[0]*n; Q=[] W=[] S=[] D=[] for i in range(0,q): o=input().rstrip().split(' ') t=int(o[0]) k=int(o[1]) d=int(o[2]) j=0; while(len(S)>0 and j<len(S)): if S[j] <= t: R=W[j]; del(S[j]) del(W[j]); for M in range(0,len(R)): L[R[M]-1]=0; else: j+=1; if L.count(0) >= k: E=[] ans=0; for j in range(0,len(L)): if L[j]==0 and k!=0: E.append(j+1) ans+=(j+1) k-=1; L[j]=1; W.append(E) S.append(t+d) print(ans) else: print(-1) # print(S,W,L) ```
output
1
58,535
14
117,071
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,536
14
117,072
Tags: implementation Correct Solution: ``` n , q = map(int,input().split()) tasks=[] servers = [0]*n for _ in range(q): tasks.append(tuple(map(int,input().split()))) for t,k,d in tasks: a = [] for i in range(n): if t>=servers[i]: a.append(i) if len(a)>=k: total = 0 for s in range(k): total+=a[s]+1 servers[a[s]]=t+d print(total) else: print(-1) ```
output
1
58,536
14
117,073
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,537
14
117,074
Tags: implementation Correct Solution: ``` import sys input = sys.stdin.readline # server, task = map(int, input().split()) serverstatus = [0]*server for i in range(task): moment, serven, time = map(int, input().split()) ava = 0 total = 0 d = serverstatus[:] for i in range(server): if ava < serven and serverstatus[i] <= moment: ava += 1 total += i+1 d[i] = moment + time elif ava == serven: break if ava < serven: print(-1) else: print(total) serverstatus = d[:] ```
output
1
58,537
14
117,075
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,538
14
117,076
Tags: implementation Correct Solution: ``` import heapq as pq from sys import stdin, stdout #Heap method written by Engineermind.cho #Testing if heap + fast IO can make python pass this question n, q = map(int, stdin.readline().split()) server = [i for i in range(1, n+1)] running = [] is_chg = False for x in stdin.readlines(): t, k, d = map(int, x.split()) while running: if t >= running[0][0]: server += pq.heappop(running)[1] is_chg = True else: break if is_chg: server = sorted(server) is_chg = False if len(server) < k: stdout.write('-1\n') continue else: stdout.write(str(sum(server[:k]))+'\n') if d != 1: pq.heappush(running, (t+d, server[:k].copy())) server = server[k:] # Made By Mostafa_Khaled ```
output
1
58,538
14
117,077
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,539
14
117,078
Tags: implementation Correct Solution: ``` num = [int(n) for n in input().split()] server = [0 for n in range(0,num[0])] result = list() num_task = num[1] temp_ti = 0 for i in range(0,num_task): temp_task = [int(n) for n in input().split()] time_passed = temp_task[0]-temp_ti temp_ti = temp_task[0] ###length for n in range(0,num[0]): server[n] -= time_passed server[n] = 0 if(server[n]<0) else server[n] if(server.count(0) < temp_task[1]): result.append(-1) else: accumulate_result = 0 for i in range(0,num[0]): if(not bool(server[i])): server[i] += temp_task[2] temp_task[1] -=1 accumulate_result +=(i+1) if(temp_task[1] ==0): break result.append(accumulate_result) for i in range(0,num_task): print(result[i]) ```
output
1
58,539
14
117,079
Provide tags and a correct Python 3 solution for this coding contest problem. There are n servers in a laboratory, each of them can perform tasks. Each server has a unique id β€” integer from 1 to n. It is known that during the day q tasks will come, the i-th of them is characterized with three integers: ti β€” the moment in seconds in which the task will come, ki β€” the number of servers needed to perform it, and di β€” the time needed to perform this task in seconds. All ti are distinct. To perform the i-th task you need ki servers which are unoccupied in the second ti. After the servers begin to perform the task, each of them will be busy over the next di seconds. Thus, they will be busy in seconds ti, ti + 1, ..., ti + di - 1. For performing the task, ki servers with the smallest ids will be chosen from all the unoccupied servers. If in the second ti there are not enough unoccupied servers, the task is ignored. Write the program that determines which tasks will be performed and which will be ignored. Input The first line contains two positive integers n and q (1 ≀ n ≀ 100, 1 ≀ q ≀ 105) β€” the number of servers and the number of tasks. Next q lines contains three integers each, the i-th line contains integers ti, ki and di (1 ≀ ti ≀ 106, 1 ≀ ki ≀ n, 1 ≀ di ≀ 1000) β€” the moment in seconds in which the i-th task will come, the number of servers needed to perform it, and the time needed to perform this task in seconds. The tasks are given in a chronological order and they will come in distinct seconds. Output Print q lines. If the i-th task will be performed by the servers, print in the i-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. Examples Input 4 3 1 3 2 2 2 1 3 4 3 Output 6 -1 10 Input 3 2 3 2 3 5 1 2 Output 3 3 Input 8 6 1 3 20 4 2 1 6 5 5 10 1 1 15 3 6 21 8 8 Output 6 9 30 -1 15 36 Note In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third task will come. By this time, servers with the ids 1, 2 and 3 will be unoccupied again, so the third task will be done on all the servers with the ids 1, 2, 3 and 4 (the sum of the ids is 10). In the second example in the second 3 the first task will come, it will be performed on the servers with ids 1 and 2 (the sum of the ids is 3) during three seconds. In the second 5 the second task will come, it will be performed on the server 3, because the first two servers will be busy performing the first task.
instruction
0
58,540
14
117,080
Tags: implementation Correct Solution: ``` n,q=map(int,input().split()) s=[0]*(n+1) ans = [] for i in range(q): t,k,d=map(int,input().split()) sm=[] for j in range(1, n+1): if s[j] < t: sm.append(j) if len(sm)==k:break if len(sm)!=k:ans.append('-1') else: ans.append(str(sum(sm))) for j in sm: s[j]=d+t-1 print('\n'.join(ans)) ```
output
1
58,540
14
117,081