message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp is an introvert person. In fact he is so much of an introvert that he plays "Monsters and Potions" board game alone. The board of the game is a row of n cells. The cells are numbered from 1 to n from left to right. There are three types of cells: a cell containing a single monster, a cell containing a single potion or a blank cell (it contains neither a monster nor a potion).
Polycarp has m tokens representing heroes fighting monsters, which are initially located in the blank cells s_1, s_2, ..., s_m. Polycarp's task is to choose a single cell (rally point) and one by one move all the heroes into this cell. A rally point can be a cell of any of three types.
After Policarp selects a rally point, he picks a hero and orders him to move directly to the point. Once that hero reaches the point, Polycarp picks another hero and orders him also to go to the point. And so forth, until all the heroes reach the rally point cell. While going to the point, a hero can not deviate from the direct route or take a step back. A hero just moves cell by cell in the direction of the point until he reaches it. It is possible that multiple heroes are simultaneously in the same cell.
Initially the i-th hero has h_i hit points (HP). Monsters also have HP, different monsters might have different HP. And potions also have HP, different potions might have different HP.
If a hero steps into a cell which is blank (i.e. doesn't contain a monster/potion), hero's HP does not change.
If a hero steps into a cell containing a monster, then the hero and the monster fight. If monster's HP is strictly higher than hero's HP, then the monster wins and Polycarp loses the whole game. If hero's HP is greater or equal to monster's HP, then the hero wins and monster's HP is subtracted from hero's HP. I.e. the hero survives if his HP drops to zero, but dies (and Polycarp looses) if his HP becomes negative due to a fight. If a hero wins a fight with a monster, then the monster disappears, and the cell becomes blank.
If a hero steps into a cell containing a potion, then the hero drinks the potion immediately. As a result, potion's HP is added to hero's HP, the potion disappears, and the cell becomes blank.
Obviously, Polycarp wants to win the game. It means that he must choose such rally point and the order in which heroes move, that every hero reaches the rally point and survives. I.e. Polycarp loses if a hero reaches rally point but is killed by a monster at the same time. Polycarp can use any of n cells as a rally point β initially it can contain a monster, a potion, or be a blank cell with or without a hero in it.
Help Polycarp write a program to choose a rally point and the order in which heroes move.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100; 1 β€ m β€ n) β length of the game board and the number of heroes on it.
The following m lines describe heroes. Each line contains two integers s_i and h_i (1 β€ s_i β€ n; 1 β€ h_i β€ 10^6), where s_i is the initial position and h_i is the initial HP of the i-th hero. It is guaranteed that each cell s_i is blank. It is also guaranteed that all s_i are different.
The following line contains n integers a_1, a_2, ..., a_n (-10^6 β€ a_j β€ 10^6), where a_j describes the i-th cell of the game board:
* a_j=0 means that the i-th cell is blank,
* a_j<0 means that the i-th cell contains monster with positive HP of -a_j,
* a_j>0 means that the i-th cell contains potion with a_j HP.
Output
On the first line of the output print the index of the rally point cell.
On the second line print m integers β the order in which heroes should move to the rally point. Heroes are numbered from 1 to m in the order they are given in the input.
If there are multiple solutions, print any of them.
If it is impossible to find a rally point which can be reached by all heroes, print a single integer -1 in the output.
Examples
Input
8 3
8 2
1 3
4 9
0 3 -5 0 -5 -4 -1 0
Output
6
3 1 2
Input
1 1
1 1
0
Output
1
1
Input
3 2
1 1
3 1
0 -5000 0
Output
-1
Input
8 3
1 15
5 10
8 1
0 -5 -5 -5 0 -5 -5 0
Output
7
2 1 3
Note
The picture illustrates the first example:
<image> | instruction | 0 | 16,861 | 24 | 33,722 |
Tags: brute force, dp, greedy, implementation
Correct Solution:
```
#!/usr/bin/env python3
import collections
import sys
import traceback
class Input(object):
def __init__(self):
self.fh = sys.stdin
def next_line(self):
while True:
line = sys.stdin.readline()
if line == '\n':
continue
return line
def next_line_ints(self):
line = self.next_line()
return [int(x) for x in line.split()]
def next_line_strs(self):
line = self.next_line()
return line.split()
class Hero(object):
def __init__(self, id, hp):
self.id = id
self.hp = hp
class Room(object):
def __init__(self, value):
self.heros = []
self.value = value
def get_orders(cells, heros):
n = len(cells)
rooms = [Room(cell) for cell in cells]
for i in range(len(heros)):
pos = heros[i][0] - 1
hp = heros[i][1]
rooms[pos].heros.append(Hero(i, hp))
for room in rooms:
room.heros.sort(key=lambda hero: hero.hp, reverse=True)
left_best_heros = [-1] * n
left_reach = 0
while left_reach < n and not rooms[left_reach].heros:
left_reach += 1
best_hero = None
while left_reach < n:
if rooms[left_reach].heros:
hero = rooms[left_reach].heros[0]
if best_hero is None or hero.hp > best_hero.hp:
best_hero = hero
elif best_hero and best_hero.hp + rooms[left_reach].value >= 0:
best_hero.hp += rooms[left_reach].value
else:
break
left_best_heros[left_reach] = best_hero.id
left_reach += 1
right_best_heros = [-1] * n
right_reach = n - 1
while right_reach > -1 and not rooms[right_reach].heros:
right_reach -= 1
best_hero = None
while right_reach > -1:
if rooms[right_reach].heros:
hero = rooms[right_reach].heros[0]
if best_hero is None or hero.hp > best_hero.hp:
best_hero = hero
elif best_hero and best_hero.hp + rooms[right_reach].value >= 0:
best_hero.hp += rooms[right_reach].value
else:
break
right_best_heros[right_reach] = best_hero.id
right_reach -= 1
#print('left_reach {}, right_reach {}'.format(left_reach, right_reach))
if right_reach + 1 > left_reach:
return None, []
rally_point = left_reach - 1
visited = [False for _ in heros]
order = []
def put_id(id):
if id != -1 and not visited[id]:
order.append(id + 1)
visited[id] = True
for i in range(rally_point, -1, -1):
put_id(left_best_heros[i])
for hero in rooms[i].heros:
put_id(hero.id)
for i in range(rally_point + 1, n):
put_id(right_best_heros[i])
for hero in rooms[i].heros:
put_id(hero.id)
return rally_point + 1, order
def main():
input = Input()
while True:
try:
nums = input.next_line_ints()
if not nums:
break
n, m = nums
if n == -1:
break
heros = []
for _ in range(m):
heros.append(input.next_line_ints())
cells = input.next_line_ints()
except:
print('read input failed')
try:
rally, order = get_orders(cells, heros)
if rally is None:
print("-1")
else:
print("{}".format(rally))
print(" ".join([str(x) for x in order]))
except:
traceback.print_exc(file=sys.stdout)
print('get_min_dist failed')
main()
``` | output | 1 | 16,861 | 24 | 33,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,931 | 24 | 35,862 |
Tags: *special, brute force, implementation
Correct Solution:
```
n=int(input())
m=[]
for i in range(n):
x=input()
m.append(x)
t=0
c=0
for i in range(len(m[0])):
t=m[0][i]
for j in range(1,len(m)):
if m[j][i] != t:
c=i
print(c)
exit()
``` | output | 1 | 17,931 | 24 | 35,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,932 | 24 | 35,864 |
Tags: *special, brute force, implementation
Correct Solution:
```
n = int(input())
phones = []
for i in range(n):
phones.append(input())
m = len(phones[0])
count = 0
flag = False
for j in range(m):
compare = phones[0][j]
for i in range(n):
if compare != phones[i][j]:
flag = True
if flag:
break
else:
count+=1
print(count)
``` | output | 1 | 17,932 | 24 | 35,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,933 | 24 | 35,866 |
Tags: *special, brute force, implementation
Correct Solution:
```
n=int(input())
number=input()
for i in range(n-1):
li=[]
new=input()
for j in range(len(number)):
if new[j]==number[j]:
li.append(number[j])
if new[j]!=number[j]:
break
number=''.join(li)
print(len(number))
``` | output | 1 | 17,933 | 24 | 35,867 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,934 | 24 | 35,868 |
Tags: *special, brute force, implementation
Correct Solution:
```
garbage = int(input())
result = ""
all_numbers = [input() for _ in range(garbage)]
first_number = all_numbers[0]
for i in range(len(all_numbers[0])):
ch = True
for j in range(garbage):
if all_numbers[j][i] != first_number[i]:
ch = False
break
if ch == True:
result = result + first_number[i]
if ch == False:
break
print(len(result))
``` | output | 1 | 17,934 | 24 | 35,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,935 | 24 | 35,870 |
Tags: *special, brute force, implementation
Correct Solution:
```
n=int(input())
l=[]
for i in range(n):
l.append(input())
l1=[]
for i in range(len(l)-1):
for j in range(len(l[-1])):
if l[i][j]!=l[i+1][j]:
l1.append(j)
print(min(l1))
``` | output | 1 | 17,935 | 24 | 35,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,936 | 24 | 35,872 |
Tags: *special, brute force, implementation
Correct Solution:
```
''' Design by Dinh Viet Anh(JOKER)
//_____________________________________$$$$$__
//___________________________________$$$$$$$$$
//___________________________________$$$___$
//___________________________$$$____$$$$
//_________________________$$$$$$$__$$$$$$$$$$$
//_______________________$$$$$$$$$___$$$$$$$$$$$
//_______________________$$$___$______$$$$$$$$$$
//________________$$$$__$$$$_________________$$$
//_____________$__$$$$__$$$$$$$$$$$_____$____$$$
//__________$$$___$$$$___$$$$$$$$$$$__$$$$__$$$$
//_________$$$$___$$$$$___$$$$$$$$$$__$$$$$$$$$
//____$____$$$_____$$$$__________$$$___$$$$$$$
//__$$$$__$$$$_____$$$$_____$____$$$_____$
//__$$$$__$$$_______$$$$__$$$$$$$$$$
//___$$$$$$$$$______$$$$__$$$$$$$$$
//___$$$$$$$$$$_____$$$$___$$$$$$
//___$$$$$$$$$$$_____$$$
//____$$$$$$$$$$$____$$$$
//____$$$$$__$$$$$___$$$
//____$$$$$___$$$$$$
//____$$$$$____$$$
//_____$$$$
//_____$$$$
//_____$$$$
'''
from math import *
from cmath import *
from itertools import *
from decimal import * # su dung voi so thuc
from fractions import * # su dung voi phan so
from sys import *
from types import new_class
#from numpy import *
'''getcontext().prec = x # lay x-1 chu so sau giay phay (thuoc decimal)
Decimal('12.3') la 12.3 nhung Decimal(12.3) la 12.30000000012
Fraction(a) # tra ra phan so bang a (Fraction('1.23') la 123/100 Fraction(1.23) la so khac (thuoc Fraction)
a = complex(c, d) a = c + d(i) (c = a.real, d = a.imag)
a.capitalize() bien ki tu dau cua a(string) thanh chu hoa, a.lower() bien a thanh chu thuong, tuong tu voi a.upper()
a.swapcase() doi nguoc hoa thuong, a.title() bien chu hoa sau dau cach, a.replace('a', 'b', slg)
chr(i) ki tu ma i ord(c) ma ki tu c
a.join['a', 'b', 'c'] = 'a'a'b'a'c, a.strip('a') bo dau va cuoi ki tu 'a'(rstrip, lstrip)
a.split('a', slg = -1) cat theo ki tu 'a' slg lan(rsplit(), lsplit()), a.count('aa', dau = 0, cuoi= len(a)) dem slg
a.startswith('a', dau = 0, cuoi = len(a)) co bat dau bang 'a' ko(tuong tu endswith())
a.index("aa") vi tri dau tien xuat hien (rfind())
input = open(".inp", mode='r') a = input.readline()
out = open(".out", mode='w') a.index(val) '''
#inn = open(".inp", "r")
n = int(input())
s = []
for x in range(n):
s.append(input())
l = 0
r = len(s[0])
def check(x):
for _ in range(1, n):
if s[_][:x] != s[0][:x]:
return 0
return 1
while l < r-1:
mid = (l+r)//2
if check(mid):
l = mid
else: r = mid
if check(r):
print(r)
else:
print(l)
``` | output | 1 | 17,936 | 24 | 35,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,937 | 24 | 35,874 |
Tags: *special, brute force, implementation
Correct Solution:
```
n = int(input())
p = input()
for x in range(1, n):
t = input()
if p != t[: len(p)]:
j = 0
while p[j] == t[j]: j += 1
p = p[: j]
print(len(p))
``` | output | 1 | 17,937 | 24 | 35,875 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789". | instruction | 0 | 17,938 | 24 | 35,876 |
Tags: *special, brute force, implementation
Correct Solution:
```
n = int(input())
fl = False
numbers = []
for i in range(n):
numbers.append(input())
first_symbol = ''
for j in range(len(numbers[0])):
if fl: break
first_symbol += numbers[0][j]
for i in range(1,n):
if numbers[i][0:j+1] != first_symbol:
print(len(first_symbol)-1)
fl = True
break
``` | output | 1 | 17,938 | 24 | 35,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
n=int(input())
a=[]
for i in range(n):
a.append(input())
s=''
k=a[0]
j=0
r=0
for i in k:
for ii in a:
if ii[j]==k[j]:
pass
else:
r=1
break
else:
s=s+k[j]
if r==1:
break
j=j+1
print(len(s))
``` | instruction | 0 | 17,939 | 24 | 35,878 |
Yes | output | 1 | 17,939 | 24 | 35,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
n = int(input())
x = []
for i in range(n):
l =input()
x.append(l)
res = ''
prefix = x[0]
for string in x[1:]:
while string[:len(prefix)] != prefix and prefix:
prefix = prefix[:len(prefix) - 1]
if not prefix:
break
res = prefix
print(len(str(res)))
``` | instruction | 0 | 17,940 | 24 | 35,880 |
Yes | output | 1 | 17,940 | 24 | 35,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
n = int(input())
max_prefix = input()
j = len(max_prefix)
for i in range(1, n):
s = input()
k = 0
while s[k] == max_prefix[k] and k < j:
k += 1
j = k
print(k)
``` | instruction | 0 | 17,941 | 24 | 35,882 |
Yes | output | 1 | 17,941 | 24 | 35,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
n=I()
l=[S() for _ in range(n)]
for i in range(len(l[0])):
x=l[0][i]
for j in range(n):
if l[j][i]!=x:
return i
return n
# main()
print(main())
``` | instruction | 0 | 17,942 | 24 | 35,884 |
Yes | output | 1 | 17,942 | 24 | 35,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
x=int(input())
l=[]
for i in range(x):
l=l+[input()]
c=l[0]
m=1
k=[]
for i in range(1,len(l)):
while c[:m] in l[i]:
m=m+1
k=k+[c[:m-1]]
m=1
k.sort()
print(len(k[0]))
``` | instruction | 0 | 17,943 | 24 | 35,886 |
No | output | 1 | 17,943 | 24 | 35,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
n = int(input())
s = []
e = []
f = ""
for x in range(n):
s.append(input())
for x in range(1,len(s[0])):
for y in s[1:]:
if s[0][:x] in y:
e.append(s[0][:x])
e.reverse()
for x in e:
if e.count(x) == n - 1:
f = str(x)
break
print(len(f))
``` | instruction | 0 | 17,944 | 24 | 35,888 |
No | output | 1 | 17,944 | 24 | 35,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
lst=[]
for i in range(int(input())):
lst.append(input())
ans=0
for j in range(len(lst[0])):
for k in range(j+1,len(lst[0])+1):
c=0
for l in lst:
if lst[0][j:k] in l and lst[0][j:k][0]==lst[0][0]:
c+=1
if c==len(lst) and len(lst[0][j:k])>ans:
ans=len(lst[0][j:k])
print(ans)
``` | instruction | 0 | 17,945 | 24 | 35,890 |
No | output | 1 | 17,945 | 24 | 35,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length.
Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string c which is a prefix (the beginning) of each si for all i (1 β€ i β€ n). Help Polycarpus determine the length of the city phone code.
Input
The first line of the input contains an integer n (2 β€ n β€ 3Β·104) β the number of Polycarpus's friends. The following n lines contain strings s1, s2, ..., sn β the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different.
Output
Print the number of digits in the city phone code.
Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
Note
A prefix of string t is a string that is obtained by deleting zero or more digits from the end of string t. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209".
In the first sample the city phone code is string "00".
In the second sample the city phone code is an empty string.
In the third sample the city phone code is string "770123456789".
Submitted Solution:
```
num = int(input())
arr, arr2 = ([], [])
i = 0
nums = input()
for x in range(num - 1):
nums = input()
while len(arr) < len(nums):
arr.append(set())
for y in range(len(nums)):
arr[y].add(nums[y])
y = 0
for z in range(len(arr)):
if len(arr[z]) == 1 and i == z:
arr2.append(arr[z])
i += 1
if len(nums) > 1:
print(len(arr2))
else:
print(0)
``` | instruction | 0 | 17,946 | 24 | 35,892 |
No | output | 1 | 17,946 | 24 | 35,893 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,485 | 24 | 38,970 |
Tags: math, number theory
Correct Solution:
```
l=list(map(int,input().split()))
n=l[0]
k=l[1]
l=[]
b=[]
for i in range (k):
b.append(int(0))
l=list(map(int,input().split()))
for i in l:
b[i%k]+=1
sum=b[0]-b[0]%2
for i in range (1,(k+1)//2):
sum+=(min(b[i],b[k-i])*2)
if(k%2==0):
sum+=b[k//2]-b[k//2]%2
print (sum)
``` | output | 1 | 19,485 | 24 | 38,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,486 | 24 | 38,972 |
Tags: math, number theory
Correct Solution:
```
num = [0 for i in range(104)]
numBoxes, girls = input().split()
numBoxes = int(numBoxes)
girls = int(girls)
caixas = map(int, input().split())
for e in caixas:
num[e%girls]+=1
qtdCaixas = 0
for i in range(1, girls):
if i==girls-i:
qtdCaixas += min(num[i], num[girls-i])//2*2
else:
qtdCaixas += min(num[i], num[girls-i])
print(qtdCaixas+num[0]//2*2)
``` | output | 1 | 19,486 | 24 | 38,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,487 | 24 | 38,974 |
Tags: math, number theory
Correct Solution:
```
def womens_day_problem():
n, k = input().split(' ')
n, k = int(n), int(k)
b = input().split(' ')
for i, _ in enumerate(b):
b[i] = int(b[i])
a = []
for i in range(k+1):
a.append(0)
for i in range(n):
a[b[i] % k] += 1
cnt = a[0] // 2
if k % 2 == 0:
cnt += a[k//2] // 2
for i in range((k+1)//2):
tmp = min(a[i], a[k-i])
cnt += tmp
a[i] -= tmp
a[k-i] -= tmp
print(2 * cnt)
return
if __name__ == '__main__':
womens_day_problem()
``` | output | 1 | 19,487 | 24 | 38,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,488 | 24 | 38,976 |
Tags: math, number theory
Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N,K=MAP()
A=LIST()
C=Counter()
for i in range(N):
C[A[i]%K]+=1
ans=C[0]//2
del C[0]
if K%2==0:
ans+=C[K//2]//2
del C[K//2]
for k in sorted(C.keys()):
if k>K//2:
break
ans+=min(C[k], C[K-k])
print(ans*2)
``` | output | 1 | 19,488 | 24 | 38,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,489 | 24 | 38,978 |
Tags: math, number theory
Correct Solution:
```
from collections import defaultdict
def main():
d = defaultdict(int)
n,k = map(int, input().split())
arr = list(map(int , input().split()))
for ele in arr:
d[ele%k] += 1
m = 0
for key in list(d.keys()):
if key == 0:
if d[key] %2 == 0:
m += d[key]
else:
m += d[key] -1
elif k-key == key:
if d[key]%2 == 0:
m += d[key]
else:
m += d[key] -1
else:
l = min(d[key], d[k-key])
m += 2*l
d[key] -= l
d[k-key] -= l
print(m)
main()
``` | output | 1 | 19,489 | 24 | 38,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,490 | 24 | 38,980 |
Tags: math, number theory
Correct Solution:
```
'''input
7 3
1 2 2 3 2 4 5
'''
import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
import heapq
mod=10**9+7
def ri(flag=0):
if flag==0:
return [int(i) for i in sys.stdin.readline().split()]
else:
return int(sys.stdin.readline())
n,k=ri()
a=ri()
take=[0 for i in range(105)]
nee=[0 for i in range(105)]
for i in a:
take[i%k]+=1
nee[i%k]+=1
ans=0
ans+=(take[0]//2)*2
for i in range(1,k):
if i==k-i:
ans+=(take[i]//2)*2
elif k-i>=0:
#print(i,k-i)
ans+=min(take[i],take[k-i])
print(ans)
``` | output | 1 | 19,490 | 24 | 38,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,491 | 24 | 38,982 |
Tags: math, number theory
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = [0] * k
for i in range(n):
d[a[i] % k] += 1
num = 0
for i in range(k):
if k - i < i:
break
if i == 0:
num += d[i] // 2
elif i == k - i:
num += d[i] // 2
else:
num += min(d[i], d[k - i])
print(num * 2)
``` | output | 1 | 19,491 | 24 | 38,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4. | instruction | 0 | 19,492 | 24 | 38,984 |
Tags: math, number theory
Correct Solution:
```
n,k=map(int,input().split())
l=list(map(int,input().split()))
re=[0]*101
for i in range(n):
re[l[i]%k]+=1
#print(l[i]%k,re[l[i]%k])
m=0
for i in range(n):
a=l[i]%k
if 2*a==k:
if re[k-a]>=2 and a!=0:
m=m+2
#print(i)
re[k-a]=re[k-a]-2
elif re[k-a]>=1 and a!=0 and re[a]>=1:
m=m+2
#print(i)
re[k-a]=re[k-a]-1
re[a]=re[a]-1
elif a==0 and re[0]>=2:
m=m+2
#print(i)
re[0]=re[0]-2
print(m)
``` | output | 1 | 19,492 | 24 | 38,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
n, k = list(map(int, input().strip().split()))
d = list(map(int, input().strip().split()))
mod_dict = dict()
for di in d:
di_mod = di % k
if di_mod in mod_dict:
mod_dict[di_mod] += 1
else:
mod_dict[di_mod] = 1
# print(mod_dict)
tot_boxes = 0
for i in range(1, k):
if i in mod_dict and (k-i) in mod_dict:
if i == k - i:
tot_boxes += ( int(mod_dict[i] / 2) * 2 )
else:
tot_boxes += min(mod_dict[i], mod_dict[k-i])
if 0 in mod_dict:
tot_boxes += ( int(mod_dict[0] / 2) * 2 )
print(tot_boxes)
# a = 10**14
# print(a)
# print(a - 1)
``` | instruction | 0 | 19,493 | 24 | 38,986 |
Yes | output | 1 | 19,493 | 24 | 38,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
a = input().split()
#length = int(a[0])
mod = int(a[1])
data = list(map(int, input().split()))
dic = {}
for i in range(mod):
dic[i] = 0
for num in data:
dic[num%mod] += 1
sum = 0
for i in range(1, (mod+1)//2):
sum += min(dic[i], dic[mod - i])
sum += dic[0]//2
if mod % 2 ==0:
sum += dic[mod//2]//2
print(sum*2)
``` | instruction | 0 | 19,494 | 24 | 38,988 |
Yes | output | 1 | 19,494 | 24 | 38,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
dicttotal = dict.fromkeys(range(k), 0)
answer = 0
for i in range (n) :
dicttotal[a[i] % k] += 1
answer += dicttotal[0] // 2
for i in range (1, (k + 1) // 2) :
answer += min(dicttotal[i], dicttotal[k - i])
if k % 2 == 0 :
answer += dicttotal[k / 2] // 2
print (answer * 2)
``` | instruction | 0 | 19,495 | 24 | 38,990 |
Yes | output | 1 | 19,495 | 24 | 38,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
z,zz=input,lambda:list(map(int,z().split()))
n,k=zz()
lst=zz()
cnt=[0]*k
for i in lst:cnt[i%k]+=1
ans=cnt[0]//2
l=1
r=k-1
while l<r:
ans+=min(cnt[l],cnt[r])
l+=1
r-=1
if k%2==0:
ans+=cnt[k//2]//2
print(ans*2)
``` | instruction | 0 | 19,496 | 24 | 38,992 |
Yes | output | 1 | 19,496 | 24 | 38,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
n,k=[int(x) for x in input().split()]
a=list(map(int,input().split()))
d=dict()
d[0]=0
for i in range(0,101):
d[i]=0
for i in range(n):
a[i]%=k
d[a[i]]+=1
ans=0
for i in range(0,k):
if a[i]==0:
ans+=(d[0]//2)*2
if(d[0]):
d[0]=0
else:
d[0]=1
continue
if d[k-a[i]]:
d[k-a[i]]-=1
d[a[i]]-=1
ans+=2
print(ans)
``` | instruction | 0 | 19,497 | 24 | 38,994 |
No | output | 1 | 19,497 | 24 | 38,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
n, k = map(int, input().split())
l = map (int, input().split())
f = [0 for i in range(0, k)]
for i in l:
f[i%k]=f[i%k]+1
ans = f[0]//2
for i in range(1, k//2+1):
ans=ans+min(f[i], f[k-i])
print(2*ans)
``` | instruction | 0 | 19,498 | 24 | 38,996 |
No | output | 1 | 19,498 | 24 | 38,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
n, k = map(int, input().split())
liczby = list(map(int, input().split()))
lista = []
wynik = 0
zera = 0
for x in range(n):
reszta = liczby[x] % k
lista.append(reszta)
lista.sort()
slownik = {}
a = 1
for x in range(n-1):
if lista[x] == lista[x+1]:
a+=1
if x == n-2:
if lista[x] == 0:
zera += a
else:
slownik[lista[x]] = a
else:
if lista[x] == 0:
zera += a
else:
slownik[lista[x]] = a
a = 1
x = 1
y = k-1
while x <= y:
if x + y == k:
try:
if x != y:
wynik+= min(slownik[x], slownik[y])
y-=1
x+=1
else:
wynik+= slownik[x] // 2
x+=1
except:
x+=1
elif x + y > k:
y-=1
else:
x+=1
wynik+= zera // 2
print(2*wynik)
#1 2 4 6 8 == 10
``` | instruction | 0 | 19,499 | 24 | 38,998 |
No | output | 1 | 19,499 | 24 | 38,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
International Women's Day is coming soon! Polycarp is preparing for the holiday.
There are n candy boxes in the shop for sale. The i-th box contains d_i candies.
Polycarp wants to prepare the maximum number of gifts for k girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by k. In other words, two boxes i and j (i β j) can be combined as a gift if d_i + d_j is divisible by k.
How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.
Input
The first line of the input contains two integers n and k (1 β€ n β€ 2 β
10^5, 1 β€ k β€ 100) β the number the boxes and the number the girls.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^9), where d_i is the number of candies in the i-th box.
Output
Print one integer β the maximum number of the boxes Polycarp can give as gifts.
Examples
Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4
Note
In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (2, 3);
* (5, 6);
* (1, 4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (6, 8);
* (2, 3);
* (1, 4);
* (5, 7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
* (1, 2);
* (6, 7).
So the answer is 4.
Submitted Solution:
```
n,k=map(int,input().split())
b=[0]*(k+1)
s=list(map(int,input().split()))
for z in s:
b[z%k]+=1
if k==1:
print(0)
exit()
del s
count=(b[0]//2)*2
for i in range(1,len(b)//2+1):
count+=min(b[i],b[k-i])
print(count)
``` | instruction | 0 | 19,500 | 24 | 39,000 |
No | output | 1 | 19,500 | 24 | 39,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,592 | 24 | 39,184 |
Tags: math, number theory
Correct Solution:
```
#import math
#from functools import lru_cache
#import heapq
#from collections import defaultdict
#from collections import Counter
#from sys import stdout
#from sys import setrecursionlimit
from sys import stdin
input = stdin.readline
for Ti in range(int(input().strip())):
n, k = [int(x) for x in input().strip().split()]
i = 1
a = float('inf')
while(i*i<=n and i<=k):
rem, div = n%i, n//i
if(not rem):
if(div<=k): a = min(a, i)
a = min(a, div)
i+=1
print(a)
``` | output | 1 | 19,592 | 24 | 39,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,593 | 24 | 39,186 |
Tags: math, number theory
Correct Solution:
```
from math import sqrt
def divisors(n):
divs = {1}
for i in range(2, int(sqrt(n)) + 5):
if n % i == 0:
divs.add(i)
divs.add(n // i)
divs |= {n}
return divs
def main():
n, k = map(int, input().split())
ans = 1e18
for div in divisors(n):
if div <= k:
ans = min(ans, n // div)
return ans
if __name__ == "__main__":
t = int(input())
for _ in range(t):
print(main())
``` | output | 1 | 19,593 | 24 | 39,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,594 | 24 | 39,188 |
Tags: math, number theory
Correct Solution:
```
from sys import stdin,stdout
for query in range(int(stdin.readline())):
nk=stdin.readline().split()
n=int(nk[0])
k=int(nk[1])
lowest=10000000000
mybool=False
count=0
for x in range(1,int(n**.5)+1):
count+=1
if n%x==0:
if n//x<=k:
stdout.write(str(x)+'\n')
mybool=True
break
if x<=k:
lowest=n//x
if mybool:
continue
stdout.write(str(lowest)+'\n')
``` | output | 1 | 19,594 | 24 | 39,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,595 | 24 | 39,190 |
Tags: math, number theory
Correct Solution:
```
import math
for i1 in range(int(input())):
n,k=map(int,input().split())
root=int(math.sqrt(n))
if k>=n:
print(1)
continue
lim=min(k,root)
#print('lim',lim)
flag=0
for i in range(2,lim+1):
if n%i==0:
flag=1
temp=n//i
if temp<=k:
temp=i
break
if flag:
print(temp)
else:
print(n)
``` | output | 1 | 19,595 | 24 | 39,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,596 | 24 | 39,192 |
Tags: math, number theory
Correct Solution:
```
testcases = int( input() )
import math
for testcase in range(testcases):
newarr = input()
newarr = newarr.split()
n = int(newarr[0])
k = int(newarr[1])
if k >= n:
print(1)
continue
if n % k == 0 :
print( n // k)
continue
if k == 2 and n & 1 == 1 :
print(n)
continue
if k == 3 and n & 1 == 0 :
print(n // 2)
continue
sqrtans = int(math.sqrt(n)) + 3
ans = n
#print("sqrtans is" + str(sqrtans))
for i in range( 2, min(k + 1, sqrtans) ):
if n % i == 0 :
ans = n // i
if ans <= k :
ans = i
break
print(ans)
``` | output | 1 | 19,596 | 24 | 39,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,597 | 24 | 39,194 |
Tags: math, number theory
Correct Solution:
```
def f(n,k):
x = 1
while x*x <=n:
if n%x == 0 and n/x <= k:
return x
x+=1
ans = 0
y = 1
while y*y <=n:
if n%y == 0 and y<=k:
ans = n//y
y+=1
return ans
t = int(input())
for i in range(t):
[n,k] = input().split(' ')
n = int(n)
k = int(k)
print(f(n,k))
``` | output | 1 | 19,597 | 24 | 39,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,598 | 24 | 39,196 |
Tags: math, number theory
Correct Solution:
```
import math
def checkprime(n):
for i in range(2,int(math.sqrt(n))+1):
if(n%i==0):
return False
return True
def fctrlist(n):
L = []
for i in range(2,int(n**0.5)+1):
if(n%i==0):
if(n//i == i):
L.append(i)
else:
L.append(n//i);L.append(i)
return L
# Priyanshu Kumar
for _ in range(int(input())):
n,k = map(int,input().split())
if(k==1):
print(n)
continue
if(n<=k):
print(1)
continue
if(checkprime(n)):
print(n)
continue
A = fctrlist(n)
A.sort()
i = 0
d = 1
while(i<len(A)):
if(n//A[i] <= k):
d = n//A[i]
break
else:
i+=1
print(int(n//d))
``` | output | 1 | 19,598 | 24 | 39,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels. | instruction | 0 | 19,599 | 24 | 39,198 |
Tags: math, number theory
Correct Solution:
```
import math
for _ in range(int(input())):
n, k = list(map(int,input().split()))
res = n
for i in range(1, int(math.sqrt(n))+1):
if n % i == 0:
if n // i <= k and i <= res:
res = i
elif i <= k and n // i <= res:
res = n // i
print(res)
``` | output | 1 | 19,599 | 24 | 39,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
t=int(input())
import math
def factors(n,k):
results = set()
for i in range(1, int(math.sqrt(n)) + 1):
if n % i == 0 and i<=k:
results.add(i)
last=int(n/i)
if last <=k:
results.add(int(n/i))
return results
for test in range(t):
n,k=[int(x) for x in input().split()]
high=1
if n <= k:
print(1)
continue
ans=list(factors(n,k))
ans.sort()
print(n//ans[-1])
``` | instruction | 0 | 19,600 | 24 | 39,200 |
Yes | output | 1 | 19,600 | 24 | 39,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
import math
T = int(input())
def divs(n):
d = []
for i in range(1, math.ceil(math.sqrt(n))+1):
if n % i == 0:
d.extend([i, n//i])
return sorted(d)
for t in range(T):
N, K = [int(_) for _ in input().split()]
for d in divs(N):
if N / d <= K:
print(d)
break
``` | instruction | 0 | 19,601 | 24 | 39,202 |
Yes | output | 1 | 19,601 | 24 | 39,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
import sys
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
import math
# method to print the divisors
def div(n):
# Note that this loop runs till square root
i = 1
c = []
while i <= math.sqrt(n):
if (n % i == 0):
# If divisors are equal, print only one
if (n / i == i):
c.append(i)
else:
# Otherwise print both
c.append(i)
c.append(n // i)
i = i + 1
return (list(set(c)))
for _ in range(int(input())):
n, k = map(int, input().split())
li = div(n)
li.sort()
d=[]
for i in range(len(li)):
if li[i] > k:
break
d.append(n // li[i])
print(min(d))
``` | instruction | 0 | 19,602 | 24 | 39,204 |
Yes | output | 1 | 19,602 | 24 | 39,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
import math
t=int(input())
for j in range(t):
n,k=map(int,input().split())
max=1
if n<=k:
print("1")
else:
for i in range(1,int(math.sqrt(n))+1):
if n%i==0:
if i<=k:
if max<=i:
max=i
if n//i<=k:
if max<n//i:
max=n//i
print(n//max)
``` | instruction | 0 | 19,603 | 24 | 39,206 |
Yes | output | 1 | 19,603 | 24 | 39,207 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
mod=10**9+7
def ni():
return int(raw_input())
def li():
return map(int,raw_input().split())
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
for t in range(input()):
n,k=li()
i=2
ans=1
if n<=k:
pn(1)
continue
while i*i<=n:
if n%i==0:
x1=i
x2=n/i
if x1<=k:
ans=max(ans,x1)
if x2<=k:
ans=max(ans,x2)
i+=1
pn(n/ans)
``` | instruction | 0 | 19,604 | 24 | 39,208 |
Yes | output | 1 | 19,604 | 24 | 39,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
from math import sqrt
if __name__ == '__main__':
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
if k >= n:
print(1)
continue
i = min(int(sqrt(n)) + 1, k)
while i > 0:
if n % i == 0:
m = min(n//i, i)
M = max(n//i, i)
print(m if M <= k else M)
break
i -= 1
else:
print(n)
``` | instruction | 0 | 19,605 | 24 | 39,210 |
No | output | 1 | 19,605 | 24 | 39,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
def isPrime(n):
if (n <= 1):
return False
if (n <= 3):
return True
if (n % 2 == 0 or n % 3 == 0):
return False
i = 5
while (i * i <= n):
if (n % i == 0 or n % (i + 2) == 0):
return False
i = i + 6
return True
answer = []
for i in range(int(input())):
n, k = list(map(int, input().split()))
if k >= n:
answer.append(1)
elif k == 1:
answer.append(n)
else:
if not isPrime(n):
for j in range(2, k + 1):
if n % j == 0:
answer.append(j)
break
else:
answer.append(n)
for i in range(len(answer)):
print(answer[i])
``` | instruction | 0 | 19,606 | 24 | 39,212 |
No | output | 1 | 19,606 | 24 | 39,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
import math
for _ in range(int(input())):
n, k = map(int, input().split())
if k >= n:
print(1)
else:
j = 1
ans = n
while j * j < n:
if n % j == 0:
if j < k:
ans = min(ans, n// j)
if n // j < k:
ans = min(ans, j)
j += 1
print(ans)
``` | instruction | 0 | 19,607 | 24 | 39,214 |
No | output | 1 | 19,607 | 24 | 39,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1 β€ i β€ k). The store has an infinite number of packages of each type.
Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly n shovels?
For example, if n=8 and k=7, then Polycarp will buy 2 packages of 4 shovels.
Help Polycarp find the minimum number of packages that he needs to buy, given that he:
* will buy exactly n shovels in total;
* the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from 1 to k, inclusive.
Input
The first line contains an integer t (1 β€ t β€ 100) β the number of test cases in the input. Then, t test cases follow, one per line.
Each test case consists of two positive integers n (1 β€ n β€ 10^9) and k (1 β€ k β€ 10^9) β the number of shovels and the number of types of packages.
Output
Print t answers to the test cases. Each answer is a positive integer β the minimum number of packages.
Example
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
Note
The answer to the first test case was explained in the statement.
In the second test case, there is only one way to buy 8 shovels β 8 packages of one shovel.
In the third test case, you need to buy a 1 package of 6 shovels.
Submitted Solution:
```
#!/usr/bin/env python3
# vim: set fileencoding=utf-8
# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation
"""Module docstring
"""
import functools
import heapq
import itertools
import logging
import math
import os
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict, deque
from copy import deepcopy
from io import BytesIO, IOBase
from typing import Dict, List, Optional, Set, Tuple
def solve(n: int, k: int) -> int:
if n <= k:
return 1
for i in range(max(2, math.ceil(n / k)), min(k, math.ceil(math.sqrt(n))) + 1):
if n % i == 0:
return i
return n
def do_job(stdin, stdout):
"Do the work"
LOG.debug("Start working")
# first line is number of test cases
T = int(stdin.readline().strip())
for _testcase in range(T):
n, k = map(int, stdin.readline().split())
result = solve(n, k)
print(result, file=stdout)
def print_output(testcase: int, result) -> None:
"Formats and print result"
if result is None:
result = "IMPOSSIBLE"
print("Case #{}: {}".format(testcase + 1, result))
# 6 digits float precision {:.6f} (6 is the default value)
# print("Case #{}: {:f}".format(testcase + 1, result))
BUFSIZE = 8192
class FastIO(IOBase):
# pylint: disable=super-init-not-called, expression-not-assigned
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):
# pylint: disable=super-init-not-called
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def configure_log() -> None:
"Configure the log output"
log_formatter = logging.Formatter("L%(lineno)d - " "%(message)s")
handler = logging.StreamHandler(IOWrapper(sys.stderr))
handler.setFormatter(log_formatter)
LOG.addHandler(handler)
LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
LOG = logging.getLogger("template")
configure_log()
def main(argv=None):
"Program wrapper."
if argv is None:
argv = sys.argv[1:]
parser = ArgumentParser()
parser.add_argument(
"-v",
"--verbose",
dest="verbose",
action="store_true",
default=False,
help="run as verbose mode",
)
args = parser.parse_args(argv)
if args.verbose:
LOG.setLevel(logging.DEBUG)
stdin = IOWrapper(sys.stdin)
stdout = IOWrapper(sys.stdout)
do_job(stdin, stdout)
stdout.flush()
for h in LOG.handlers:
h.flush()
return 0
if __name__ == "__main__":
sys.exit(main())
``` | instruction | 0 | 19,608 | 24 | 39,216 |
No | output | 1 | 19,608 | 24 | 39,217 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.