message stringlengths 2 20.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 757 108k | cluster float64 4 4 | __index_level_0__ int64 1.51k 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,975 | 4 | 123,950 |
Tags: data structures, sortings
Correct Solution:
```
n = int(input())
lis = []
for i in range(n):
a, b = map(int, input().split())
lis.append([a, b, i+1])
lis.sort()
i = 1
ans = -1
while i<n:
if lis[i][1]<=lis[i-1][1]:
ans = lis[i][2]
print(ans)
exit(0)
elif( lis[i][0] <= lis[i-1][0] and lis[i][1] >= lis[i-1][1]):
ans = lis[i-1][2]
print(ans)
exit(0)
lis[i][0] = max( lis[i][0], lis[i-1][1] + 1)
i+=1
print(ans)
``` | output | 1 | 61,975 | 4 | 123,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,976 | 4 | 123,952 |
Tags: data structures, sortings
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
#import threading
from collections import defaultdict
#threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
#sys.setrecursionlimit(300000)
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")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=300006, func=lambda a, b: min(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b:a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] <key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
class TrieNode:
def __init__(self):
self.children = [None] * 26
self.isEndOfWord = False
class Trie:
def __init__(self):
self.root = self.getNode()
def getNode(self):
return TrieNode()
def _charToIndex(self, ch):
return ord(ch) - ord('a')
def insert(self, key):
pCrawl = self.root
length = len(key)
for level in range(length):
index = self._charToIndex(key[level])
if not pCrawl.children[index]:
pCrawl.children[index] = self.getNode()
pCrawl = pCrawl.children[index]
pCrawl.isEndOfWord = True
def search(self, key):
pCrawl = self.root
length = len(key)
for level in range(length):
index = self._charToIndex(key[level])
if not pCrawl.children[index]:
return False
pCrawl = pCrawl.children[index]
return pCrawl != None and pCrawl.isEndOfWord
#-----------------------------------------trie---------------------------------
class Node:
def __init__(self, data):
self.data = data
self.height=0
self.left = None # left node for 0
self.right = None # right node for 1
class BinaryTrie:
def __init__(self):
self.root = Node(0)
def insert(self, pre_xor):
self.temp = self.root
for i in range(31, -1, -1):
val = pre_xor & (1 << i)
if val==0:
if not self.temp.right:
self.temp.right = Node(0)
self.temp = self.temp.right
elif val>=1:
if not self.temp.left:
self.temp.left = Node(0)
self.temp = self.temp.left
def do(self,temp):
if not temp:
return 0
ter=temp
temp.height=self.do(ter.left)+self.do(ter.right)
if temp.height==0:
temp.height+=1
return temp.height
def query(self, xor):
self.temp = self.root
cur=0
i=31
while(i>-1):
val = xor & (1 << i)
if not self.temp:
return cur
if val>=1:
self.opp = self.temp.right
if self.temp.left:
self.temp = self.temp.left
else:
return cur
else:
self.opp=self.temp.left
if self.temp.right:
self.temp = self.temp.right
else:
return cur
if self.temp.height==pow(2,i):
cur+=1<<(i)
self.temp=self.opp
i-=1
return cur
#-------------------------bin trie-------------------------------------------
n=int(input())
l=[]
w=[]
for i in range(n):
a,b=map(int,input().split())
l.append((a,b))
w.append(a)
w.append(b)
w.append(a-1)
w.append(a+1)
w.append(b-1)
w.append(b+1)
w=sorted(set(w))
ind=defaultdict(int)
for i in range(len(w)):
ind[w[i]]=i
e=[0]*(len(w)+1)
for i in range(n):
a,b=l[i]
a1=ind[a]
b1=ind[b+1]
e[a1]+=1
e[b1]-=1
for i in range(1,len(w)):
e[i]+=e[i-1]
s=SegmentTree1(e)
f=0
for i in range(n):
a,b=l[i]
a1 = ind[a]
b1 = ind[b]
if s.query(a1,b1)>1:
print(i+1)
f=1
break
if f==0:
print(-1)
``` | output | 1 | 61,976 | 4 | 123,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,977 | 4 | 123,954 |
Tags: data structures, sortings
Correct Solution:
```
import sys
from heapq import heappop, heappush
from collections import Counter
n = int(sys.stdin.buffer.readline().decode('utf-8'))
query = []
imos = Counter()
for i, (l, r) in enumerate(map(int, line.decode('utf-8').split()) for line in sys.stdin.buffer):
query.append((l, r+1, i+1))
imos[l] += 1
imos[r+1] -= 1
query.sort()
acc = 0
hq = []
i = 0
for t in sorted(imos.keys()):
while hq and hq[0][0] == t:
print(hq[0][1])
exit()
acc += imos[t]
if acc > 1:
while i < n and query[i][0] == t:
heappush(hq, (query[i][1], query[i][2]))
i += 1
else:
while i < n and query[i][0] == t:
i += 1
hq.clear()
print(-1)
``` | output | 1 | 61,977 | 4 | 123,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,978 | 4 | 123,956 |
Tags: data structures, sortings
Correct Solution:
```
import os, 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")
mod = 998244353
from math import log2
from bisect import bisect_right
a=[]
for i in range(int(input())):
a.append(list(map(int,input().split()))+[i+1])
a.sort()
n=len(a)
if n==1:
print(-1)
else:
for i in range(n):
bol=True
if i==0:
if a[i][0]<a[i+1][0] :
bol=False
elif i==n-1:
if a[i-1][1]<a[i][1]:
bol=False
else:
x1=a[i-1][0]
x2=a[i-1][1]
x3=a[i+1][0]
x4=a[i+1][1]
if x2+1<x3:
if a[i][0]!=x3 and a[i][1]>x2:
bol=False
else:
x4=max(x4,x2)
if not (x1<=a[i][0] and a[i][1]<=x4):
bol=False
if bol:
print(a[i][2])
break
else:
print(-1)
``` | output | 1 | 61,978 | 4 | 123,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,979 | 4 | 123,958 |
Tags: data structures, sortings
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
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")
#-------------------game starts now-----------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
class SegmentTree1:
def __init__(self, data, default=0, func=lambda a, b: a+b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(11)]
prime[0]=prime[1]=False
#pp=[0]*10
def SieveOfEratosthenes(n=10):
p = 2
c=0
while (p <= n):
if (prime[p] == True):
c+=1
for i in range(p, n+1, p):
#pp[i]=1
prime[i] = False
p += 1
#-----------------------------------DSU--------------------------------------------------
class DSU:
def __init__(self, R, C):
#R * C is the source, and isn't a grid square
self.par = range(R*C + 1)
self.rnk = [0] * (R*C + 1)
self.sz = [1] * (R*C + 1)
def find(self, x):
if self.par[x] != x:
self.par[x] = self.find(self.par[x])
return self.par[x]
def union(self, x, y):
xr, yr = self.find(x), self.find(y)
if xr == yr: return
if self.rnk[xr] < self.rnk[yr]:
xr, yr = yr, xr
if self.rnk[xr] == self.rnk[yr]:
self.rnk[xr] += 1
self.par[yr] = xr
self.sz[xr] += self.sz[yr]
def size(self, x):
return self.sz[self.find(x)]
def top(self):
# Size of component at ephemeral "source" node at index R*C,
# minus 1 to not count the source itself in the size
return self.size(len(self.sz) - 1) - 1
#---------------------------------Lazy Segment Tree--------------------------------------
# https://github.com/atcoder/ac-library/blob/master/atcoder/lazysegtree.hpp
class LazySegTree:
def __init__(self, _op, _e, _mapping, _composition, _id, v):
def set(p, x):
assert 0 <= p < _n
p += _size
for i in range(_log, 0, -1):
_push(p >> i)
_d[p] = x
for i in range(1, _log + 1):
_update(p >> i)
def get(p):
assert 0 <= p < _n
p += _size
for i in range(_log, 0, -1):
_push(p >> i)
return _d[p]
def prod(l, r):
assert 0 <= l <= r <= _n
if l == r:
return _e
l += _size
r += _size
for i in range(_log, 0, -1):
if ((l >> i) << i) != l:
_push(l >> i)
if ((r >> i) << i) != r:
_push(r >> i)
sml = _e
smr = _e
while l < r:
if l & 1:
sml = _op(sml, _d[l])
l += 1
if r & 1:
r -= 1
smr = _op(_d[r], smr)
l >>= 1
r >>= 1
return _op(sml, smr)
def apply(l, r, f):
assert 0 <= l <= r <= _n
if l == r:
return
l += _size
r += _size
for i in range(_log, 0, -1):
if ((l >> i) << i) != l:
_push(l >> i)
if ((r >> i) << i) != r:
_push((r - 1) >> i)
l2 = l
r2 = r
while l < r:
if l & 1:
_all_apply(l, f)
l += 1
if r & 1:
r -= 1
_all_apply(r, f)
l >>= 1
r >>= 1
l = l2
r = r2
for i in range(1, _log + 1):
if ((l >> i) << i) != l:
_update(l >> i)
if ((r >> i) << i) != r:
_update((r - 1) >> i)
def _update(k):
_d[k] = _op(_d[2 * k], _d[2 * k + 1])
def _all_apply(k, f):
_d[k] = _mapping(f, _d[k])
if k < _size:
_lz[k] = _composition(f, _lz[k])
def _push(k):
_all_apply(2 * k, _lz[k])
_all_apply(2 * k + 1, _lz[k])
_lz[k] = _id
_n = len(v)
_log = _n.bit_length()
_size = 1 << _log
_d = [_e] * (2 * _size)
_lz = [_id] * _size
for i in range(_n):
_d[_size + i] = v[i]
for i in range(_size - 1, 0, -1):
_update(i)
self.set = set
self.get = get
self.prod = prod
self.apply = apply
MIL = 1 << 20
def makeNode(total, count):
# Pack a pair into a float
return (total * MIL) + count
def getTotal(node):
return math.floor(node / MIL)
def getCount(node):
return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)
def nodeOp(node1, node2):
return node1 + node2
# Equivalent to the following:
return makeNode(
getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2)
)
identityMapping = -1
def mapping(tag, node):
if tag == identityMapping:
return node
# If assigned, new total is the number assigned times count
count = getCount(node)
return makeNode(tag * count, count)
def composition(mapping1, mapping2):
# If assigned multiple times, take first non-identity assignment
return mapping1 if mapping1 != identityMapping else mapping2
#---------------------------------Pollard rho--------------------------------------------
def memodict(f):
"""memoization decorator for a function taking a single argument"""
class memodict(dict):
def __missing__(self, key):
ret = self[key] = f(key)
return ret
return memodict().__getitem__
def pollard_rho(n):
"""returns a random factor of n"""
if n & 1 == 0:
return 2
if n % 3 == 0:
return 3
s = ((n - 1) & (1 - n)).bit_length() - 1
d = n >> s
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
p = pow(a, d, n)
if p == 1 or p == n - 1 or a % n == 0:
continue
for _ in range(s):
prev = p
p = (p * p) % n
if p == 1:
return math.gcd(prev - 1, n)
if p == n - 1:
break
else:
for i in range(2, n):
x, y = i, (i * i + 1) % n
f = math.gcd(abs(x - y), n)
while f == 1:
x, y = (x * x + 1) % n, (y * y + 1) % n
y = (y * y + 1) % n
f = math.gcd(abs(x - y), n)
if f != n:
return f
return n
@memodict
def prime_factors(n):
"""returns a Counter of the prime factorization of n"""
if n <= 1:
return Counter()
f = pollard_rho(n)
return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)
def distinct_factors(n):
"""returns a list of all distinct factors of n"""
factors = [1]
for p, exp in prime_factors(n).items():
factors += [p**i * factor for factor in factors for i in range(1, exp + 1)]
return factors
def all_factors(n):
"""returns a sorted list of all distinct factors of n"""
small, large = [], []
for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
if not n % i:
small.append(i)
large.append(n // i)
if small[-1] == large[-1]:
large.pop()
large.reverse()
small.extend(large)
return small
#---------------------------------Binary Search------------------------------------------
def binarySearch(arr, n, key):
left = 0
right = n-1
mid = 0
res = n
while (left <= right):
mid = (right + left)//2
if (arr[mid] > key):
res=mid
right = mid-1
else:
left = mid + 1
return res
def binarySearch1(arr, n, key):
left = 0
right = n-1
mid = 0
res=-1
while (left <= right):
mid = (right + left)//2
if (arr[mid] > key):
right = mid-1
else:
res=mid
left = mid + 1
return res
#---------------------------------running code------------------------------------------
n=int(input())
l=[]
for i in range(n):
a,b=(int(i) for i in input().split())
l.append((a,b,i+1))
l1=[]
for i in range(n):
l1.append(l[i])
l1.sort()
ind=-1
le=l1[0][0]
ri=l1[0][1]
k=l1[0][2]
for i in range(1,n):
if(l1[i][0]<=le and l1[i][1]>=ri):
ind=k
break
elif(l1[i][1]<=ri):
ind=l1[i][2]
break
else:
le=max(ri+1,l1[i][0])
ri=l1[i][1]
k=l1[i][2]
print(ind)
``` | output | 1 | 61,979 | 4 | 123,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,980 | 4 | 123,960 |
Tags: data structures, sortings
Correct Solution:
```
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n=int(input())
a=[[-1,-1,0]]
for i in range(n):
a.append(list(map(int,input().split()))+[i+1])
a.append([1000000005,1000000005,n+1])
a.sort()
e=0
for i in range(1,len(a)-1):
b=a[i]
c=a[i-1]
d=a[i+1]
if (c[1]+1>=d[0] and d[1]>=b[1]) or (c[0]<=b[0] and b[1]<=c[1]) or (d[0]<=b[0] and b[1]<=d[1]):
print(b[2])
e=1
break
if e==0:
print(-1)
``` | output | 1 | 61,980 | 4 | 123,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4]. | instruction | 0 | 61,981 | 4 | 123,962 |
Tags: data structures, sortings
Correct Solution:
```
from operator import itemgetter
def main():
n = int(input())
tv = [(-1, -1, 0)]
for i in range(1, n+1):
li, fi = map(int, input().split(' '))
make_tuple = (li, fi, i)
tv.append(make_tuple)
tv.append((10000000000, 10000000000, n+1))
tv.sort()
for i in range(1, n+1):
tp = tv[i-1]
tc = tv[i]
tn = tv[i+1]
if(tc[1] <= tp[1] or (tc[0] >= tn[0] and tc[1] <= tn[1]) or (tp[1]+1 >= tn[0] and tc[1] <= tn[1])):
print(tc[2])
break
else:
print("-1")
if __name__ == "__main__":
main()
``` | output | 1 | 61,981 | 4 | 123,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
"""T=int(input())
for _ in range(0,T):
n=int(input())
a,b=map(int,input().split())
s=input()
s=[int(x) for x in input().split()]
for i in range(0,len(s)):
a,b=map(int,input().split())"""
n=int(input())
L=[]
for i in range(n):
a,b=map(int,input().split())
L.append((a,b,i))
L.sort()
if(n==1):
print(-1)
else:
temp=-2
for i in range(0,len(L)):
if(i==0):
if(L[i][0]==L[i+1][0]):
if(L[i][1]<=L[i+1][1]):
temp=L[i][2]
else:
temp=L[i+1][2]
break
elif(i>0 and i<len(L)-1):
if(L[i][1]<=L[i-1][1]):
temp=L[i][2]
break
elif(L[i][0]==L[i+1][0] and L[i][1]<=L[i+1][1]):
temp=L[i][2]
break
else:
if(L[i][0]<=L[i-1][1] and L[i+1][0]<=L[i-1][1]+1 and L[i+1][1]>=L[i][1]):
temp=L[i][2]
break
elif(L[i][0]>L[i-1][1] and L[i+1][0]<=L[i][0]):
temp=L[i][2]
break
else:
if(L[i][1]<=L[i-1][1]):
temp=L[i][2]
break
print(temp+1)
``` | instruction | 0 | 61,982 | 4 | 123,964 |
Yes | output | 1 | 61,982 | 4 | 123,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
n = int(input())
lst = [(-1, -1, 0)]
for i in range(1, n + 1):
li, ri = map(int,input().split())
lst.append((li, ri, i))
lst.append((1000000001, 1000000001, n+1))
#print(lst)
lst.sort()
#print(lst)
for i in range(1, n + 1):
tc = lst[i]
tp = lst[i - 1]
tn = lst[i + 1]
if (tc[1] <= tp[1]) or (tc[0] >= tn[0] and tc[1] <= tn[1]) or (tp[1] + 1 >= tn[0] and tc[1] <= tn[1]):
print(tc[2])
break
else:
print(-1)
``` | instruction | 0 | 61,983 | 4 | 123,966 |
Yes | output | 1 | 61,983 | 4 | 123,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
n = int(input())
a = [(-1,-1,0)]
for i in range(n):
tl,tr = (map(int, input().split()))
a.append((tl,tr,i+1))
a.append((1000000001,1000000001,n+1))
a.sort()
for i in range(1,n+1):
t = a[i]
tp = a[i-1]
tn = a[i+1]
if (t[1]<=tp[1]) or (t[0]>=tn[0] and t[1]<=tn[1]) or (tp[1]+1>=tn[0] and t[1]<=tn[1]):
print (t[2])
break
else:
print (-1)
``` | instruction | 0 | 61,984 | 4 | 123,968 |
Yes | output | 1 | 61,984 | 4 | 123,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
from collections import defaultdict,deque
import sys
import bisect
import math
input=sys.stdin.readline
mod=1000000007
t=int(input())
both=[]
for ii in range(t):
l,r=map(int,input().split())
both.append([l,r,ii+1])
both.sort()
e=-1
#print(both)
for i in range(t):
if i>0:
if both[i][0]==both[i-1][0]:
print(both[i-1][2])
#print('a')
break
if i<t-1:
if both[i][0]<=e and both[i+1][0]<=e+1 and both[i+1][1]>=both[i][1]:
print(both[i][2])
#print('b')
break
if both[i][0]<=e and both[i][1]<=e:
print(both[i][2])
#print('c')
break
e=max(e,both[i][1])
else:
print(-1)
``` | instruction | 0 | 61,985 | 4 | 123,970 |
Yes | output | 1 | 61,985 | 4 | 123,971 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
from collections import defaultdict,deque
import sys
import bisect
import math
input=sys.stdin.readline
mod=1000000007
t=int(input())
both=[]
for ii in range(t):
l,r=map(int,input().split())
both.append([l,r,ii+1])
both.sort()
ans=-1
r=-1
l=-1
tmp=-1
for i in range(t):
if(both[i][0]<=l and both[i][1]>=r):
ans=tmp
break;
if(both[i][1]<=r):
ans=both[i][2]
break;
else:
l=r+1
r=both[i][1]
tmp=both[i][2]
print(ans)
``` | instruction | 0 | 61,986 | 4 | 123,972 |
No | output | 1 | 61,986 | 4 | 123,973 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
n=int(input())
a=[(-1,-1,0)]
for i in range(n):
x,y=map(int,input().split())
a.append((x,y,i+1))
a.append((1000000005,1000000005,n+1))
a.sort()
for i in range(1,n+1):
t=a[i]
tp=a[i-1]
tn=a[i+1]
#what the fuck
if (t[1]<=tp[1]) or (t[0]>=tn[0] and t[1]<=tn[1]) or (tp[1]+1>=tn[0] and t[1]>=tn[1]):
print(t[2])
break
else:
print(-1)
``` | instruction | 0 | 61,987 | 4 | 123,974 |
No | output | 1 | 61,987 | 4 | 123,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
n = int(input())
lst = [(-1, -1, 0)]
for i in range(1, n + 1):
li, ri = map(int,input().split())
lst.append((li, ri, i))
lst.append((1000000001, 1000000001, n+1))
#print(lst)
lst.sort()
print(lst)
for i in range(1, n + 1):
tc = lst[i]
tp = lst[i - 1]
tn = lst[i + 1]
if (tc[1] <= tp[1]) or (tc[0] >= tn[0] and tc[1] <= tn[1]) or (tp[1] + 1 >= tn[0] and tc[1] <= tn[1]):
print(tc[2])
break
else:
print(-1)
``` | instruction | 0 | 61,988 | 4 | 123,976 |
No | output | 1 | 61,988 | 4 | 123,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.
Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.
Input
The first line contains one integer number n (1 β€ n β€ 2Β·105) β the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 β€ li β€ ri β€ 109) denoting the working time of i-th TV set.
Output
If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them.
Examples
Input
3
1 3
4 6
1 7
Output
1
Input
2
0 10
0 10
Output
1
Input
3
1 2
3 4
6 8
Output
-1
Input
3
1 2
2 3
3 4
Output
2
Note
Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].
Submitted Solution:
```
n=int(input())
a=[(-1,-1,0)]
for i in range(n):
x,y=map(int,input().split())
a.append((x,y,i+1))
a.append((1000000005,1000000005,n+1))
a.sort()
for i in range(1,n+1):
t=a[i]
tp=a[i-1]
tn=a[i+1]
#shut the fuck up
if (t[1]<=tp[1]) or (t[0]>=tn[0] and t[1]<=tn[1]) or (tp[1]+1>=tn[0] and t[1]<=tn[1]):
print(t[2])
break
``` | instruction | 0 | 61,989 | 4 | 123,978 |
No | output | 1 | 61,989 | 4 | 123,979 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,033 | 4 | 126,066 |
"Correct Solution:
```
while True:
num = int(input())
if num == 0:
break
L = [0] * 7
for _ in range(num):
L[min(6,int(input())//10)] += 1
print("\n".join(map(str,L)))
``` | output | 1 | 63,033 | 4 | 126,067 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,034 | 4 | 126,068 |
"Correct Solution:
```
while True:
n = int(input())
if not n:
break
d = {k:[] for k, v in enumerate(range(7))}
for _ in range(n):
age = int(input())
if age >= 10 and age < 20:
d[1].append(1)
elif age >= 20 and age < 30:
d[2].append(1)
elif age >= 30 and age < 40:
d[3].append(1)
elif age >= 40 and age < 50:
d[4].append(1)
elif age >= 50 and age < 60:
d[5].append(1)
elif age >= 60:
d[6].append(1)
else:
d[0].append(1)
for k, v in d.items():
print(sum(v))
``` | output | 1 | 63,034 | 4 | 126,069 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,035 | 4 | 126,070 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0184
"""
import sys
from sys import stdin
from collections import defaultdict
input = stdin.readline
def main(args):
while True:
n = int(input())
if n == 0:
break
visitors = defaultdict(int)
for _ in range(n):
age = int(input())
if age < 10:
visitors['under10'] += 1
elif age < 20:
visitors['10s'] += 1
elif age < 30:
visitors['20s'] += 1
elif age < 40:
visitors['30s'] += 1
elif age < 50:
visitors['40s'] += 1
elif age < 60:
visitors['50s'] += 1
else:
visitors['60s+'] += 1
print(visitors['under10'])
print(visitors['10s'])
print(visitors['20s'])
print(visitors['30s'])
print(visitors['40s'])
print(visitors['50s'])
print(visitors['60s+'])
def main2(args):
while True:
n = int(input())
if n == 0:
break
age = [0] * (12+1)
for _ in range(n):
n = int(input())
age[n//10] += 1
print(age[0])
print(age[1])
print(age[2])
print(age[3])
print(age[4])
print(age[5])
print(sum(age[6:]))
if __name__ == '__main__':
main2(sys.argv[1:])
``` | output | 1 | 63,035 | 4 | 126,071 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,036 | 4 | 126,072 |
"Correct Solution:
```
while 1:
n = int(input())
if n == 0:
break
h = [0, 0, 0, 0, 0, 0, 0 ]
for _ in range(n):
a = int(input())//10
if a > 6:
a = 6
h[a] += 1
for i in range(7):
print(h[i], sep='\n')
``` | output | 1 | 63,036 | 4 | 126,073 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,037 | 4 | 126,074 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0: break
age = [0] * 7
for _ in range(n):
x = int(input())
if x < 10:
age[0] += 1
elif 10 <= x < 20:
age[1] += 1
elif 20 <= x < 30:
age[2] += 1
elif 30 <= x < 40:
age[3] += 1
elif 40 <= x < 50:
age[4] += 1
elif 50 <= x < 60:
age[5] += 1
elif 60 <= x:
age[6] += 1
print('\n'.join(map(str, age)))
``` | output | 1 | 63,037 | 4 | 126,075 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,038 | 4 | 126,076 |
"Correct Solution:
```
while True:
n = int(input())
if n == 0:
break
To_lis = [0,0,0,0,0,0,0]
for i in range(n):
tosi = int(input())
if tosi < 10:
To_lis[0] += 1
elif tosi < 20:
To_lis[1] += 1
elif tosi < 30:
To_lis[2] += 1
elif tosi < 40:
To_lis[3] += 1
elif tosi < 50:
To_lis[4] += 1
elif tosi < 60:
To_lis[5] += 1
else:
To_lis[6] += 1
for k in range(len(To_lis)):
print(To_lis[k])
``` | output | 1 | 63,038 | 4 | 126,077 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,039 | 4 | 126,078 |
"Correct Solution:
```
from collections import Counter
while True:
n = int(input())
if n == 0:
break
a = [int(input()) for _ in range(n)]
cnt = Counter(i for i in range(7))
for v in a:
if v < 10:
cnt[0] += 1
elif v < 20:
cnt[1] += 1
elif v < 30:
cnt[2] += 1
elif v < 40:
cnt[3] += 1
elif v < 50:
cnt[4] += 1
elif v < 60:
cnt[5] += 1
else:
cnt[6] += 1
for i in range(7):
print(cnt[i]-1)
``` | output | 1 | 63,039 | 4 | 126,079 |
Provide a correct Python 3 solution for this coding contest problem.
Tsuruga Castle, a symbol of Aizuwakamatsu City, was named "Tsuruga Castle" after Gamo Ujisato built a full-scale castle tower. You can overlook the Aizu basin from the castle tower. On a clear day, you can see Tsuruga Castle from the summit of Mt. Iimori, which is famous for Byakkotai.
<image>
We decided to conduct a dating survey of visitors to Tsuruga Castle to use as a reference for future public relations activities in Aizuwakamatsu City. Please create a program that inputs the age of visitors and outputs the number of people by age group below.
Category | Age
--- | ---
Under 10 years old | 0 ~ 9
Teens | 10 ~ 19
20s | 20 ~ 29
30s | 30 ~ 39
40s | 40 ~ 49
50s | 50 ~ 59
Over 60 years old | 60 ~
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format:
n
a1
a2
::
an
The first line gives the number of visitors n (1 β€ n β€ 1000000), and the following n lines give the age of the i-th visitor ai (0 β€ ai β€ 120).
Output
The number of people is output in the following format for each data set.
Line 1: Number of people under 10
Line 2: Number of teens
Line 3: Number of people in their 20s
Line 4: Number of people in their 30s
Line 5: Number of people in their 40s
Line 6: Number of people in their 50s
Line 7: Number of people over 60
Example
Input
8
71
34
65
11
41
39
6
5
4
67
81
78
65
0
Output
2
1
0
2
1
0
2
0
0
0
0
0
0
4 | instruction | 0 | 63,040 | 4 | 126,080 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
'import math'
while 1:
n=int(input())
if n==0: sys.exit()
arr=[0]*7
while n:
a=int(input())
if a>60: a=61
arr[int(a/10)]+=1
n-=1
for i in range(len(arr)):
print(arr[i])
``` | output | 1 | 63,040 | 4 | 126,081 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,560 | 4 | 127,120 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
def osn(x):
ans=[]
x7=''
while x>=7:
ans.append(x%7)
x=x//7
ans.append(x)
ans.reverse()
for k in ans:
x7+=str(k)
return x7
def it(n,m):
from itertools import permutations
ans=0
for k in permutations('0123456', len(n)+len(m)):
s=''
for l in k:
s+=l
if int(s[:len(n)])<=int(n) and int(s[len(n):])<=int(m):
ans+=1
return ans
n,m=map(int,input().split())
n,m=osn(n-1),osn(m-1)
if len(n)+len(m)>7:
print(0)
else:
print(it(n,m))
``` | output | 1 | 63,560 | 4 | 127,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,561 | 4 | 127,122 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
from itertools import permutations
def C(l):
for i in range(15):
if 7**i > l: return max(i,1)
return -1
n,m = map(int,input().split())
n -= 1
m -= 1
n1, n2 = (C(n), C(m))
if n1+n2 > 7:
print(0)
exit()
ans = 0
for i in list(permutations(list(range(0,7)), n1+n2)):
ans1, ans2 = (0, 0)
for j in range(n1):
ans1 += (7**j)*i[j]
for j in range(n1, n1+n2):
ans2 += (7**(j-n1))*i[j]
if ans1 <= n and ans2 <= m:
ans += 1
print(ans)
``` | output | 1 | 63,561 | 4 | 127,123 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,562 | 4 | 127,124 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
import sys
import math
from itertools import permutations
def convert(n):
if n == 0:
return []
return convert(n//7)+[n % 7]
n,m = list(map(int,sys.stdin.readline().split()))
x = convert(n-1)
y = convert(m-1)
nn = max(1,len(x))
mm = max(1,len(y))
ans = 0
for i in permutations("0123456",nn+mm):
a, b = "".join(i[:nn]), "".join(i[nn:])
ans += (int(a,7)<n and int(b,7)<m)
sys.stdout.write(str(ans))
``` | output | 1 | 63,562 | 4 | 127,125 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,563 | 4 | 127,126 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
def D(n):
x,r=n-1,1
while x>=7:
x//=7
r+=1
return r
def H(n,l):
x,r=n,""
if x==0:r+='0'
while x:
r+=chr(ord('0')+x%7)
x//=7
r+='0'*(l-len(r))
return r
a,b=map(int,input().split())
la=D(a)
lb=D(b)
V=[0]*99
r=0
def F(deep,wa,wb):
global r
if wa>=a or wb>=b:return
if deep==la+lb:
r+=1
return
i=-1
while i<6:
i+=1
if V[i]:continue
V[i]=1
if deep>=la:
F(deep+1,wa,wb+i*(7**(lb-1-(deep-la))))
else:
F(deep+1,wa+i*(7**(la-1-deep)),wb)
V[i]=0
if la+lb<8:F(0,0,0)
print(r)
``` | output | 1 | 63,563 | 4 | 127,127 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,564 | 4 | 127,128 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
n, m = map(int, input().split())
def l(x):
r = x == 0
while x:
r += 1
x //= 7
return r
ans, ln, lm = 0, l(n - 1), l(m - 1)
if ln + lm <= 7:
from itertools import permutations
for s in permutations('0123456', ln + lm):
s = ''.join(s)
ans += int(s[:ln], 7) < n and int(s[ln:], 7) < m
print(ans)
``` | output | 1 | 63,564 | 4 | 127,129 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,565 | 4 | 127,130 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
from itertools import permutations
def dfs(x):
r = x==0
while x :
r += 1
x //= 7
return r
n ,m = map(int,input().split())
res, ln, lm = 0, dfs(n-1), dfs(m-1)
for i in permutations('0123456', ln+lm):
i = ''.join(i)
res += int(i[:ln], 7) < n and int(i[ln:], 7) < m
print(res)
``` | output | 1 | 63,565 | 4 | 127,131 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,566 | 4 | 127,132 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
n,m=map(int,input().split())
d=[pow(7,i) for i in range(12)]
ans=0
nn,mm,kn,km=n-1,m-1,0,0
while nn: kn+=1; nn//=7
while mm: km+=1; mm//=7
kn+=kn==0
km+=km==0
nn,mm=[0]*kn,[0]*km
def hm(r1,r2,s1,s2):
global ans
if s1>=n : return
if r1==kn:
if s2>=m : return
if r2==km: ans+=1; return
for i in range(0,7):
mm[r2]=i
if i in nn: continue
if len(set(mm[:r2+1]))<r2+1: continue
hm(r1,r2+1,s1,s2+i*d[r2])
return
for i in range(0,7):
nn[r1]=i
if len(set(nn[:r1+1]))<r1+1: continue
hm(r1+1,r2,s1+i*d[r1],s2)
#if kn+km<8:
hm(0,0,0,0)
print(ans)
``` | output | 1 | 63,566 | 4 | 127,133 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1). | instruction | 0 | 63,567 | 4 | 127,134 |
Tags: brute force, combinatorics, dp, math
Correct Solution:
```
BASE = 7
class Solution(object):
def __init__(self,m,n):
self.max_hour = self.itov(n)
self.max_min = self.itov(m)
self.used = used = [False] * BASE
def itov(self,x):
digits = []
if x == 0:
digits.append(0)
while x > 0:
digits.append(x % BASE)
x //= BASE
digits.reverse()
return digits
def gen(self,pos = 0, minute = False, smaller = False):
max_val = self.max_min if minute else self.max_hour
if pos >= len(max_val):
if minute:
return 1
else:
return self.gen(0, True)
else:
ans = 0
for digit in range(BASE):
if not self.used[digit] and (smaller or digit <= max_val[pos]):
self.used[digit] = True
ans += self.gen(pos + 1, minute, smaller or digit < max_val[pos])
self.used[digit] = False
return ans
def main():
n, m = map(int, input().split())
n -= 1
m -= 1
s = Solution(m,n)
print(s.gen())
if __name__ == '__main__':
main()
``` | output | 1 | 63,567 | 4 | 127,135 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
from itertools import permutations
def findPow(num):
ans = 1
num = num // 7
while num > 0:
num //= 7
ans +=1
return ans
a, b = [int(x) for x in input().split(' ')]
x = findPow(a-1)
y = findPow(b-1)
ans = 0
if (x + y) > 7:
ans = 0
else:
for i in permutations('0123456', x+y):
s = ''.join(list(i))
p, q = int(s[:x], 7), int(s[x:], 7)
if p <= a-1 and q <= b-1:
ans+=1
print(ans)
``` | instruction | 0 | 63,568 | 4 | 127,136 |
Yes | output | 1 | 63,568 | 4 | 127,137 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
import math
n, m = map(int, input().split())
def toBase7D(x):
base = 1
digits = 1
while base*7 - 1 < x:
base *= 7
digits += 1
return digits
def toBase7(x):
base = 1
number = ""
while base*7 - 1 < x:
base *= 7
while base != 0:
d = math.floor(x / base)
number += str(d)
x -= d * base
base = math.floor(base / 7)
return number
def checkDigits(a, b):
digits = []
for d in a:
if d in digits:
return False
else:
digits.append(d)
for d in b:
if d in digits:
return False
else:
digits.append(d)
return True
def substract(x, digits):
xx = int(x)
xx -= 1
if xx < 0:
return False
x = str(xx)
newX = ""
for d in x:
if d == '7' or d == '8' or d == '9':
newX += "6"
else:
newX += d
if digits - len(newX) >= 2:
return False
elif digits - len(newX) == 1:
newX = "0" + newX
return newX
def check(n, nDigits, m, mDigits):
nn = toBase7(n-1)
mm2 = toBase7(m-1)
total = 0
while True:
mm = mm2
if checkDigits(nn, []):
while True:
if checkDigits(nn,mm):
#print(nn + ":" + mm)
total += 1
mm = substract(mm, mDigits)
if not mm:
break
nn = substract(nn, nDigits)
if not nn:
break
print(total)
nDigits = toBase7D(n-1)
mDigits = toBase7D(m-1)
if nDigits + mDigits > 7:
print(0)
exit()
else:
if nDigits < mDigits:
check(m, mDigits, n, nDigits)
else:
check(n, nDigits, m, mDigits)
'''
if nDigits > 1:
if mDigits > 1:
check(n, nDigits, m, mDigits - 1)
else:
check(n, nDigits, m, mDigits)
else:
if mDigits > 1:
check(n, nDigits, m, mDigits - 1)
else:
check(n, nDigits, m, mDigits)
'''
``` | instruction | 0 | 63,569 | 4 | 127,138 |
Yes | output | 1 | 63,569 | 4 | 127,139 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
from itertools import permutations
from math import ceil, log
n, m = t = list(map(int, input().split()))
l, _ = t = [ceil(log(x, 7.)) if x > 1 else 1 for x in t]
print(sum(int(s[:l], 7) < n and int(s[l:], 7) < m for s in map(''.join, permutations("0123456", sum(t)))))
``` | instruction | 0 | 63,570 | 4 | 127,140 |
Yes | output | 1 | 63,570 | 4 | 127,141 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
n, m = map(int, input().split())
def GetDigitsNumberIn7System(number):
result = 1
x = 7
while (True):
if (number <= x - 1):
return result
else:
result += 1
x *= 7
def fillZeros(s, razryadCount):
for i in range(razryadCount - len(s)):
s = "0" + s
return s
def HasTheSameDigits(s):
digits = set()
for letter in s:
digits.add(letter)
if len(digits) == len(s):
return False
else:
return True
def int2base(x, base):
if x < 0:
sign = -1
elif x == 0:
return '0'
else:
sign = 1
x *= sign
res = ''
while x != 0:
res += str(x % base)
x //= base
return res[::-1]
def GetNumberOfVariations(hoursInDay, minutesInHour):
n1 = GetDigitsNumberIn7System(hoursInDay-1)
n2 = GetDigitsNumberIn7System(minutesInHour-1)
count = 0
listHours = []
listMinutes = []
for i in range(hoursInDay):
if (HasTheSameDigits(fillZeros(int2base(i,7),n1)) == False):
listHours.append(i)
for i in range(minutesInHour):
if (HasTheSameDigits(fillZeros(int2base(i, 7), n2)) == False):
listMinutes.append(i)
for i in listHours:
for j in listMinutes:
str1 = fillZeros(int2base(i,7),n1)
str2 = fillZeros(int2base(j,7),n2)
strc = str1+str2
if (HasTheSameDigits(strc) == False):
count+=1
return count
r1 = GetDigitsNumberIn7System(n-1)
r2 = GetDigitsNumberIn7System(m-1)
if r1 + r2 > 7:
print(0)
else:
res = GetNumberOfVariations(n,m)
print (res)
``` | instruction | 0 | 63,571 | 4 | 127,142 |
Yes | output | 1 | 63,571 | 4 | 127,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
from itertools import permutations
def getdigits(x):
if x==0:
return 1
digs=0
while x!=0:
x//=7
digs+=1
return digs
n,m=map(int,input().split())
a,b=(getdigits(n),getdigits(m))
c=a+b
if c>7:
print(0)
exit(0)
combs=permutations(range(7),c)
ans=0
for comb in combs:
d=comb[:a]
e=comb[a:]
f=""
g=""
for i in d:
f+=str(i)
for i in e:
g+=str(i)
x=int(f,7)
y=int(g,7)
if x<n and y<m:
ans+=1
print(ans)
``` | instruction | 0 | 63,572 | 4 | 127,144 |
No | output | 1 | 63,572 | 4 | 127,145 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
from itertools import *
from math import *
n, m = map(int, input().split())
x = ceil(log(m,7))
y = ceil(log(n,7))
ms = dict()
# print(x,y)
def conv(s):
s = s[::-1]
j = 0
num = 0
for i in s:
num += int(i)*7**j
j+=1
# print(num)
return num
if x+y > 7:
print(0)
else:
s = '0123456'
ans = 0
for i in permutations(s,x+y):
# print(i)
a = i[:y]
b = i[y:x+y]
# print(a,b)
if conv(a)<n and conv(b)<m:
# print(conv(a),conv(b),i)
ans +=1
print(ans)
``` | instruction | 0 | 63,573 | 4 | 127,146 |
No | output | 1 | 63,573 | 4 | 127,147 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
from itertools import *
from math import *
n, m = map(int, input().split())
x = ceil(log(m,7))
y = ceil(log(n,7))
ms = dict()
# print(x,y)
def conv(s):
s = s[::-1]
j = 0
num = 0
for i in s:
num += int(i)*7**j
j+=1
# print(num)
return num
if x+y > 7:
print(0)
else:
s = '0123456'
ans = 0
for i in permutations(s,x+y):
# print(i)
a = i[:y]
b = i[y:x+y]
# print(a,b)
if len(i) == 0:
continue
if conv(a)<n and conv(b)<m:
# print(conv(a),conv(b),i)
ans +=1
print(ans)
``` | instruction | 0 | 63,574 | 4 | 127,148 |
No | output | 1 | 63,574 | 4 | 127,149 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.
First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.
Note that to display number 0 section of the watches is required to have at least one place.
Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
Input
The first line of the input contains two integers, given in the decimal notation, n and m (1 β€ n, m β€ 109) β the number of hours in one day and the number of minutes in one hour, respectively.
Output
Print one integer in decimal notation β the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
Examples
Input
2 3
Output
4
Input
8 2
Output
5
Note
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).
In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
Submitted Solution:
```
from itertools import permutations as P
n, m = map(int, input().split())
a = n-1
b = m-1
x = 0
y = 0
c = 0
while a:
x += 1
a = a//7
while b:
y += 1
b = b//7
if x+y > 7:
print(0)
else:
r = x+y
l = list(P('0123456', r))
for ele in l:
a = 0
b = 0
for i in range(x):
a += int(ele[i])*(7**(x-i-1))
for i in range(x, r):
b += int(ele[i])*(7**(r-i-1))
if a < n and b < m:
c += 1
#print(a, b, end = ' ')
#print()
print(c)
``` | instruction | 0 | 63,575 | 4 | 127,150 |
No | output | 1 | 63,575 | 4 | 127,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,720 | 4 | 127,440 |
Tags: constructive algorithms, strings
Correct Solution:
```
n, p = map(int, input().split())
a = input()
b = list(a)
for i in range(p):
j = i
c = a[j]
if j + p < n and a[j] == '.':
c = a[j + p]
if c == '.':
c = '0'
cnt = 0
for j in range(i, n, p):
if a[j] == '.':
if cnt % 2 == 0:
if c == '0':
b[j] = '1'
else:
b[j] = '0'
else:
b[j] = c
cnt += 1
ok = 0
for i in range(p, n):
if b[i] != b[i-p]:
ok = 1
if ok == 1:
print(''.join(b))
else:
print("No")
``` | output | 1 | 63,720 | 4 | 127,441 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,721 | 4 | 127,442 |
Tags: constructive algorithms, strings
Correct Solution:
```
n,m=map(int,input().split())
s=list(input())
l=len(s)
f=False
for i in range(l-m):
if not((s[i]==s[i+m]) and ((s[i]!=".") and (s[i+m]!="."))):
f=True
if s[i]==".":
if s[i+m]=="1":
s[i]="0"
else:
s[i]="1"
if s[i+m]==".":
if s[i]=="0":
s[i+m]="1"
else:
s[i+m]="0"
if f==False:
print("No")
quit()
for i in range(len(s)):
if s[i]=='.':
s[i]='0'
print("".join(s))
``` | output | 1 | 63,721 | 4 | 127,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,722 | 4 | 127,444 |
Tags: constructive algorithms, strings
Correct Solution:
```
n, p = map(int, input().split(' '))
s = input()
res = True
def op(c):
return '1' if c == '0' else '0'
def out(s):
print(s.replace('.', '0'))
exit(0)
for i in range(n - p):
j = i + p
if s[i] == s[j] == '.':
out(s[0:i] + '1' + s[i+1:j] + '0' + s[j+1:])
if s[i] == '.':
out(s[0:i] + op(s[j]) + s[i+1:])
if s[j] == '.':
out(s[0:j] + op(s[i]) + s[j+1:])
if s[i] != s[j]:
out(s)
print('No')
``` | output | 1 | 63,722 | 4 | 127,445 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,723 | 4 | 127,446 |
Tags: constructive algorithms, strings
Correct Solution:
```
a, p = map(int,input().split())
s = list(input())
n = len(s)
d = []
stop = 0
#print(s)
for i in range(p):
d = []
count = 0
for j in range(i,n,p):
d.append(s[j])
#print(d)
if count == 0:
count = s[j]
count_index = j;
elif count != s[j]:
#print("ΠΠ΅ΡΠΎΠ²ΠΏΠ°Π΄Π΅Π½ΠΈΠ΅", j)
stop = 1
if count == "." and s[j] == "1":
s[count_index] = "0"
elif count == "." and s[j] == "0":
s[count_index] = "1"
elif count == "1" and s[j] == ".":
s[j] = "0"
elif count == "0" and s[j] == ".":
s[j] = "1"
elif count == s[j] and count == '.':
s[count_index] = "0"
s[j] = "1"
stop = 1
if stop == 1:
#print(s)
for i in s:
if i == '.':
print(0,end='')
else:
print(i,end='')
break
if stop == 0:
print('No')
``` | output | 1 | 63,723 | 4 | 127,447 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,724 | 4 | 127,448 |
Tags: constructive algorithms, strings
Correct Solution:
```
n,p=list(map(int,input().split()))
s=list(input())
f=1
for i in range(n-p):
if s[i]=='.':
if s[i+p]=='.':
s[i]='1'
s[i+p]='0'
else:
s[i]='0' if s[i+p]=='1' else '1'
else:
if s[i+p]=='.':
s[i+p]='0' if s[i]=='1' else '1'
for i in range(n):
if s[i]=='.':
s[i]='1'
for i in range(n-p):
if s[i+p]!=s[i]:
f=0
break
if f:
print('No')
else:
print(''.join(s))
``` | output | 1 | 63,724 | 4 | 127,449 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,725 | 4 | 127,450 |
Tags: constructive algorithms, strings
Correct Solution:
```
str1 = list(map(int,input().split()))
n = str1[0]
p = str1[1]
s = input()
cor = dict()
flag = False
for i in range(n - p):
if s[i] != '.' and s[i+p] != '.':
if s[i] == s[i+p]:
continue
else:
flag = True
break
elif s[i] == '.' and s[i+p] != '.':
cor[i] = str(((int)(s[i+p]) + 1) % 2)
flag = True
break
elif s[i] != '.' and s[i+p] == '.':
cor[i+p] = str(((int)(s[i]) + 1) % 2)
flag = True
break
elif s[i] == '.' and s[i+p] == '.':
cor[i] = '0'
cor[i+p] = '1'
flag = True
break
ans = []
if flag:
for i in range(n):
if s[i] != '.':
ans.append(s[i])
elif cor.get(i,'-1') != '-1':
ans.append(cor.get(i))
else:
ans.append('0')
print (''.join(ans))
else:
print ('No')
``` | output | 1 | 63,725 | 4 | 127,451 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,726 | 4 | 127,452 |
Tags: constructive algorithms, strings
Correct Solution:
```
n, p = map(int, input().split())
s = input()
for i in range(p, n):
x, y = s[i % p], s[i]
if x == y != '.':
continue
if x == y == '.':
s = (s[:i] + '0' + s[i + 1:]).replace('.', '1')
elif '1' in [x, y]:
s = s.replace('.', '0')
else:
s = s.replace('.', '1')
print(s)
exit()
print('NO')
``` | output | 1 | 63,726 | 4 | 127,453 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them. | instruction | 0 | 63,727 | 4 | 127,454 |
Tags: constructive algorithms, strings
Correct Solution:
```
n, p = map(int, input().split())
u = list(input())
def loop(k):
global u
for i in range(k, p + k):
if i + p < n:
if u[i] == '.':
if u[i + p] == '.':
u[i] = '0'
u[i + p] = '1'
elif u[i + p] == '0':
u[i] = '1'
else:
u[i] = '0'
return True
elif u[i + p] == '.':
if u[i] == '.':
u[i] = '0'
u[i + p] = '1'
elif u[i] == '0':
u[i + p] = '1'
else:
u[i + p] = '0'
return True
else:
if u[i] != u[i + p]:
return True
return False
ok = False
for i in range(n // p):
ok = loop(i * p)
if ok:
break
if not ok:
import sys
print('No')
sys.exit()
for i in u:
if i == '.':
print(0, end = '')
else:
print(i, end = '')
``` | output | 1 | 63,727 | 4 | 127,455 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
Submitted Solution:
```
def print_result(s):
for i in range(0, len(s)):
if s[i] == '.':
s[i] = 0
print(''.join(map(str, s)))
def solution(n, p, s):
for i in range(0, len(s) - p):
if s[i] == '0':
if s[i + p] != '0':
if s[i + p] == '.':
s[i + p] = '1'
print_result(s)
return
elif s[i] == '1':
if s[i + p] != '1':
if s[i + p] == '.':
s[i + p] = '0'
print_result(s)
return
else:
if s[i + p] == '1':
s[i] = '0'
elif s[i + p] == '0':
s[i] = '1'
else:
s[i] = '0'
s[i + p] = '1'
print_result(s)
return
print('No')
return
n, p = input().split()
n = int(n)
p = int(p)
s = list(input())
solution(n, p, s)
``` | instruction | 0 | 63,728 | 4 | 127,456 |
Yes | output | 1 | 63,728 | 4 | 127,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
Submitted Solution:
```
n, p = map(int, input().split())
s = input()
flag = -1
for i in range(p, n, p):
if i + p < n:
s1 = s[i-p:i]
s2 = s[i:i+p]
else:
s1 = s[i-p:n-p]
s2 = s[i:n]
if '.' in s1:
index = s1.find('.')
if s2[index] != '.':
flag = 1
else:
flag = 2
index += i - p
break
elif '.' in s2:
index = s2.find('.')
index += i
flag = 3
break
elif s1 != s2:
flag = 0
break
if flag == -1:
print('No')
elif flag == 0:
print(s.replace('.', '0'))
elif flag == 1:
s = s[:index] + str(1 - int(s[index+p])) + s[index+1:]
print(s.replace('.', '0'))
elif flag == 2:
s = s[:index] + '1' + s[index+1:index+p] + '0' + s[index+p+1:]
print(s.replace('.', '0'))
elif flag == 3:
s = s[:index] + str(1 - int(s[index-p])) + s[index+1:]
print(s.replace('.', '0'))
``` | instruction | 0 | 63,729 | 4 | 127,458 |
Yes | output | 1 | 63,729 | 4 | 127,459 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Walking along a riverside, Mino silently takes a note of something.
"Time," Mino thinks aloud.
"What?"
"Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this."
"And what are you recording?"
"You see it, tide. Everything has its own period, and I think I've figured out this one," says Mino with confidence.
Doubtfully, Kanno peeks at Mino's records.
The records are expressed as a string s of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low).
You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer p is not a period of the resulting string. In case the answer is yes, please also show such a replacement to Mino.
In this problem, a positive integer p is considered a period of string s, if for all 1 β€ i β€ \lvert s \rvert - p, the i-th and (i + p)-th characters of s are the same. Here \lvert s \rvert is the length of s.
Input
The first line contains two space-separated integers n and p (1 β€ p β€ n β€ 2000) β the length of the given string and the supposed period, respectively.
The second line contains a string s of n characters β Mino's records. s only contains characters '0', '1' and '.', and contains at least one '.' character.
Output
Output one line β if it's possible that p is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
Examples
Input
10 7
1.0.1.0.1.
Output
1000100010
Input
10 6
1.0.1.1000
Output
1001101000
Input
10 9
1........1
Output
No
Note
In the first example, 7 is not a period of the resulting string because the 1-st and 8-th characters of it are different.
In the second example, 6 is not a period of the resulting string because the 4-th and 10-th characters of it are different.
In the third example, 9 is always a period because the only constraint that the first and last characters are the same is already satisfied.
Note that there are multiple acceptable answers for the first two examples, you can print any of them.
Submitted Solution:
```
n, p = map(int, input().split())
s = input()
x = []
for j in s:
x.append(j)
ind = False
for i in range(n):
if i + p < n:
if not ind and x[i + p] == ".":
if x[i] != ".":
x[i + p] = 1 - int(x[i])
else:
x[i] = 0
x[i + p] = 1
ind = True
elif not ind and x[i] == ".":
x[i] = 1 - int(x[i + p])
ind = True
elif not ind and x[i] != x[i + p]:
ind = True
elif ind:
if x[i] == ".":
x[i] = 0
elif x[i] == ".":
x[i] = 0
if ind:
for j in range(n):
print(x[j], end = "")
else:
print("No")
``` | instruction | 0 | 63,730 | 4 | 127,460 |
Yes | output | 1 | 63,730 | 4 | 127,461 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.