id stringlengths 14 117 | description stringlengths 29 13k | code stringlengths 10 49.8k | test_samples dict | source class label 3
classes | prompt stringlengths 391 104k |
|---|---|---|---|---|---|
p03922 CODE FESTIVAL 2016 Final (Parallel) - Pair Cards_36865 | Takahashi is playing with N cards.
The i-th card has an integer X_i on it.
Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:
* The integers on the two cards are the same.
* The sum of the integers on the two cards is a multiple of M.
Find the maximum numb... | import math
N, M = map(int, input().split())
X = list(map(int, input().split()))
mod_arr = [{} for i in range(M)]
for x in X:
d = mod_arr[x % M]
if x in d:
d[x] += 1
else:
d[x] = 1
ans = 0
if M == 1:
print(N // 2)
exit()
def calc_only_one(d):
sum_v = sum(d.values())
return... | {
"input": [
"7 5\n3 1 4 1 5 9 2",
"15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 99 99",
"7 5\n3 1 4 1 5 9 3",
"15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 83 99",
"15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 83 56",
"15 10\n1 5 6 10 11 11 11 20 21 25 25 26 99 124 99",
"7 5\n3 1 4 1 5 8 3",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is playing with N cards.
The i-th card has an integer X_i on it.
Takahashi is trying to create as many pairs of cards as possible satisfying one of the following condition... |
p00023 Circles Intersection_36869 | You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$.
Write a program which prints:
* "2" if $B$ is in $A$,
* "-2" if $A$ is in $B$,
* "1" if circumference of $A$ and $B$ intersect, and
* "0" if $A$ and $B$ do not... | n = int(input())
for _ in range(n):
xa, ya, ra, xb, yb, rb = map(float, input().split())
dist = ((xa - xb)**2 + (ya - yb)**2)**.5
if ra + rb < dist:
print('0')
elif abs(ra - rb) <= dist:
print('1')
elif (rb < ra):
print('2')
elif (ra < rb):
print('-2') | {
"input": [
"2\n0.0 0.0 5.0 0.0 0.0 4.0\n0.0 0.0 2.0 4.1 0.0 2.0",
"2\n0.0 0.0 5.0 0.0 0.0 4.0\n0.0 0.0 2.0 4.1 0.0 2.4515674947137622",
"2\n0.0 0.0 5.0 0.0 1.5542884595470625 4.0\n0.0 0.0 2.0 4.1 0.0 2.4515674947137622",
"2\n3.1147350602004042 10.32674830176415 10.748453312336865 4.001069425760041 6... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given circle $A$ with radius $r_a$ and with central coordinate $(x_a, y_a)$ and circle $B$ with radius $r_b$ and with central coordinate $(x_b, y_b)$.
Write a program which p... |
p00154 Sum of Cards_36873 | Let's play the game using a bag containing several cards with integers written on it. In each game, participants first declare one of their favorite number n. Then, take out an appropriate number of cards from the bag at a time, and if the sum of the numbers written on those cards is equal to n, you will receive a luxu... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
ans = []
while 1:
M = int(readline())
if M == 0:
break
P = [list(map(int, input().split())) for i in range(M)]
memo = {}
def dfs(i, rest):
if i == M:
return rest == 0
key = (i, rest)
if key ... | {
"input": [
"5\n1 10\n5 3\n10 3\n25 2\n50 2\n4\n120\n500\n100\n168\n7\n1 10\n3 10\n5 10\n10 10\n25 10\n50 10\n100 10\n3\n452\n574\n787\n0",
"5\n1 10\n5 3\n10 3\n25 2\n50 2\n4\n120\n500\n100\n168\n7\n1 10\n3 10\n5 10\n10 10\n25 10\n10 10\n100 10\n3\n452\n574\n787\n0",
"5\n2 10\n5 3\n10 3\n25 2\n50 2\n4\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's play the game using a bag containing several cards with integers written on it. In each game, participants first declare one of their favorite number n. Then, take out an approp... |
p00311 Fishing Competition_36877 | The brothers Hiroshi and Kenjiro came to Lake Inawashiro for fishing. The two decided to score as follows and compete with the total score of the fish they caught.
* One char is a point
* One yamame trout b points
* Add c points for every 10 chars
* Add d points for every 20 yamame trout
Create a program to determi... | def main():
h1, h2 = map(int, input().split())
k1, k2 = map(int, input().split())
a, b, c, d = map(int, input().split())
hiroshi = h1 * a + int(h1 / 10) * c + h2 * b + int(h2 / 20) *d
kenjiro = k1 * a + int(k1 / 10) * c + k2 * b + int(k2 / 20) *d
if hiroshi > kenjiro:
print('hiroshi')
... | {
"input": [
"5 1\n3 1\n1 2 5 5",
"0 20\n10 0\n1 1 10 0",
"5 1\n4 2\n1 2 5 5",
"9 1\n3 1\n1 2 5 5",
"0 20\n10 0\n2 1 10 0",
"5 0\n4 1\n0 0 6 -1",
"5 1\n4 1\n1 2 5 5",
"9 1\n3 1\n1 2 5 3",
"0 13\n10 0\n2 1 10 0",
"5 1\n4 1\n1 2 5 1",
"9 2\n3 1\n1 2 5 3",
"0 9\n10 0\n2 1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The brothers Hiroshi and Kenjiro came to Lake Inawashiro for fishing. The two decided to score as follows and compete with the total score of the fish they caught.
* One char is a po... |
p00475 Exposition_36880 | problem
JOI City will hold a large-scale exposition.
There are two themes for this exposition, and each of the N exhibition facilities in JOI City will exhibit on one of the two themes.
The location of the facility is represented by plane coordinates (x, y). To move from the facility at position (x, y) to the facili... | # AOJ 0552: Exposition
# Python3 2018.7.1 bal4u
import sys
from sys import stdin
input = stdin.readline
x, y = [], []
n = int(input())
for i in range(n):
a, b = map(int, input().split())
x.append(a+b)
y.append(a-b)
xmin, xmax = min(x), max(x)
ymin, ymax = min(y), max(y)
ans1 = ans2 = 0
for i in range(n):
d1 = max... | {
"input": [
"5\n0 0\n1 0\n-1 -2\n0 1\n-1 1",
"5\n-1 0\n1 0\n-1 -2\n0 1\n-1 1",
"5\n-2 0\n1 0\n0 -2\n0 2\n-1 1",
"5\n0 0\n2 0\n0 -1\n-2 6\n-4 2",
"5\n0 1\n2 1\n0 -1\n-2 4\n-4 1",
"5\n-1 1\n1 1\n0 -1\n-2 8\n-5 1",
"5\n-2 2\n-1 2\n0 -1\n-2 26\n-9 1",
"5\n-2 2\n-1 3\n0 -2\n-2 26\n-9 1",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
JOI City will hold a large-scale exposition.
There are two themes for this exposition, and each of the N exhibition facilities in JOI City will exhibit on one of the two the... |
p00667 11224111122411_36883 | My arm is stuck and I can't pull it out.
I tried to pick up something that had rolled over to the back of my desk, and I inserted my arm while illuminating it with the screen of my cell phone instead of a flashlight, but I accidentally got caught in something and couldn't pull it out. It hurts if you move it forcibly.... | def f3(n):
a=b=c=0
for _ in range(n):
a,b,c=(a+b+c+1)%100000007,a,b
return a
def f5(n):
a=b=c=d=e=0
for _ in range(n):
a,b,c,d,e=(a+b+c+d+e+1)%100000007,a,b,c,d
return a
while 1:
s=input()
if s=="#":break
ans=1
num="_"
cnt=1
for n in s+"_":
i... | {
"input": [
"1\n11\n111111\n111111111111\n12345\n11111111119999999999\n11111111113333333333\n11111111118888888888\n11111111112222222222111111111\n11111111110000000000444444444\n11224111122411\n888888888888999999999999888888888888999999999999999999\n666666666666666777333333333338888888888\n11111144444411111114444... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
My arm is stuck and I can't pull it out.
I tried to pick up something that had rolled over to the back of my desk, and I inserted my arm while illuminating it with the screen of my c... |
p00810 Super Star_36886 | During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theory of "super stars". Do not take this term as a description of actors or singers. It is a revolutionary theory in astronomy.
According to... | def distance(star, position):
return sum([(a - b)**2 for a, b in zip(star, position)])**(1 / 2)
def difference(star, position):
return [(a - b) for a, b in zip(star, position)]
while True:
n = int(input())
if n == 0:
break
stars = [list(map(float, input().split())) for i in range(n)]
... | {
"input": [
"4\n10.00000 10.00000 10.00000\n20.00000 10.00000 10.00000\n20.00000 20.00000 10.00000\n10.00000 20.00000 10.00000\n4\n10.00000 10.00000 10.00000\n10.00000 50.00000 50.00000\n50.00000 10.00000 50.00000\n50.00000 50.00000 10.00000\n0",
"4\n10.00000 10.00000 10.00000\n20.00000 10.00000 10.00000\n20... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
During a voyage of the starship Hakodate-maru (see Problem A), researchers found strange synchronized movements of stars. Having heard these observations, Dr. Extreme proposed a theor... |
p00941 Do Geese See God?_36889 | Example
Input
crc
1
Output
crc | from heapq import heappush, heappop
def solve():
S = input()
K = int(input())
L = len(S)
INF = 10**9
cost = [[INF]*(L+1) for i in range(L+1)]
cost[0][L] = 0
ss = []
que = [(0, 0, L)]
while que:
d, a, b = heappop(que)
if cost[a][b] < d:
continue
ss... | {
"input": [
"crc\n1",
"crb\n1",
"bqc\n1",
"bcq\n2",
"ccq\n2",
"cdq\n2",
"dcq\n2",
"dcq\n4",
"qcd\n3",
"qce\n3",
"qce\n4",
"pde\n1",
"pdf\n1",
"ode\n0",
"ecp\n0",
"dcp\n0",
"ecp\n2",
"pce\n3",
"eep\n0",
"fep\n0",
"feq\n0",
"ffq\n0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Example
Input
crc
1
Output
crc
### Input:
crc
1
### Output:
crc
### Input:
crb
1
### Output:
bcrcb
### Code:
from heapq import heappush, heappop
def solve():
S = input()... |
p01074 Unhappy Class_36892 | Problem
Yamano Mifune Gakuen's 1st grade G group is a class where female students carrying misfortune gather. They face various challenges every day with the goal of being happy.
In their class, they can take practical happiness courses as part of the test of happiness.
From Monday to Friday, there are classes from 1... | from itertools import product
n, m, l = map(int, input().split())
subjects = [[] for _ in range(5)]
for _ in range(m):
d, a, k, t = map(int, input().split())
subjects[d].append((a, a + k - 1, t))
for i in range(5):
subjects[i].sort(key=lambda x:x[1])
#各曜日の科目数ごとの最大幸福
def calcDp(i):
#dp[y][x] ... y科目x... | {
"input": [
"3 7 3\n0 1 1 1\n0 1 1 2\n1 1 3 4\n1 1 1 1\n1 2 1 2\n2 1 1 3\n2 2 2 1",
"5 10 5\n0 1 1 2\n0 2 1 2\n0 1 2 3\n1 2 1 2\n1 4 2 3\n2 1 1 1\n2 1 1 2\n3 3 2 3\n4 1 1 2\n4 2 1 2",
"3 7 3\n0 1 1 1\n0 1 1 2\n1 1 3 4\n1 1 1 1\n1 2 1 2\n3 1 1 3\n2 2 2 1",
"5 10 5\n0 1 1 2\n0 2 1 2\n0 1 2 3\n1 2 0 2\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Yamano Mifune Gakuen's 1st grade G group is a class where female students carrying misfortune gather. They face various challenges every day with the goal of being happy.
In... |
p02248 String Search_36905 | Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P ≤ 10000
* The input consists of alphabetical characters and digits
Input
In the first line, a text T is given. In the second line, a s... | s=input();t=input()
[print(x) for x in range(len(s)-len(t)+1) if s[x:x+len(t)]==t] | {
"input": [
"xyzz\nyz",
"aabaaa\naa",
"aaabaa\naa",
"aabbaa\naa",
"aabaab\naa",
"aababb\naa",
"aaabaa\nab",
"aabba`\na`",
"cbabaa\nba",
"cbaaaa\nba",
"dbaaba\nba",
"dbaaba\nab",
"babaaa\naa",
"aaaaab\naa",
"baaaab\naa",
"eababa\nba",
"yzyz\nyz",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P... |
p02396 Print Test Cases_36909 | In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.
Write a program which reads an integer x and print it as is. Note that multiple datasets are give... | i = 0
while True:
n = int(input())
i += 1
if n == 0:
break
print("Case {}: {}".format(i, n)) | {
"input": [
"3\n5\n11\n7\n8\n19\n0",
"3\n5\n11\n3\n8\n19\n0",
"3\n5\n11\n7\n8\n34\n0",
"3\n5\n11\n4\n8\n19\n0",
"3\n5\n11\n7\n14\n34\n0",
"3\n5\n11\n4\n2\n19\n0",
"3\n5\n11\n7\n26\n34\n0",
"3\n5\n9\n4\n2\n19\n0",
"3\n2\n11\n7\n26\n34\n0",
"3\n4\n11\n7\n26\n34\n0",
"3\n4\n1... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice sol... |
1015_B. Obtaining the String_36919 | You are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n.
You can successively perform the following move any number of times (possibly, zero):
* swap any two adjacent (neighboring) characters of s (i.e. for any i = ... | n = int(input())
s = input()
t = input()
if s == t:
print(0)
elif sorted(s) != sorted(t):
print(-1)
else:
res = list()
ls = list(s)
lt = list(t)
for i in range(n):
if ls[i] != lt[i]:
pos = ls.index(lt[i], i+1)
j = pos-1
while j >= i:
ls... | {
"input": [
"4\nabcd\naccd\n",
"6\nabcdef\nabdfec\n",
"50\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"4\naaab\naabb\n",
"50\nbababababababababababababababababababababababababa\nababababababababababababababababababababababababab\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two strings s and t. Both strings have length n and consist of lowercase Latin letters. The characters in the strings are numbered from 1 to n.
You can successively per... |
1038_F. Wrap Around_36922 | You are given a binary string s.
Find the number of distinct cyclical binary strings of length n which contain s as a substring.
The cyclical string t contains s as a substring if there is some cyclical shift of string t, such that s is a substring of this cyclical shift of t.
For example, the cyclical string "00011... | n=int(input())
s=[c=='1' for c in input()]
m=len(s)
z=[[0,0]]
for c in s:
ind = z[-1][c]
z[-1][c] = len(z)
z.append(z[ind][:])
assert(len(z) == m+1)
z[m][0] = z[m][1] = m # make it sticky
# how many things match directly
dp = [0 for _ in range(m+1)]
dp[0] = 1
for i in range(n):
ndp = [0 for _ in range(m+1)]
for i... | {
"input": [
"4\n1010\n",
"20\n10101010101010\n",
"2\n0\n",
"5\n1\n",
"40\n0010\n",
"39\n00111\n",
"40\n1010100001001010110011000110001\n",
"38\n11111010100111100011\n",
"40\n0001\n",
"40\n1111\n",
"37\n1111110000000000000000000000000000000\n",
"37\n10011011100001101001... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a binary string s.
Find the number of distinct cyclical binary strings of length n which contain s as a substring.
The cyclical string t contains s as a substring if t... |
1061_B. Views Matter_36926 | You came to the exhibition and one exhibit has drawn your attention. It consists of n stacks of blocks, where the i-th stack consists of a_i blocks resting on the surface.
The height of the exhibit is equal to m. Consequently, the number of blocks in each stack is less than or equal to m.
There is a camera on the cei... | n,m=map(int,input().split(' '))
a=list(map(int,input().split(' ')))
a.sort()
count=0
prev=0
for i in range(n):
count+=1
if a[i]>prev:
prev+=1
count+=a[n-1]-prev
print(sum(a)-count)
| {
"input": [
"3 5\n1 2 4\n",
"5 6\n3 3 3 3 3\n",
"5 5\n2 3 1 4 4\n",
"3 3\n3 1 1\n",
"1 1000\n548\n",
"9 12\n3 3 3 3 3 5 8 8 11\n",
"5 4\n4 2 2 2 2\n",
"10 100\n1 1 1 1 1 1 1 1 1 6\n",
"5 100\n3 1 1 1 3\n",
"50 1000000000\n824428839 821375880 831521735 868908015 86990853 248293... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You came to the exhibition and one exhibit has drawn your attention. It consists of n stacks of blocks, where the i-th stack consists of a_i blocks resting on the surface.
The height... |
1083_A. The Fair Nut and the Best Path_36929 | The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city u and go by a simple path to city v. He hasn't determined the pat... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
adj = [[] for i in range(n)]
for i in range(n-1):
u, v, w = map(int, input().split())
u -= 1
v -= 1
adj[u].append((v, w))
adj[v].append((u, w))
best = [0] * n
ans = 0
def dfs(u):
stack = list()
visit... | {
"input": [
"3\n1 3 3\n1 2 2\n1 3 2\n",
"5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n",
"10\n81 34 31 38 69 62 54 18 72 29\n4 8 12\n2 9 25\n4 5 17\n5 7 35\n10 1 13\n9 3 53\n7 6 22\n1 6 82\n3 10 42\n",
"10\n11 43 11 96 18 53 25 89 31 41\n2 4 41\n7 1 88\n3 2 19\n10 3 38\n8 4 97\n7 5 21\n7 2 71\n3 6 69\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Fair Nut is going to travel to the Tree Country, in which there are n cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tre... |
1102_C. Doors Breaking and Repairing_36933 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.
There are n doors, the i-th door initially has durability equal to a_i.
During your move you can try to br... | n, x, y = map(int, input().split())
a = list(map(int,input().split()))
if x > y:
print( n )
else:
m = 0
for i in a:
if i <= x:
m += 1
print( m - m // 2 )
| {
"input": [
"5 5 6\n1 2 6 10 3\n",
"6 3 2\n2 3 1 3 4 2\n",
"5 3 3\n1 2 4 2 3\n",
"1 2 3\n3\n",
"69 2 3\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"100 1 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second ... |
1130_C. Connect_36937 | Alice lives on a flat planet that can be modeled as a square grid of size n × n, with rows and columns enumerated from 1 to n. We represent the cell at the intersection of row r and column c with ordered pair (r, c). Each cell in the grid is either land or water.
<image> An example planet with n = 5. It also appears i... | #complexity - O(n^2)
import math
import sys
sys.setrecursionlimit(2600)
class UnionFind():
def __init__(self, num_elements):
self.parent = list(range(num_elements))
self.rank = [1] * num_elements
def union(self, a, b):
par_a = self.find(a)
par_b = self.find(b)
if par_a == par_b:
re... | {
"input": [
"5\n1 1\n5 5\n00001\n11111\n00111\n00110\n00110\n",
"3\n1 3\n3 1\n010\n101\n010\n",
"5\n4 5\n1 1\n01111\n11111\n11110\n11010\n11000\n",
"10\n9 9\n2 2\n1111111111\n1000111111\n1000111111\n1111111111\n1111000001\n1111011111\n1111010001\n1111010101\n1111000101\n1111111111\n",
"5\n1 3\n5 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice lives on a flat planet that can be modeled as a square grid of size n × n, with rows and columns enumerated from 1 to n. We represent the cell at the intersection of row r and c... |
1190_A. Tokitsukaze and Discard Items_36945 | Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≤ m ≤ n) special items of them.
These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed o... | ##n,m,k=list(map(int,input().split()))
##p=list(map(int,input().split()))
##p.sort()
##import math
##ok=k
##ip=0
##s=1
##cnt=0
##a=False
##for i in p:
##
## if ip<i<=k:
##
## cnt+=1
##
## a=True
## elif ip<i<=k+cnt:
##
## s+=1
## k+=cnt+1
## a=True
##... | {
"input": [
"13 4 5\n7 8 9 10\n",
"10 4 5\n3 5 7 10\n",
"1000000000000000000 20 365\n31881893160049984 103938857870698567 103962228223609431 140762820261865064 175962215264653912 239086305245565642 354522451098745823 383839975876242372 443471287955807705 478923027151493682 511195154588214957 619570919279... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (... |
1209_E1. Rotate Columns (easy version)_36949 | This is an easier version of the next problem. The difference is only in constraints.
You are given a rectangular n × m matrix a. In one move you can choose any column and cyclically shift elements in this column. You can perform this operation as many times as you want (possibly zero). You can perform this operation ... |
def naiveSolve():
return
def main():
t=int(input())
allans=[]
for _ in range(t):
n,m=readIntArr()
grid=[]
for __ in range(n):
grid.append(readIntArr())
columns=[]
for col in range(m):
temp=[grid[i][col] for i in rang... | {
"input": [
"2\n2 3\n2 5 7\n4 2 4\n3 6\n4 1 5 2 10 4\n8 6 6 4 9 10\n5 4 9 5 8 7\n",
"1\n4 3\n1 1 100\n1 3 1\n2 100 100\n1 3 1\n",
"40\n2 2\n5 2\n1 5\n1 1\n3\n1 2\n1 1\n1 2\n1 1\n1 2\n2 3\n2 1\n1\n1\n1 1\n1\n2 1\n1\n1\n1 2\n2 3\n2 2\n1 3\n3 3\n1 1\n1\n2 1\n3\n4\n1 1\n2\n2 2\n1 1\n1 1\n2 2\n1 1\n1 1\n1 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an easier version of the next problem. The difference is only in constraints.
You are given a rectangular n × m matrix a. In one move you can choose any column and cyclically... |
1228_D. Complete Tripartite_36953 | You have a simple undirected graph consisting of n vertices and m edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.
Let's make a definition.
Let v_1 and v_2 be two some nonempty subsets of vertices that do not intersect. Let f(v_{1}... | from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.s... | {
"input": [
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"6 11\n1 2\n1 3\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n",
"3 0\n",
"4 3\n1 4\n2 4\n3 4\n",
"5 4\n1 3\n1 4\n2 3\n2 4\n",
"21 35\n1 4\n2 4\n1 5\n2 5\n1 6\n2 6\n1 7\n2 7\n1 8\n2 8\n1 9\n2 9\n1 10\n2 10\n1 11\n2 11\n1 12\n2 12\n1 13\n2 13\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a simple undirected graph consisting of n vertices and m edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph ca... |
1270_D. Strange Device_36957 | This problem is interactive.
We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.
This device can answer queries of the following form: in response to the positions of k diffe... | import sys
input = sys.stdin.readline
N, K = map(int, input().split())
def inout(A):
print("?", end=" ")
print(*A)
sys.stdout.flush()
pos, a = map(int, input().split())
return pos, a
dic = {}
for k in range(1, K+2):
A = list(range(1,k)) + list(range(k+1, K+2))
pos, a = inout(A)
if a ... | {
"input": [
"4 3\n4 9\n4 9\n4 9\n1 2",
"11 9 8\n814595022 582230335 322421617 575726087 777696481 48691809 44632024 183761969 460459274 253447215 169826060\n",
"2 1 1\n534807456 124320943\n",
"3 2 2\n421335162 750960858 577245309\n",
"10 9 1\n321376743 64146243 670700897 575471266 303438330 11315... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This problem is interactive.
We have hidden an array a of n pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using... |
1293_B. JOE is on TV!_36961 | [3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in rounds, where in each round the host asks JOE and his opponents a common question. All participants failing to answer are eliminated. The sho... | n = int(input())
c = 0
while n>0:
c += 1/n
n -= 1
print(c) | {
"input": [
"1\n",
"2\n",
"8212\n",
"99998\n",
"12\n",
"43\n",
"19\n",
"99999\n",
"5\n",
"696\n",
"368\n",
"9\n",
"13\n",
"99996\n",
"9788\n",
"40862\n",
"50225\n",
"22\n",
"99995\n",
"10\n",
"7660\n",
"99993\n",
"23\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
[3R2 - Standby for Action](https://www.youtube.com/watch?v=P2ZVC9aoiKo)
Our dear Cafe's owner, JOE Miller, will soon take part in a new game TV-show "1 vs. n"!
The game goes in roun... |
1313_B. Different Rules_36965 | Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest numb... | """
1
6 3 4
"""
n = int(input())
for _ in range(n):
nums = list(map(int,input().split()))
if nums[0] == 1:
print(1,1)
continue
if nums[1]+nums[2] <= nums[0]:
ans = 1
else:
ans = min(nums[0], nums[1]+nums[2]-nums[0]+1)
res = nums[0] if nums[1]+nums[2] > nums[0] else nu... | {
"input": [
"1\n6 3 4\n",
"1\n5 1 3\n",
"25\n5 1 1\n5 2 3\n5 5 5\n5 5 1\n5 4 4\n10 1 2\n10 3 7\n10 10 10\n10 3 1\n10 7 6\n1000000 21232 1234\n999999 999999 999999\n1000000 300001 701321\n1000000 290001 679121\n500000 98765 123456\n100 1 1\n1000000000 1 1000000000\n1000000000 1 500000000\n100000000 1 1234... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay... |
1335_E2. Three Blocks Palindrome (hard version)_36969 | The only difference between easy and hard versions is constraints.
You are given a sequence a consisting of n positive integers.
Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are a and b, a can be equal b) and is as follows: [\underbrace{a, a, ... | def max_tbp(xs, a, b, O, C):
m = 1
occs = O[a]
b_cnts = C[b]
for i in range(len(occs)//2):
st = occs[i]
en = occs[len(occs)-1-i]
cnt = b_cnts[en-1] - b_cnts[st]
m = max(m, (i+1)*2 + cnt)
return m
t = int(input())
for _ in range(t):
n = int(input... | {
"input": [
"6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 1\n3\n1 1 1\n",
"6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 2\n3\n1 1 1\n",
"6\n8\n1 1 2 2 3 2 1 1\n3\n1 3 2\n4\n1 10 10 1\n1\n26\n2\n2 1\n3\n1 1 1\n",
"6\n8\n1 1 2 2 1 2 1 2\n3\n1 3 3\n4\n1 10 10 1\n1\n26\n2\n2 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between easy and hard versions is constraints.
You are given a sequence a consisting of n positive integers.
Let's define a three blocks palindrome as the sequen... |
1358_B. Maria Breaks the Self-isolation_36973 | Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.
She has n friends who are also grannies (Maria is not included in this number). The i-th granny is ready to attend the ceremony, provided that at the time of her appearance in t... |
t = int(input())
for i in range(t):
n = int(input())
nums = list(map(int, input().split()))
ans = False
nums.sort()
for j in range(n-1, -1,-1):
if nums[j] <= j+1:
print(j+2)
ans = True
break
if not ans:
print(1)
... | {
"input": [
"4\n5\n1 1 2 2 1\n6\n2 3 4 5 6 7\n6\n1 5 4 5 1 9\n5\n1 2 3 5 6\n",
"8\n1\n1\n1\n2\n1\n3\n1\n4\n1\n5\n1\n6\n1\n7\n1\n8\n",
"2\n2\n179 57\n2\n444 1329\n",
"8\n1\n1\n1\n2\n1\n3\n1\n8\n1\n5\n1\n6\n1\n7\n1\n8\n",
"2\n2\n179 32\n2\n444 1329\n",
"4\n5\n1 1 2 2 1\n6\n2 3 4 5 6 7\n6\n2 5 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Maria is the most active old lady in her house. She was tired of sitting at home. She decided to organize a ceremony against the coronavirus.
She has n friends who are also grannies ... |
1375_G. Tree Modification_36977 | You are given a tree with n vertices. You are allowed to modify the structure of the tree through the following multi-step operation:
1. Choose three vertices a, b, and c such that b is adjacent to both a and c.
2. For every vertex d other than b that is adjacent to a, remove the edge connecting d and a and add t... | import sys
input = sys.stdin.readline
n=int(input())
graph=[[] for _ in range(n)]
for j in range(n-1):
x,y=map(int,input().split())
x-=1
y-=1
graph[x].append(y)
graph[y].append(x)
color=[-1]*n
tem=[0]
visit=[0]*n
color[0]=0
while(tem!=[]):
x=tem.pop()
for i in graph[x]:
if(color[i]... | {
"input": [
"6\n4 5\n2 6\n3 2\n1 2\n2 4\n",
"4\n2 4\n4 1\n3 4\n",
"15\n12 13\n12 2\n2 6\n4 9\n2 15\n5 4\n4 11\n8 4\n1 4\n1 2\n10 6\n3 2\n7 4\n2 14\n",
"15\n5 8\n5 12\n4 10\n1 2\n6 1\n5 14\n11 4\n4 15\n3 1\n5 3\n4 3\n7 5\n9 1\n13 5\n",
"5\n5 3\n3 4\n1 3\n1 2\n",
"5\n1 4\n3 1\n1 2\n5 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree with n vertices. You are allowed to modify the structure of the tree through the following multi-step operation:
1. Choose three vertices a, b, and c such that... |
1399_C. Boats Competition_36981 | There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.
So, if there are k teams (a_1, b_1), (a_2, b_2)... | from collections import Counter
def solve():
n=int(input())
A=list(map(int,input().split()))
if n==1:
return 0
A.sort()
mi=A[0]+A[1]
ma=A[-1]+A[-2]
a=Counter(A)
t=0
q=-1
for i in range(mi,ma+1):
t=0
for j in a:
if i-j in a:
# pr... | {
"input": [
"5\n5\n1 2 3 4 5\n8\n6 6 6 6 6 6 8 8\n8\n1 2 2 1 2 1 1 2\n3\n1 3 3\n6\n1 1 3 4 2 2\n",
"4\n14\n2 6 5 9 5 8 13 14 12 5 6 14 5 2\n36\n15 22 27 7 23 36 10 17 33 21 18 22 3 4 32 24 8 19 36 22 17 11 24 10 33 4 30 6 2 17 11 16 18 1 2 20\n2\n2 2\n12\n4 9 10 6 1 9 5 8 8 9 9 12\n",
"4\n14\n2 6 5 9 5 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n people who want to participate in a boat competition. The weight of the i-th participant is w_i. Only teams consisting of two people can participate in this competition. A... |
1440_D. Graph Subset Problem_36988 | You are given an undirected graph with n vertices and m edges. Also, you are given an integer k.
Find either a clique of size k or a non-empty subset of vertices such that each vertex of this subset has at least k neighbors in the subset. If there are no such cliques and subsets report about it.
A subset of vertices ... | from __future__ import division,print_function
from heapq import*
import sys
le = sys.__stdin__.read().split("\n")[::-1]
af = []
for ezo in range(int(le.pop())):
n,m,k = list(map(int, le.pop().split()))
ar = [set() for _ in range(n)]
for i in range(m):
a,b = list(map(int, le.pop().split()))
... | {
"input": [
"3\n5 9 4\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n10 15 3\n1 2\n2 3\n3 4\n4 5\n5 1\n1 7\n2 8\n3 9\n4 10\n5 6\n7 10\n10 8\n8 6\n6 9\n9 7\n4 5 4\n1 2\n2 3\n3 4\n4 1\n1 3\n",
"1\n15 17 4\n1 4\n1 3\n1 2\n2 3\n2 4\n3 4\n1 15\n1 14\n1 13\n1 12\n1 11\n1 10\n1 9\n1 8\n1 7\n1 6\n1 5\n",
"1\n15 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an undirected graph with n vertices and m edges. Also, you are given an integer k.
Find either a clique of size k or a non-empty subset of vertices such that each verte... |
1468_A. LaIS_36991 | Let's call a sequence b_1, b_2, b_3 ..., b_{k - 1}, b_k almost increasing if $$$min(b_1, b_2) ≤ min(b_2, b_3) ≤ ... ≤ min(b_{k - 1}, b_k).$$$ In particular, any sequence with no more than two elements is almost increasing.
You are given a sequence of integers a_1, a_2, ..., a_n. Calculate the length of its longest alm... | import bisect as bs
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
if n <= 2:
print(n)
continue
stack, m, p = [a[0]], [], [(1000000, 0)]
for v in a[1:]:
k = bs.bisect_right(m, v)
if k == len(m):
stack.append(v)
... | {
"input": [
"3\n8\n1 2 7 3 2 1 2 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n",
"3\n8\n1 2 7 3 2 1 2 5\n2\n2 1\n7\n4 1 5 2 6 3 7\n",
"3\n8\n1 2 7 6 2 1 1 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n",
"3\n8\n1 2 7 1 2 1 1 3\n2\n2 1\n7\n4 1 5 2 6 3 7\n",
"3\n8\n1 2 7 6 2 1 4 4\n2\n2 1\n7\n7 3 3 2 6 3 7\n",
"3\n8\n1 2 7 1 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's call a sequence b_1, b_2, b_3 ..., b_{k - 1}, b_k almost increasing if $$$min(b_1, b_2) ≤ min(b_2, b_3) ≤ ... ≤ min(b_{k - 1}, b_k).$$$ In particular, any sequence with no more ... |
1515_A. Phoenix and Gold_36996 | Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pieces of gold on a weight scale, one piece at a time.
The scale has an unusual defect: if the total weight on it is exactly x, it will ex... | import sys
input = sys.stdin.readline
for i in range(int(input())):
n,x = map(int,input().split())
arr = list(map(int,input().split()))
if sum(arr)==x:
print("NO")
else:
arr.sort()
print("YES")
s = 0
temp = -1
for i in range(n):
if s+arr[i]!=x:... | {
"input": [
"3\n3 2\n3 2 1\n5 3\n1 2 3 4 8\n1 5\n5\n",
"1\n6 46\n10 11 12 13 21 25\n",
"3\n3 2\n3 2 1\n5 3\n1 2 3 4 8\n1 5\n5\n",
"1\n6 46\n18 11 12 13 21 25\n",
"3\n3 2\n3 2 1\n5 3\n1 2 5 4 8\n1 5\n5\n",
"1\n6 46\n18 11 12 4 21 25\n",
"3\n3 4\n3 2 1\n5 3\n1 2 3 4 8\n1 5\n5\n",
"1\n6 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Phoenix has collected n pieces of gold, and he wants to weigh them together so he can feel rich. The i-th piece of gold has weight w_i. All weights are distinct. He will put his n pie... |
18_C. Stripe_37003 | Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, an... | n=int(input())
l=list(map(int,input().split()))
s=[0]*n
for i in range(n):
if i==0:
s[i]=l[i]
else:
s[i]=l[i]+s[i-1]
ans=0
for i in range(1,n):
if s[i-1]==s[-1]-s[i-1]:
ans=ans+1
print(ans) | {
"input": [
"2\n0 0\n",
"3\n1 1 1\n",
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"6\n2 3 -3 0 -3 1\n",
"4\n1 2 3 3\n",
"10\n-1 5 2 3 1 5 0 2 2 5\n",
"3\n0 0 0\n",
"1\n-3\n",
"10\n0 0 0 0 0 0 0 0 0 0\n",
"4\n-2 3 3 2\n",
"100\n-2 -1 1 0 -2 -1 2 2 0 0 2 1 0 2 0 2 1 0 -1 -1 -1 0 -2 -1 2 -... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways e... |
237_C. Primes on Interval_37009 | You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.
Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any int... | p=[1]*(1000005)
p[0]=0
p[1]=0
for i in range(2,1001):
if p[i]:
for j in range(2*i,1000005,i):
p[j]=0
for i in range(1,1000001):
p[i]+=p[i-1]
a,b,k=map(int,input().split())
if p[b]-p[a-1]<k:
exit(print(-1))
i=j=a
l=0
while j<=b:
if p[j]-p[i-1]<k:
j+=1
else:
l=max(l... | {
"input": [
"2 4 2\n",
"1 4 3\n",
"6 13 1\n",
"10000 1000000 60000\n",
"1 3 1\n",
"11 11 6\n",
"2 1000000 10000\n",
"1 1000000 78498\n",
"999953 999953 2\n",
"404430 864261 6\n",
"690059 708971 10000\n",
"1 1 1000000\n",
"1 1000000 10000\n",
"100000 1000000 782... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisor... |
262_A. Roma and Lucky Numbers_37013 | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got n positive integers.... | n, k = map(int,input().split())
l = list(map(int,input().split()))
a = 0
for i in range(len(l)):
c = list(str(l[i]))
s = 0
for j in range(len(c)):
if c[j] == "7" or c[j] == "4":
s += 1
if s <= k:
a += 1
print(a)
| {
"input": [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n",
"38 29\n333702889 680931737 61137217 203030505 68728281 11414209 642645708 590904616 3042901 607198177 189041074 700764043 813035201 198341461 126403544 401436841 420826465 45046581 20249976 46978855 46397957 706610773 24701041 57954481 51603266 593109701 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representati... |
286_A. Lucky Permutation_37017 | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | n=int(input())
if(n%4>1):
print(-1)
else:
ans=[0]*(n+1)
i,j,a,b=1,n,1,n
while(i<j and a<=n and b>=1):
ans[i],ans[j]=a+1,b-1
ans[i+1],ans[j-1]=b,a
i+=2
j-=2
a+=2
b-=2
if(i==j):
ans[i]=a
for i in range(1,n+1):
print(ans[i],end=' ')
... | {
"input": [
"4\n",
"2\n",
"1\n",
"5\n",
"10004\n",
"505\n",
"99999\n",
"7\n",
"10000\n",
"10001\n",
"20001\n",
"25\n",
"30001\n",
"10002\n",
"6\n",
"101\n",
"33\n",
"30001\n",
"10003\n",
"10004\n",
"20001\n",
"101\n",
"8\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, tha... |
311_A. The Closest Pair_37021 | Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded.
The problem is the follows. Given n points in the plane, find a pair of points between... | r = input().split(' ')
n = int( r[ 0 ] )
k = int( r[ 1 ] )
if n * ( n - 1 ) >> 1 <= k:
print( 'no solution' )
else:
for i in range( 0 , n ):
print( 0 , i + 1 )
| {
"input": [
"4 3\n",
"2 100\n",
"1854 631695\n",
"342 340\n",
"1947 944738707\n",
"1699 1442450\n",
"1989 367830\n",
"6 15\n",
"1792 341122\n",
"1595 1271214\n",
"1699 1442450\n",
"2 1\n",
"1854 631695\n",
"1834 1680860\n",
"1750 215129\n",
"5 6\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time comple... |
37_C. Old Berland Language_37030 | Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfect... | #!/usr/bin/python3
counts = [0]*1024
for x in range(len(counts)): counts[x] = []
N = int(input())
x = [int(t) for t in input().strip().split()]
for i,t in enumerate(x): counts[t].append(i)
curr = 0
ans = [0]*N
for i in range(1,1024):
while len(counts[i]) > 0:
x = bin(curr)[2:]
if len(x) > i:
print("NO")
e... | {
"input": [
"3\n1 2 3\n",
"3\n1 1 1\n",
"3\n1 2 1000\n",
"2\n1 1\n",
"30\n6 7 7 6 7 7 7 7 7 7 7 7 7 7 7 5 7 7 7 7 2 1 5 3 7 3 2 7 5 1\n",
"20\n4 4 3 4 4 4 4 4 4 4 4 3 3 2 1 4 4 3 3 3\n",
"3\n1 1 2\n",
"200\n11 23 6 1 15 6 5 9 8 9 13 11 7 21 14 17 8 8 12 6 18 4 9 20 3 9 6 9 9 12 18 5 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Be... |
400_B. Inna and New Matrix of Candies_37034 | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game la... | n, m = (int(x) for x in input().split())
st = set()
for i in range(n):
s = input()
g = s.index('G')
s = s.index('S')
if g > s:
print(-1)
exit(0)
st.add(s - g)
print(len(st))
| {
"input": [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n",
"4 10\n***G****S*\n*****GS***\nG****S****\nG*******S*\n",
"4 8\nG*S*****\n****G*S*\nG*****S*\n**G***S*\n",
"5 10\nG***S*****\nG****S****\n***GS*****\nG*S*******\nG***S*****\n",
"1 2\nSG\n",
"1 4\nSG**\n",
"1 2\nGS\n",
"10 10\nG*... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size n × m. ... |
427_C. Checkposts_37038 | Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you have to build some police checkposts. Checkposts can only be built in a junction. A checkpost at junction i can protect junction j if eit... | MOD = int(1e9) + 7
n = int(input())
w = [0] + list(map(int, input().split()))
q = [[] for i in range(n+1)]
p = [[] for i in range(n+1)]
m = int(input())
edges = [list(map(int, input().split())) for _ in range(m)]
for u, v in edges:
p[u].append(v)
q[v].append(u)
s, t = 0, 1
r = set(i for i in range(1, n+1) if... | {
"input": [
"5\n2 8 0 6 0\n6\n1 4\n1 3\n2 4\n3 4\n4 5\n5 1\n",
"3\n1 2 3\n3\n1 2\n2 3\n3 2\n",
"2\n7 91\n2\n1 2\n2 1\n",
"10\n1 3 2 2 1 3 1 4 10 10\n12\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n5 7\n6 4\n7 3\n8 9\n9 10\n10 9\n",
"1\n0\n0\n",
"1\n1000000000\n0\n",
"100\n174 174 49 152 10 185 101 157 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions.
To ensure the security, you ... |
450_A. Jzzhu and Children_37042 | There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies.
Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. ... | import math
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in range(n):
l[i]=math.ceil(l[i]/k)
f=max(l)
for i in range(n-1,-1,-1):
if f==l[i]:
print(i+1)
break
| {
"input": [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n",
"100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies.
Jzzhu... |
472_B. Design Tutorial: Learn from Life_37046 | One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: there are lots of people waiting in front of the elevator, each person wants to go to a certain floor. We can formalize it in the following... | n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
p = 1
i = 0
while n != 0:
tp = arr[i]
ans += 2 * (tp - p) * (round(n / k + 0.49999999999999))
while n != 0 and arr[i] == tp:
n -= 1
i += 1
p = tp
print(ans)
| {
"input": [
"10 3\n2 2 2 2 2 2 2 2 2 2\n",
"4 2\n50 100 50 100\n",
"3 2\n2 3 4\n",
"1 1\n2\n",
"100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One way to create a task is to learn from life. You can choose some experience in real life, formalize it and then you will get a new task.
Let's think about a scene in real life: th... |
496_C. Removing Columns_37050 | You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
abcd
edfg
hijk
... | import sys,heapq,math
from collections import defaultdict,deque
input=sys.stdin.readline
r,c=map(int,input().split())
grid=[]
for i in range(r):
grid.append(input().strip())
equal=[0 for _ in range(c)]
less=[0 for _ in range(c)]
for i in range(c):
for row in range(1,r):
if(grid[row-1][i... | {
"input": [
"1 10\ncodeforces\n",
"5 4\ncode\nforc\nesco\ndefo\nrces\n",
"4 4\ncase\ncare\ntest\ncode\n",
"3 2\naa\nbc\nba\n",
"4 3\nabd\nacc\nbdx\nbcy\n",
"1 100\nteloaetuldspjqdlcktjlishwynmjjhlomvemhoyyplbltfwmrlnazbbjvyvwvoxjvvoadkznvxqubgwesoxrznvbdizjdzixecb\n",
"9 7\nygqartj\nlgwxl... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combin... |
547_B. Mike and Feet_37056 | Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high.
<image>
A group of bears is a non-empty contiguous segment of the line. The size of ... | import math
import random
class AVLTree():
def __init__(self, x):
self.left = None
self.rght = None
self.val = x
self.height = 1
def getHeight0(root):
if root==None: return 0
return max(getHeight0(root.left), getHeight0(root.rght))+1
def getHeight(root):
if roo... | {
"input": [
"10\n1 2 3 4 5 4 3 2 1 6\n",
"5\n585325539 365329221 412106895 291882089 564718673\n",
"20\n452405440 586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from ... |
595_B. Pasha and Phone_37062 | Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.
Also Pasha has a number k and two sequences of length n / k (n is divisible by k) a1, a2, ..., an / k and b1, b2, ..., bn / k. Let's split the phone number into blocks of le... | import sys
n, k = sys.stdin.readline().split()
n = int(n)
k = int(k)
a = [int(x) for x in sys.stdin.readline().split()]
b = [int(x) for x in sys.stdin.readline().split()]
MOD = (10 ** 9) + 7
res = 1
for i in range(0, n // k):
lo = b[i] * (10 ** (k - 1)) - 1
up = (b[i] + 1) * (10 ** (k - 1)) - 1
tmp = ( ((1... | {
"input": [
"8 2\n1 22 3 44\n5 4 3 2\n",
"6 2\n38 56 49\n7 3 4\n",
"100 4\n388 2056 122 1525 2912 1465 3066 257 5708 3604 3039 6183 3035 626 1389 5393 3321 3175 2922 2024 3837 437 5836 2376 1599\n6 5 5 2 9 6 8 3 5 0 6 0 1 8 5 3 5 2 3 0 5 6 6 7 3\n",
"2 1\n9 9\n9 9\n",
"10 1\n3 1 1 4 8 7 5 6 4 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.
Also Pasha has a number k and two se... |
616_E. Sum of Remainders_37066 | Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).
The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1.
Input
The only line co... | from math import floor
def range_sum(low, up):
return (up * (up + 1)) // 2 - (low * (low + 1)) // 2
# for _ in range(int(input())):
mod = int(1e9 + 7)
n,m=map(int,input().split())
ans, sqrt_n = m*n, int(floor(n**0.5))
temp = 0
for i in range(1, sqrt_n + 1):
up = n // i
low = n // (i + 1)
up = min(up... | {
"input": [
"3 4\n",
"4 4\n",
"1 1\n",
"100 100\n",
"997167959139 7344481199252\n",
"20000000 10000000\n",
"1666199186071 28985049\n",
"2213058376259 2126643910770\n",
"7244641009859 6300054748096\n",
"4690824608515 2078940751563\n",
"8451941492387 3119072235422\n",
"9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by ... |
689_C. Mike and Chocolate Thieves_37073 | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous o... | def main():
m = int(input())
if m < 1000000:
lo = m*4
hi = m*8
else:
lo = int(4.949 * m)
hi = int(4.9492 * m)
while lo < hi - 1:
mid = (lo + hi)//2
nposs = countposs(mid)
if nposs < m:
lo = mid
else:
hi = mid
if ... | {
"input": [
"10\n",
"1\n",
"8\n",
"149344197\n",
"13\n",
"1000000000000000\n",
"4\n",
"999999999999999\n",
"998749999999991\n",
"49729446417673\n",
"57857854\n",
"550368702711851\n",
"7\n",
"151269640772354\n",
"6\n",
"99999\n",
"116003\n",
"812... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be ve... |
711_A. Bus to Udayland_37077 | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are... | n = int(input())
result = []
z = 0
for i in range(n):
place = input()
if place.count('OO') > 0:
if z == 0:
result.append(place.replace('OO', '++', 1))
z += 1
else:
result.append(place)
else:
result.append(place)
if z == 1:
print('YES')
for ... | {
"input": [
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n",
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|XX\nXX|XO\nOX|XX\nXO|XO\n",
"6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX\n",
"10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, an... |
732_A. Buy a Shovel_37081 | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ... | price, change = map(int, input().split())
ans = 1
total = price
while not((total % 10 != 0 and change == total % 10) or (total % 10 == 0)):
total += price
ans += 1
print(ans)
| {
"input": [
"237 7\n",
"15 2\n",
"117 3\n",
"1000 1\n",
"1 8\n",
"1000 2\n",
"1 5\n",
"998 9\n",
"1 4\n",
"1000 4\n",
"8 2\n",
"23 4\n",
"666 5\n",
"2 1\n",
"25 5\n",
"1000 5\n",
"15 5\n",
"999 8\n",
"8 9\n",
"1 7\n",
"2 3\n",
"1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number ... |
756_B. Travel Card_37085 | A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare.
The fare is constructed in the following manner. There are three types of tickets:
1. a tic... | def lower_bound(arr, left, right, target):
if arr[right]<target:
return right+1
while left < right:
mid = (left + right) >> 1
if arr[mid] >= target:
right = mid
else:
left = mid + 1
return left
T = int(input())
arr = [0] * T
dp = [0] * (T + 1)
for i i... | {
"input": [
"10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516\n",
"3\n10\n20\n30\n",
"1\n0\n",
"8\n0\n2\n51\n63\n69\n75\n80\n90\n",
"7\n100\n138\n279\n308\n396\n412\n821\n",
"8\n0\n3\n5\n6\n7\n8\n9\n10\n",
"7\n000\n138\n279\n308\n396\n412\n821\n",
"8\n0\n3\n5\n6\n7\n8\n9\n19\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and t... |
777_C. Alyona and Spreadsheet_37089 | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of n rows and m columns. By ai, j we will denote the integer located at the i-th row and the j-th column. We say that the table is sorted in... | import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
# region fastio
BUFSIZE = 819... | {
"input": [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n",
"10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n386865653\n67832626\n53360557\n17\n4 5\n4 7\n8 8\n9 9\n3 9\n8 10\n8 9\n7 9\n4 5\n2 9\n4 6\n2 4\n2 6\n4 6\n7 9\n2 4\n8 10\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of ... |
802_A. Heidi and Library (easy)_37093 | Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 through n.
We will look... | n,k=map(int,input().split())
a=list(map(int,input().split()))
z=[0]*81
kz,ans=0,0
for i in range(n):
if z[a[i]]: continue
ans+=1
if k>kz:
z[a[i]]=1; kz+=1
else:
h=-1
for j in range(1,n+1):
if z[j]:
m=n+1
for p in range(i,n):
... | {
"input": [
"4 2\n1 2 3 1\n",
"4 80\n1 2 2 1\n",
"4 1\n1 2 2 1\n",
"80 32\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 11 12 13 14\n",
"80 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy boo... |
822_C. Hacker, pack your bags!_37097 | It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. For such zeal boss gave the hacker a vacation of exactly x days. You... | from bisect import bisect_left
f = lambda: map(int, input().split())
n, x = f()
s, t = {}, {}
for i in range(n):
l, r, c = f()
d = r - l
if d not in s: s[d] = []
s[d].append((l, c))
for d, p in s.items():
p.sort(key=lambda q: q[0])
q = t[d] = [[l, c] for l, c in p]
for i in range(1, len(q))[... | {
"input": [
"4 5\n1 3 4\n1 2 5\n5 6 1\n1 2 4\n",
"3 2\n4 6 3\n2 4 1\n3 5 4\n",
"2 2\n1 1 1000000000\n2 2 1000\n",
"4 3\n1 1 2\n1 1 3\n2 3 3\n2 3 4\n",
"3 3\n11 11 2\n3 4 3\n8 9 2\n",
"4 5\n1 3 500000000\n1 2 500000000\n5 6 500000000\n1 2 500000000\n",
"2 5\n1 3 1000000000\n4 5 1000000000\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha.
So the hacker began to work hard in order to get rid of bor... |
847_H. Load Testing_37101 | Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send ai requests.
Polycarp plans to test Fakebook under a special kind of... | n = int(input())
a = list(map(int, input().split()))
lp,rp = [0 for i in range(n)],[0 for i in range(n)]
lnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)]
mx = a[0]
for i in range(1,n):
if a[i] > mx:
mx = a[i]
lp[i] = lp[i-1]
else:
mx += 1
lp[i] = lp[i-1] + mx - a[i]... | {
"input": [
"5\n1 4 3 2 5\n",
"5\n1 2 2 2 1\n",
"7\n10 20 40 50 70 90 30\n",
"2\n1 15\n",
"4\n36 54 55 9\n",
"5\n984181411 215198610 969039668 60631313 85746445\n",
"10\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916\n",
"1\n1\n",
"10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load t... |
869_C. The Intriguing Obsession_37105 | — This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three... | a,b,c = list(map(int, input().split(' ')))
MOD = 998244353
def d(a, b):
s = 1
for i in range(a, b+1):
s*=i
s%=MOD
return s
def cnk(n,k):
s = 1
for i in range(n-k+1, n+1):
s*=i
for i in range(1,k+1):
s/=i
return s
def factorial(n):
s = 1
for i in range(1, n+1):
s*=i
return s
def pow(a, b... | {
"input": [
"1 3 5\n",
"1 1 1\n",
"6 2 9\n",
"1 2 2\n",
"84 29 61\n",
"2048 4096 1024\n",
"1 2 3\n",
"1171 2989 2853\n",
"1158 506 4676\n",
"5000 1 1\n",
"4756 775 3187\n",
"28 47 1\n",
"2 1 1\n",
"4998 4998 4998\n",
"17 46 45\n",
"3238 2923 4661\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This... |
895_B. XK Segments_37109 | While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai ≤ aj and there are exactly ... | from bisect import bisect_left
R=lambda:map(int,input().split())
n,x,k=R()
a=sorted(R())
z=zip(a,(((u-1)//x+k)*x for u in a))
print(sum(bisect_left(a,l+x)-bisect_left(a,max(u,l)) for u,l in z))
| {
"input": [
"4 2 1\n1 3 5 7\n",
"5 3 1\n3 3 3 3 3\n",
"4 2 0\n5 3 1 7\n",
"3 5 0\n4 4 4\n",
"5 3 4\n24 13 1 24 24\n",
"1 13 1\n13\n",
"1 1 1\n1\n",
"2 1 1000000000\n1 1000000000\n",
"100 2 1\n1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1 1 1 2 1 2 1 2 1 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has ... |
916_C. Jamie and Interesting Graph_37113 | Jamie has recently found undirected weighted graphs with the following properties very interesting:
* The graph is connected and contains exactly n vertices and m edges.
* All edge weights are integers and are in range [1, 109] inclusive.
* The length of shortest path from 1 to n is a prime number.
* The su... | INF = 1000000
erast = [1] * INF
erast[1] = 0
primes = []
for i in range(2, INF):
if erast[i] == 1:
for j in range(i * 2, INF, i):
erast[j] = 0
primes.append(i)
# print(primes)
lastp = primes[-1]
n, m = map(int, input().split())
edges = set()
print(lastp, lastp)
for i in range(n - 2):
... | {
"input": [
"4 4\n",
"5 4\n",
"9 18\n",
"19 31\n",
"4 3\n",
"4 4\n",
"4 6\n",
"10 19\n",
"3 3\n",
"87 109\n",
"13 17\n",
"3 2\n",
"4 5\n",
"5 4\n",
"2 1\n",
"100 342\n",
"89 3439\n",
"92 280\n",
"88 666\n",
"100 4309\n",
"100 4665\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Jamie has recently found undirected weighted graphs with the following properties very interesting:
* The graph is connected and contains exactly n vertices and m edges.
* All e... |
939_D. Love Rescue_37117 | Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long.
This story c... | length=int(input())
s1=input()
s2=input()
connect=[{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25}]
tot=0
spells=[]
for i in range(0, length):
l1=ord(s1[i])-97
l2=ord(s2[i])-97
if not (l1 in connect[l2]):
tot=tot+1
spell... | {
"input": [
"3\nabb\ndad\n",
"8\ndrpepper\ncocacola\n",
"3\nabb\ndad\n",
"10\ndaefcecfae\nccdaceefca\n",
"100\npfkskdknmbxxslokqdliigxyvntsmaziljamlflwllvbhqnzpyvvzirhhhglsskiuogfoytcxjmospipybckwmkjhnfjddweyqqi\nakvzmboxlcfwccaoknrzrhvqcdqkqnywstmxinqbkftnbjmahrvexoipikkqfjjmasnxofhklxappvufpsyu... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from letteri... |
965_A. Paper Airplanes_37121 | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. They are going to buy several packs of paper, each of them containing p sheets, and then distribute the sheets between the people. Each pe... | k, n, s, p = map(int, input().split())
one = (n + s - 1) // s
print((one * k + p - 1) // p)
| {
"input": [
"5 3 2 3\n",
"5 3 100 1\n",
"1 2 1 2\n",
"1 1 10 10\n",
"10000 10000 1 1\n",
"2 400 23 57\n",
"10000 10000 3 2\n",
"300 2 37 51\n",
"1 1 1 1\n",
"9000 1 2432 1\n",
"11 1 1 1\n",
"1 1 10000 10000\n",
"1 1 2 2\n",
"300 300 21 23\n",
"9 20 5 7\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make s airplanes.
A group of k people decided to make n airplanes each. T... |
992_A. Nastya and an Array_37125 | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
* In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to z... | n=int(input())
l=list(map(int,input().split()))
l=set(l)
if 0 in l:
print(len(l)-1)
else:
print(len(l)) | {
"input": [
"4\n5 -6 -5 1\n",
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"10\n1 2 3 4 5 6 7 8 9 10\n",
"4\n2 0 0 -1\n",
"5\n1 0 0 0 0\n",
"4\n-1 0 0 1\n",
"3\n0 1 2\n",
"3\n0 0 2\n",
"5\n4 5 6 0 0\n",
"5\n1 2 0 0 0\n",
"4\n0 1 2 3\n",
"2\n0 1\n",
"5\n0 0 0 0 0\n",
"5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the followin... |
p02622 AtCoder Beginner Contest 172 - Minor Change_37139 | Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.
Operation: Choose one character of S and replace it with a different character.
Constraints
* S and T have lengths between 1 and 2\times 10^5 (inclusive).
* S and T consists ... | S=input()
T=input()
cc=0
for i in range(len(S)):
cc+=int(S[i]!=T[i])
print(cc) | {
"input": [
"apple\napple",
"abcde\nbcdea",
"cupofcoffee\ncupofhottea",
"apple\nelppa",
"abcdd\nbcdea",
"eeffocfopuc\ncupofhottea",
"elppa\nelppa",
"elppa\nelppb",
"elpap\nelppb",
"ddc`a\nbbcfa",
"ffgdmdfqpuc\noeutaieppud",
"ffgdmdfqpuc\noevt`ieuppd",
"hcfrahdjpmr\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are strings S and T. Consider changing S to T by repeating the operation below. Find the minimum number of operations required to do so.
Operation: Choose one character of S an... |
p02753 AtCoder Beginner Contest 158 - Station and Bus_37143 | In AtCoder City, there are three stations numbered 1, 2, and 3.
Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is `A`, Company A operates Station i; if S_i is `B`, Company B operates Station i.
To improve t... | S = input()
print("No" if len(set(S)) == 1 else "Yes")
| {
"input": [
"ABA",
"BBA",
"BBB",
"AAB",
"AAA",
"ABB",
"BAA",
"BAB",
"BAA",
"BAB",
"AAA",
"AAB",
"ABB"
],
"output": [
"Yes",
"Yes",
"No",
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"Yes\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In AtCoder City, there are three stations numbered 1, 2, and 3.
Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents whi... |
p02888 AtCoder Beginner Contest 143 - Triangles_37147 | Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:
* a < b + c
* b < c + a
* c < a + b
How... | import bisect
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(N-2):
for j in range(i+1,N-1):
ans+=bisect.bisect_left(L,L[i]+L[j])-j-1
print(ans)
| {
"input": [
"4\n3 4 2 1",
"7\n218 786 704 233 645 728 389",
"3\n1 1000 1",
"4\n5 4 2 1",
"7\n218 1140 704 233 645 728 389",
"3\n1 1000 2",
"7\n218 1140 704 233 645 890 389",
"7\n218 1140 1051 233 449 890 389",
"7\n218 1140 1051 16 636 890 389",
"7\n218 1140 551 40 636 890 487"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.
He is going to form a triangle using three of these sticks. Let a, b, and c be t... |
p03023 M-SOLUTIONS Programming Contest - Sum of Interior Angles_37151 | Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.
Print the answer in degrees, but do not print units.
Constraints
* 3 \leq N \leq 100
Input
Input is given from Standard Input in the following format:
N
Output
Print an integer representing the sum of th... | a = int(input())
print(int(a * 180 - 360)) | {
"input": [
"3",
"100",
"5",
"000",
"9",
"001",
"7",
"110",
"101",
"2",
"111",
"-1",
"4",
"8",
"11",
"-2",
"-3",
"-6",
"6",
"10",
"-4",
"-8",
"-16",
"-32",
"-57",
"-60",
"-91",
"-48",
"-39",
"-35",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides.
Print the answer in degrees, but do not print units.
Constraints
* 3 \leq... |
p03164 Educational DP Contest - Knapsack 2_37155 | There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.
Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.
Find ... | N,W = map(int,input().split())
dp = [0]+[W+1]*(N*10**3)
for i in range(N):
w,v = map(int,input().split())
for j in range(N*10**3+1-v)[::-1]:
dp[j+v] = min(dp[j+v],dp[j]+w)
for i in range(N*10**3+1)[::-1]:
if dp[i]<=W:
print(i)
exit()
| {
"input": [
"1 1000000000\n1000000000 10",
"6 15\n6 5\n5 6\n6 4\n6 6\n3 5\n7 2",
"3 8\n3 30\n4 50\n5 60",
"1 1000000000\n0000000000 10",
"6 15\n6 5\n5 6\n3 4\n6 6\n3 5\n7 2",
"3 8\n3 30\n4 35\n5 60",
"3 8\n3 30\n4 35\n5 78",
"6 15\n6 5\n0 6\n3 4\n6 6\n3 5\n7 3",
"3 8\n3 30\n0 35\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.
Taro has decided to choose some of the N items and carry the... |
p03306 SoundHound Inc. Programming Contest 2018 -Masters Tournament- - + Graph_37159 | Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.
Kenkoooo is trying to write a positive integer in each vertex so that the following condition is satisfied:
* For every edge i, the sum of the positive integers writt... | import sys
from sys import setrecursionlimit
from collections import deque
from heapq import heappop, heappush
setrecursionlimit(10**9)
#input = sys.stdin.readline
def inpl(): return map(int, input().split())
INF = 2**31
N, M = inpl()
D = [[] for _ in range(N+1)]
for _ in range(M):
u, v, s = inpl()
D[u].app... | {
"input": [
"4 3\n1 2 6\n2 3 7\n3 4 5",
"3 3\n1 2 3\n2 3 5\n1 3 4",
"8 7\n1 2 1000000000\n2 3 2\n3 4 1000000000\n4 5 2\n5 6 1000000000\n6 7 2\n7 8 1000000000",
"4 3\n1 2 6\n2 3 7\n3 4 7",
"3 3\n1 2 3\n2 3 0\n1 3 4",
"4 3\n1 2 6\n2 3 7\n3 4 3",
"4 3\n1 2 4\n2 3 7\n3 4 7",
"4 3\n1 2 6\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.
Kenkoooo is trying to write a ... |
p03466 AtCoder Grand Contest 020 - Min Max Repetition_37162 | Let f(A, B), where A and B are positive integers, be the string satisfying the following conditions:
* f(A, B) has length A + B;
* f(A, B) contains exactly A letters `A` and exactly B letters `B`;
* The length of the longest substring of f(A, B) consisting of equal letters (ex., `AAAAA` or `BBBB`) is as small as possi... | T=int(input())
for TT in range(T):
a,b,c,d=map(int,input().split(' '))
l,x,y=(a+b)//(min(a,b)+1),0,0
if a*l<=b:
y=a+b
elif b*l<=a:
x=a+b
else:
x,y=(a*l-b)//(l-1),(b*l-a)//(l-1) #Like G2 tong long
out=""
for i in range(c,d+1):
if i<=x:
out+="AB"[i%(l+1)==0]
elif a+b-i+1<=y:
out+="BA"[(a+b-i+1)%(l+... | {
"input": [
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 4 3 7\n8 10 5 8",
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 4 3 7\n8 10 5 14",
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 4 3 7\n8 2 5 8",
"5\n2 3 1 5\n6 4 1 10\n2 3 4 4\n6 7 3 7\n8 10 5 14",
"5\n2 3 1 5\n6 4 1 10\n2 3 6 4\n6 4 3 7\n8 2 5 8",
"5\n2 3 1 5\n9 4 1 10... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let f(A, B), where A and B are positive integers, be the string satisfying the following conditions:
* f(A, B) has length A + B;
* f(A, B) contains exactly A letters `A` and exactly ... |
p03626 AtCoder Beginner Contest 071 - Coloring Dominoes_37166 | We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors... | N = int(input())
grids = [[s for s in input()],[s for s in input()]]
MOD = 1000000007
if grids[0][0] == grids[1][0]:
prv_row_type = 1
ans = 3
posx = 1
else:
prv_row_type = -1
ans = 6
posx = 2
while posx < N:
if grids[0][posx] == grids[1][posx]:
if prv_row_type == 1: ans *= 2
else: ans *= 1
... | {
"input": [
"1\nZ\nZ",
"52\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn",
"3\naab\nccb",
"1\n[\n[",
"52\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\nRLLwwdWIxxNNQUUXXVVMMooCBaggDKqcimmeYrhAljOOTTJuuzzn",
"3\naab\nacc",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square.
Then, Snuke decided to p... |
p03786 AtCoder Grand Contest 011 - Colorful Creatures_37170 | Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.
Every creature can absorb another creature whose size is at most twice the size of itself. When a creature of size A and color B absorbs another creature of siz... | N = int(input())
A = list(map(int, input().split()))
A.sort()
sumA = sum(A)-A[N-1]
memo = 0
for i in range(N-1,-1,-1):
if sumA*2<A[i] or i==0:
memo = i
break
sumA -= A[i-1]
print(N-memo) | {
"input": [
"5\n1 1 1 1 1",
"3\n3 1 4",
"6\n40 1 30 2 7 20",
"5\n1 1 1 1 2",
"3\n3 1 3",
"6\n40 1 26 2 7 20",
"3\n1 1 3",
"6\n7 2 21 2 9 20",
"5\n1 2 1 1 2",
"6\n40 1 26 2 9 20",
"5\n1 2 1 0 2",
"6\n40 1 21 2 9 20",
"5\n1 1 1 0 2",
"6\n40 1 21 1 9 20",
"5\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.
Every creature can abso... |
p03954 AtCoder Grand Contest 006 - Median Pyramid Hard_37174 | We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally. The pyramid is built so that the blocks at the centers of the steps are aligned vertically.
<image>
A pyramid with N=4 steps
Snuke wrote a per... | # def makelist(n, m):
# return [[0 for i in range(m)] for j in range(n)]
N = int(input())
a = [0] + list(map(int, input().split()))
def check(n):
b = [False]*(len(a))
for i in range(1, len(a)):
if a[i] >= n:
b[i] = True
else:
b[i] = False
r = int(1e9)
l = int(1e9)
rb = b[N]
lb = b[N]
for i in range... | {
"input": [
"2\n1 2 3",
"4\n1 6 3 7 4 5 2",
"2\n0 2 3",
"4\n0 6 3 7 4 5 2",
"2\n-1 1 7",
"4\n0 5 3 1 4 9 2",
"4\n-1 5 5 0 8 2 0",
"4\n-2 3 3 7 7 5 0",
"4\n-2 3 3 7 6 1 0",
"2\n-1 2 3",
"4\n0 6 3 4 4 5 2",
"2\n-1 2 5",
"4\n0 4 3 4 4 5 2",
"2\n-1 2 7",
"4\n0 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a pyramid with N steps, built with blocks. The steps are numbered 1 through N from top to bottom. For each 1≤i≤N, step i consists of 2i-1 blocks aligned horizontally. The pyra... |
p00044 Prime Number II_37178 | A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1.
When you enter the integer n, write a program that outputs th... | from math import sqrt, ceil
N = 53000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
if temp[i]:
temp[i+i::i] = [False]*(len(temp[i+i::i]))
while True:
try:
n = int(input())
print(n-1-temp[n-1:0:-1].index(True), n+1+temp[n+1:].index(True))
except ... | {
"input": [
"19\n3517",
"19\n5214",
"19\n3257",
"19\n6476",
"19\n10887",
"19\n17073",
"19\n30085",
"19\n357",
"19\n443",
"19\n631",
"19\n862",
"19\n1431",
"19\n2850",
"19\n995",
"19\n1278",
"19\n507",
"19\n774",
"19\n502",
"19\n734",
"19... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a p... |
p00176 What Color?_37182 | Taro, who aims to become a web designer, is currently training. My senior at the office tells me that the background color of this page is # ffe085, which is a color number peculiar to web design, but I can't think of what kind of color it is.
This color number represents the intensity of each of the three primary col... | COLOR = {
"000000": "black",
"0000ff": "blue",
"00ff00": "lime",
"00ffff": "aqua",
"ff0000": "red",
"ff00ff": "fuchsia",
"ffff00": "yellow",
"ffffff": "white"
}
while True:
input_data = input()
if len(input_data) == 1:
break
color_code = ""
for first, second ... | {
"input": [
"#ffe085\n#787878\n#decade\n#ff55ff\n0",
"ffe085\n787878\ndecade\nff55ff\n0",
"ffe085\n787878\ndfcade\nff55ff\n0",
"#ffe085\n#787878\n\"decade\n#ff55ff\n0",
"8fe0f5\n976991\ndebade\nff55ff\n0",
"8fe0f5\n1006397\ndebade\nff55ff\n0",
"#ffe075\n#787878\n#decade\n#ff55ff\n0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro, who aims to become a web designer, is currently training. My senior at the office tells me that the background color of this page is # ffe085, which is a color number peculiar t... |
p00332 Japanese Calendar_37185 | The "Western calendar" is a concept imported from the West, but in Japan there is a concept called the Japanese calendar, which identifies the "era name" by adding a year as a method of expressing the year on the calendar. For example, this year is 2016 in the Christian era, but 2016 in the Japanese calendar. Both are ... | e, y = map(int,input().split())
if e == 0:
if y < 1912:
a = y - 1867
print("M", a, sep = '')
elif y < 1926:
a = y - 1911
print("T", a, sep = '')
elif y < 1989:
a = y - 1925
print("S", a, sep = '')
elif y < 2017:
a = y - 1988
print("H", a, ... | {
"input": [
"0 2015",
"0 1912",
"4 28",
"2 1",
"4 2",
"3 1",
"1 28",
"2 0",
"3 2",
"4 1",
"1 42",
"1 0",
"3 0",
"4 0",
"1 81",
"2 -1",
"3 -1",
"4 -1",
"1 125",
"1 -1",
"4 -2",
"1 68",
"1 -2",
"4 -4",
"1 36",
"1 -3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The "Western calendar" is a concept imported from the West, but in Japan there is a concept called the Japanese calendar, which identifies the "era name" by adding a year as a method ... |
p00513 Available Areas_37189 | IOI Real Estate rents condominiums. The apartment room handled by this company is 1LDK, and the area is 2xy + x + y as shown in the figure below. However, x and y are positive integers.
Figure_Madori
In the IOI real estate catalog, the areas of condominiums are listed in ascending order (in ascending order), but it... | def check(a):
for i in range(2,int(a**(1/2))+1):
if a%i == 0:
return 1
return 0
n = int(input())
count = 0
for i in range(n):
num = int(input())
if check(2*num+1) == 0:
count += 1
print(count)
| {
"input": [
"None",
"10\n4\n7\n9\n10\n12\n13\n16\n17\n19\n20",
"enoN",
"10\n4\n7\n9\n10\n12\n13\n20\n17\n19\n20",
"10\n8\n7\n8\n10\n12\n13\n20\n17\n19\n20",
"10\n8\n0\n8\n10\n12\n13\n20\n17\n19\n20",
"10\n8\n0\n18\n10\n0\n13\n20\n17\n19\n2",
"10\n8\n0\n18\n10\n0\n13\n3\n3\n19\n3",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
IOI Real Estate rents condominiums. The apartment room handled by this company is 1LDK, and the area is 2xy + x + y as shown in the figure below. However, x and y are positive integer... |
p00690 A Long Ride on a Railway_37193 | Travelling by train is fun and exciting. But more than that indeed. Young challenging boys often tried to purchase the longest single tickets and to single ride the longest routes of various railway systems. Route planning was like solving puzzles. However, once assisted by computers, and supplied with machine readable... | # AOJ 1108: A Long Ride on a Railway
# Python3 2018.7.14 bal4u
def combi(k, a, w):
global len, ans
for b in range(1, n+1):
if b == a: continue
for i in range(m):
if not f[i] and ((tbl[i][0] == a and tbl[i][1] == b) or
(tbl[i][0] == b and tbl[i][1] == a)):
f[i] = 1
tmp[k] = b
co... | {
"input": [
"6 5\n 1 3 10\n 2 3 12\n 3 4 2\n 4 5 13\n 4 6 11\n10 10\n 1 2 11\n 2 3 25\n 2 5 81\n 2 6 82\n 4 5 58\n 5 9 68\n 6 7 80\n 6 9 67\n 8 9 44\n 9 10 21\n 0 0",
"6 5\n1 3 10\n2 3 12\n3 4 2\n4 5 13\n4 6 11\n10 10\n1 2 11\n2 3 25\n2 5 81\n2 6 82\n4 5 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Travelling by train is fun and exciting. But more than that indeed. Young challenging boys often tried to purchase the longest single tickets and to single ride the longest routes of ... |
p00831 Confusing Login Names_37196 | Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facilities including supercomputers and many personal computers connected to the Internet.
One of the policies of the computer center is to le... | from collections import Counter
from itertools import permutations
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
def dist(a, b):
LA = len(a); LB = len(b)
dp = [[10**18]*(LB+1) for i in range(LA+1)]
... | {
"input": [
"8\n2\nomura\ntoshio\nraku\ntanaka\nimura\nyoshoi\nhayashi\nmiura\n3\n1\ntasaka\nnakata\ntanaka\n1\n1\nfoo\n5\n2\npsqt\nabcdef\nabzdefa\npqrst\nabdxcef\n0",
"8\n2\nomura\ntoshio\nraku\ntanaka\ninura\nyoshoi\nhayashi\nmiura\n3\n1\ntasaka\nnakata\ntanaka\n1\n1\nfoo\n5\n2\npsqt\nabcdef\nabzdefa\npqr... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Meikyokan University is very famous for its research and education in the area of computer science. This university has a computer center that has advanced and secure computing facili... |
p00962 Pizza Delivery_37199 | Problem F Pizza Delivery
Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street section between two adjac... | from heapq import heappush, heappop
from collections import deque
import sys
sys.setrecursionlimit(10**6)
n, m = map(int, input().split())
E = []
G = [[] for i in range(n)]
RG = [[] for i in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
E.append((a-1, b-1, c))
G[a-1].append((b-1, c, i))
... | {
"input": [
"4 5\n1 3 5\n3 4 6\n4 2 7\n2 1 18\n2 3 12",
"4 5\n1 3 5\n3 4 6\n4 2 7\n2 1 18\n2 3 17",
"4 5\n1 3 5\n3 4 6\n4 2 7\n2 1 6\n2 3 17",
"4 5\n1 3 5\n3 2 6\n4 2 7\n2 1 18\n2 3 12",
"4 5\n1 3 5\n3 4 6\n4 2 13\n2 1 6\n2 3 17",
"4 1\n1 3 5\n3 2 6\n4 2 7\n2 1 18\n2 3 12",
"8 5\n1 3 5\n3... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem F Pizza Delivery
Alyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative... |
p01095 Bamboo Blossoms_37201 | Bamboo Blossoms
The bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his travel to Tsukuba. He liked the flower so much that he was tempted to make a garden where the bamboos bloom annually. Dr. ACM started resea... | from bisect import bisect_left
def rwh_primes2(n):
# https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
""" Input n>=6, Returns a list of primes, 2 <= p < n """
correction = (n%6>1)
n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
sieve = [True]... | {
"input": [
"3 1\n3 4\n10 20\n100 50\n2 500000\n0 0",
"3 2\n3 4\n10 20\n100 50\n2 500000\n0 0",
"3 2\n3 4\n13 20\n100 50\n2 500000\n0 0",
"3 2\n3 4\n22 20\n100 50\n2 500000\n0 0",
"3 1\n3 4\n10 20\n100 50\n3 500000\n0 0",
"3 2\n3 4\n13 20\n100 50\n4 500000\n0 0",
"3 2\n3 4\n10 20\n100 52\... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bamboo Blossoms
The bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his tr... |
p01847 Curtain_37209 | curtain
Summer is coming soon. You decide to redecorate your room for the summer. It is expected that the sun will be very strong this summer, and it will be a difficult season for you who are not good at dazzling. So you thought about installing a curtain on the window of the room to adjust the brightness of the room... | from collections import defaultdict
INF = 10**9
while 1:
N = int(input())
if N == 0:
break
P = [list(map(int, input().split())) for i in range(N)]
S = defaultdict(list)
X = set()
x0 = y0 = INF; x1 = y1 = -INF
for i in range(4):
x, y = map(int, input().split())
x0 = mi... | {
"input": [
"4\n0 0\n10 0\n10 10\n0 10\n0 0\n5 0\n5 10\n0 10\n6\n0 0\n10 0\n10 5\n5 5\n5 10\n0 10\n2 0\n8 0\n8 10\n2 10\n12\n1 1\n1 3\n-1 3\n-1 1\n-3 1\n-3 -1\n-1 -1\n-1 -3\n1 -3\n1 -1\n3 -1\n3 1\n2 2\n-2 2\n-2 -2\n2 -2\n4\n20000 20000\n-20000 20000\n-20000 -20000\n20000 -20000\n1000 1000\n-1000 1000\n-1000 -100... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
curtain
Summer is coming soon. You decide to redecorate your room for the summer. It is expected that the sun will be very strong this summer, and it will be a difficult season for y... |
p01983 Proof of Knowledge_37212 | Proof of knowledge
The entrance door of the apartment you live in has a password-type lock. This password consists of exactly four digits, ranging from 0 to 9, and you always use the password P given to you by the apartment manager to unlock this door.
One day, you wondered if all the residents of the apartment were ... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
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.... | {
"input": [
"[+c[+a[^bd]]]\n0404\n[*b[*[*cd]a]]\n7777\n[^[^ab][^cd]]\n1295\na\n9876\n[^dd]\n9090\n.",
"[+c[+a[^bd]]]\n0404\n[*b[*[*cd]a]]\n7777\n[^[^ab][^cd]]\n2570\na\n9876\n[^dd]\n9090\n.",
"[+c[*a[^bd]]]\n0404\n[*b[*[*cd]a]]\n7777\n[^[^ab][^cd]]\n2570\na\n9876\n[^dd]\n9090\n.",
"[+c[^a[+bd]]]\n040... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Proof of knowledge
The entrance door of the apartment you live in has a password-type lock. This password consists of exactly four digits, ranging from 0 to 9, and you always use the... |
p02129 Ghost Legs_37215 | Problem
There are $ N $ Amidakuji with 3 vertical lines.
No matter which line you start from, the Amidakuji that ends at the starting line is considered a good Amidakuji.
You can select one or more Amidakuji and connect them vertically in any order.
Output "yes" if you can make a good Amidakuji, otherwise output "no".... | def amida():
line = list(map(int, input().split()))[1:]
res = [0, 1, 2]
for i in line:
if i:
res[1], res[2] = res[2], res[1]
else:
res[0], res[1] = res[1], res[0]
return res
def func(x, line, flag):
if line == [0, 1, 2] and flag:
return True
for ... | {
"input": [
"3\n2 0 0\n1 1\n5 1 0 0 1 0",
"2\n1 1\n1 0",
"3\n2 0 0\n1 1\n10 1 0 0 1 0",
"2\n1 1\n3 0",
"2\n1 1\n2 0",
"3\n2 0 0\n1 1\n10 1 0 0 2 0",
"2\n1 0\n2 0",
"3\n3 0 0\n1 1\n10 1 0 0 2 0",
"2\n1 1\n2 -1",
"3\n3 0 0\n1 1\n10 2 0 0 2 0",
"2\n1 1\n2 -2",
"3\n3 0 0\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
There are $ N $ Amidakuji with 3 vertical lines.
No matter which line you start from, the Amidakuji that ends at the starting line is considered a good Amidakuji.
You can sel... |
p02270 Allocation_37218 | You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each truck can load consecutive packages (more than or equals to zero) from the belt conveyor unless the total weights of the packages in the s... | from sys import stdin
def binSearch(k, p_min, p_max):
global w
while p_max-p_min > 1:
mid = p_min + (p_max-p_min)//2
if k >= countTrack(w, mid):
p_max = mid
else:
p_min = mid
return p_max
def countTrack(w, p):
rest = []
for wi in w:
if len(r... | {
"input": [
"5 3\n8\n1\n7\n3\n9",
"4 2\n1\n2\n2\n6",
"5 3\n4\n1\n7\n3\n9",
"4 2\n1\n1\n2\n6",
"5 3\n4\n1\n7\n3\n5",
"5 6\n4\n1\n7\n3\n5",
"4 2\n1\n1\n3\n1",
"4 2\n1\n1\n3\n0",
"4 2\n1\n4\n3\n0",
"5 3\n6\n2\n8\n5\n4",
"5 3\n6\n2\n8\n7\n4",
"5 3\n8\n2\n9\n7\n5",
"5 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given $n$ packages of $w_i$ kg from a belt conveyor in order ($i = 0, 1, ... n-1$). You should load all packages onto $k$ trucks which have the common maximum load $P$. Each t... |
p02417 Counting Characters_37222 | Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
Constraints
* The number of characters in the sentence < 1200
Input
A sentence in English is given in several lines.
Output
Prints the number of alphabetical letters in the following format:
a : The n... | import sys
x=sys.stdin.read().lower()
for i in range(97,123):
print(chr(i),':',x.count(chr(i)))
| {
"input": [
"This is a pen.",
"This is ` pen.",
"This si a pen.",
"hTit si a pen.",
"hTis ir a pen.",
"hTis ri a pdn.",
"hTis ri a odn.",
"hTis ri a odo.",
"hsiT rh a od.o",
"Tsih is a od-o",
"Tsih is ` od-o",
"ihsT it ` od-o",
"ihsU it ` od-o",
"ihrU it ` od-o... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which counts and reports the number of each alphabetical letter. Ignore the case of characters.
Constraints
* The number of characters in the sentence < 1200
Input
... |
1006_B. Polycarp's Practice_37232 | Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a_1, a_2, ..., a_n, respectively. His plan is to practice for exactly k days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip ... | # Accepted:
isVerbose = False
def v(msg):
if isVerbose:
print(msg)
n, k = map(int, input().split())
nums = list(enumerate(map(int, input().split())))
#print(n, k)
#print(nums)
nums.sort(key=lambda tup:tup[1])
#print(nums)
nums_top = nums[-min(k, n):]
#print(nums_top)
nums_top.sort(key=lambda tup:tup[0])... | {
"input": [
"8 3\n5 4 2 6 5 1 9 2\n",
"4 2\n1 2000 2000 2\n",
"5 1\n1 1 1 1 1\n",
"8 3\n5 4 2 6 5 1 9 2\n",
"5 3\n2 2 2 3 3\n",
"8 3\n15 14 11 19 17 14 14 8\n",
"6 4\n1 1 1 1 2 2\n",
"1 1\n1996\n",
"6 5\n1 1 6 6 6 6\n",
"5 3\n5 5 6 7 1\n",
"8 4\n1 2 2 2 2 3 4 5\n",
"18... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a_1, a_2, ..., a_n, respectively. His plan is to practice for exactly k days. Each day ... |
102_A. Clothes_37236 | A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.
Overall the shop sells n clothing items, and exactly m pairs of clothing items match. Each item has i... | I=lambda:map(int,input().split())
n,m=I()
N=list(I())
p=set()
for i in range(m):
x,y=I();x-=1;y-=1
p.add((x,y)if x<y else(y,x))
r=1e9
for i in range(n):
for j in range(i):
for k in range(j):
if(j,i)in p and(k,i)in p and(k,j)in p:
r = min(r,N[i]+N[j]+N[k])
print(-1 if r>1e8 else r) | {
"input": [
"4 4\n1 1 1 1\n1 2\n2 3\n3 4\n4 1\n",
"3 3\n1 2 3\n1 2\n2 3\n3 1\n",
"3 2\n2 3 4\n2 3\n2 1\n",
"3 3\n1000000 1000000 1000000\n2 1\n1 3\n3 2\n",
"4 3\n10 10 5 1\n2 1\n3 1\n3 4\n",
"4 3\n1 2 8 6\n1 3\n1 4\n3 4\n",
"6 8\n69 36 41 23 91 35\n1 2\n3 1\n3 2\n1 4\n3 4\n3 5\n5 4\n4 6\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in ... |
1051_A. Vasya And Password_37240 | Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.
But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin l... |
def check( s, L, R ):
for i in s:
if i>=L and i<=R:
return False
return True
def ok(s):
low = True;
for i in s:
if i>='a' and i<='z':
low = False;
break
if low :
return False
low = True;
for i in s:
if i>='A' and i<='Z':
low = False;
break
if low :
return False
low = True;
f... | {
"input": [
"2\nabcDCE\nhtQw27\n",
"1\nA00\n",
"1\na00\n",
"1\n825\n",
"1\nNV641\n",
"1\naAbAcDeF\n",
"1\n000\n",
"6\n11b\n4bh\nBeh\nTuY\n1YJ\nP28\n",
"1\nM62H\n",
"3\nafd\n142\nTRE\n",
"2\nabcDCE\nhtQw27\n",
"4\nYtG3\n33Yo\n123n\nm23m\n",
"1\n0a0\n",
"1\nWK7S\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.
Bu... |
1073_B. Vasya and Books_37244 | Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one — a_2, and so on. The book at the bottom of the stack has number a_n. All numbers are distinct.
Vasya wants to move all the books to his backpack in n steps. During i-th step he wants to move the book number... | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from functools import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout ... | {
"input": [
"3\n1 2 3\n2 1 3\n",
"6\n6 5 4 3 2 1\n6 5 3 4 2 1\n",
"5\n3 1 4 2 5\n4 5 1 3 2\n",
"1\n1\n1\n",
"10\n4 7 10 2 1 8 3 5 9 6\n4 2 7 1 8 10 5 3 9 6\n",
"7\n7 6 3 1 5 4 2\n2 3 1 6 4 7 5\n",
"5\n3 1 4 2 5\n4 5 1 3 3\n",
"7\n7 6 3 1 5 4 2\n2 3 1 6 4 7 7\n",
"5\n3 1 4 2 5\n2 5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya has got n books, numbered from 1 to n, arranged in a stack. The topmost book has number a_1, the next one — a_2, and so on. The book at the bottom of the stack has number a_n. A... |
1095_B. Array Stabilization_37248 | You are given an array a consisting of n integer numbers.
Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i.
You have to remove exactly one element from this array to minimize instability of the resulting (n-1)-elements array. Your task is to calculate the minimum possible... | input()
sequence = [int(i) for i in input().split(' ')]
sequence.sort()
a, b = sequence[-2] - sequence[0], sequence[-1] - sequence[1]
print(a) if a < b else print(b) | {
"input": [
"4\n1 3 3 7\n",
"2\n1 100000\n",
"30\n28 69 21 75 45 3 30 78 95 30 49 53 29 50 44 90 15 47 84 88 15 80 29 83 12 43 36 71 75 23\n",
"6\n67 100 5 97 83 85\n",
"60\n36 91 2 38 37 49 48 11 59 67 53 56 35 60 87 59 60 16 73 34 15 4 57 40 38 44 4 80 63 26 94 99 68 47 88 4 96 36 15 54 54 19 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an array a consisting of n integer numbers.
Let instability of the array be the following value: max_{i = 1}^{n} a_i - min_{i = 1}^{n} a_i.
You have to remove exactly ... |
1114_C. Trailing Loves (or L'oeufs?)_37252 | The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number 9200 has two trailing zeros. Aki thinks the more trailing zero digits a n... | import math
from collections import Counter
def checkprime(x):
if x==1:
return False
i=2
while i*i<=x:
if x%i==0:
return False
i+=1
return True
def pfactors(n):
lt=[]
while n % 2 == 0:
lt.append(2)
n = (n // 2)
for i in range(3,int(math.sqr... | {
"input": [
"6 9\n",
"5 2\n",
"5 10\n",
"38 11\n",
"36 110075314176\n",
"36 322687697779\n",
"912222 250880942892\n",
"72 250880942892\n",
"72 999999998141\n",
"912222 193773\n",
"57 10080\n",
"1000000000000000000 64339296875\n",
"14 10080\n",
"72 30\n",
"8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers... |
1183_E. Subsequences (easy version)_37261 | The only difference between the easy and the hard versions is constraints.
A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th... | R = lambda: map(int, input().split())
n,k = R()
s = input()
p = [s]
ans = 0
d= set()
while p:
q = p.pop(0)
if q not in d:
k -= 1
ans += (n-len(q))
if k == 0:
print(ans)
quit()
d.add(q)
for i in range(len(q)):
t = q[:i]+q[i+1:]
... | {
"input": [
"4 5\nasdf\n",
"5 6\naaaaa\n",
"5 7\naaaaa\n",
"10 100\najihiushda\n",
"1 50\ns\n",
"100 20\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"50 10\ndnovfytvosvwbeykfnkkebgonntfqapbuphspjsclowovrgrae\n",
"100 50\nmhn... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The only difference between the easy and the hard versions is constraints.
A subsequence is a string that can be derived from another string by deleting some or no symbols without ch... |
1200_F. Graph Traveler_37264 | Gildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_i outgoing edges that are labeled as e_i[0], e_i[1], …, e_i[m_i-1], each representing the destination vertex of the edge. The graph can h... | import io, sys
input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip()
LCM = 2520
n = int(input())
k = list(map(int, input().split()))
m, e = [0] * n, [None] * n
for i in range(n):
m[i] = int(input())
e[i] = list(map(int, input().split()))
nxt = []
for i in range(n):
for j in... | {
"input": [
"4\n0 0 0 0\n2\n2 3\n1\n2\n3\n2 4 1\n4\n3 1 2 1\n6\n1 0\n2 0\n3 -1\n4 -2\n1 1\n1 5\n",
"4\n4 -5 -3 -1\n2\n2 3\n1\n2\n3\n2 4 1\n4\n3 1 2 1\n6\n1 0\n2 0\n3 -1\n4 -2\n1 1\n1 5\n",
"1\n0\n1\n1\n1\n1 0\n",
"4\n0 0 0 0\n2\n2 3\n1\n2\n3\n2 4 1\n4\n3 1 2 2\n6\n1 0\n2 0\n3 -1\n4 -2\n1 1\n1 5\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gildong is experimenting with an interesting machine Graph Traveler. In Graph Traveler, there is a directed graph consisting of n vertices numbered from 1 to n. The i-th vertex has m_... |
1284_A. New Year and Naming_37273 | Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.
There are two sequences of n strings s_1, s_2, s_3, …, s_{n} and m strings t_1, t_2, t_3, …, t_{m}. ... | from sys import stdin, stdout
def main():
(n1, n2) = tuple([int(x) for x in stdin.readline().split()])
arr1 = [x for x in stdin.readline().split()]
arr2 = [x for x in stdin.readline().split()]
q = int(stdin.readline())
res = []
for i in range(0, q):
year = int(stdin.readline())
... | {
"input": [
"10 12\nsin im gye gap eul byeong jeong mu gi gyeong\nyu sul hae ja chuk in myo jin sa o mi sin\n14\n1\n2\n3\n4\n10\n11\n12\n13\n73\n2016\n2017\n2018\n2019\n2020\n",
"2 6\na a\nb b c d e f\n1\n3\n",
"5 2\na b c d e\nhola mundo\n1\n5\n",
"10 12\nsin im gye gap eul byeong jeong mu gi gyeong... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditional... |
1303_C. Perfect Keyboard_37277 | Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 26 lowercase Latin letters will be arranged in some order.
Polycarp uses the same password s on all websites where he is registered (it is bad, but he doesn't care)... | ''' Hey stalker :) '''
INF = 10**10
def main():
print = out.append
''' Cook your dish here! '''
st = list(input())
keyboard = []
if len(set(st))>1:
adj = defaultdict(set)
for i in range(len(st)-1):
adj[st[i]].add(st[i+1])
adj[st[i+1]].add(st[i])
c1 = 0... | {
"input": [
"5\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghijklmnopqrstuvwxyza\n",
"5\nababa\ncodedoca\nabcda\nzxzytyz\nabcdefghjjklmnopqrstuvwxyza\n",
"5\nababa\ncodedoca\nabcda\nzxtyzyz\nazyxwvutsrqponmlkjjhgfedcba\n",
"5\nababa\ncodfdoca\nabcda\nzxzytyz\nabcdefghjjklmnopqrstuvwxyza\n",
"5\nababa... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all 26 lowercase Latin letters w... |
1327_D. Infinite Path_37281 | You are given a colored permutation p_1, p_2, ..., p_n. The i-th element of the permutation has color c_i.
Let's define an infinite path as infinite sequence i, p[i], p[p[i]], p[p[p[i]]] ... where all elements have same color (c[i] = c[p[i]] = c[p[p[i]]] = ...).
We can also define a multiplication of permutations a a... | def monocolor_subcycle(start, divisor):
for i in range(start, len(cycle), divisor):
v = cycle[i]
if c[v] != c[cycle[start]]:
return False
return True
def any_monocolor_subcycle(divisor):
for start in range(divisor):
if monocolor_subcycle(start, divisor):
ret... | {
"input": [
"3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n",
"3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 3 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 8 7 5 8 4\n",
"3\n4\n1 3 4 2\n1 2 2 3\n5\n2 3 4 5 1\n1 2 5 4 5\n8\n7 4 5 6 1 8 3 2\n5 3 6 4 7 5 8 4\n",
"3\n4\n1 3 4 2\n1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a colored permutation p_1, p_2, ..., p_n. The i-th element of the permutation has color c_i.
Let's define an infinite path as infinite sequence i, p[i], p[p[i]], p[p[p[... |
1368_D. AND, OR and square sum_37285 | Gottfried learned about binary number representation. He then came up with this task and presented it to you.
You are given a collection of n non-negative integers a_1, …, a_n. You are allowed to perform the following operation: choose two distinct indices 1 ≤ i, j ≤ n. If before the operation a_i = x, a_j = y, then a... | from sys import stdin
input = stdin.readline
n = int(input())
a = [*map(lambda x: bin(int(x))[:1:-1], input().split())]
c1 = len(max(a, key=len))
a = [x + '0' * (c1 - len(x)) for x in a]
b = [sum(c[i] == '1' for c in a) for i in range(c1)]
c2 = max(b)
ans = 0
for i in range(c2):
num = ''
for i in range(c1):
if b[i]... | {
"input": [
"1\n123\n",
"3\n1 3 5\n",
"2\n349525 699050\n",
"10\n35 516 92 57 58 161 273 664 567 8\n",
"1\n0\n",
"1\n1048575\n",
"5\n991 143 445 903 399\n",
"37\n1048575 327657 1046479 686078 513773 589787 387035 736754 1038077 1048056 59263 753353 784318 647131 519679 294910 185560 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Gottfried learned about binary number representation. He then came up with this task and presented it to you.
You are given a collection of n non-negative integers a_1, …, a_n. You a... |
1389_F. Bicolored Segments_37288 | You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i.
Let's call a pair of segments i and j bad if the following two conditions are met:
* t_i ≠ t_j;
* the segments [l_i, r_i] and [l_j, r_j] intersect, embed or touch, i. e. there ex... | from operator import add
class LazySegmentTree():
def __init__(self,n,init,merge=max,merge_unit=-10**18,operate=add,operate_unit=0):
self.merge=merge
self.merge_unit=merge_unit
self.operate=operate
self.operate_unit=operate_unit
self.n=(n-1).bit_length()
self.data=[... | {
"input": [
"7\n19 20 1\n13 15 2\n6 11 2\n4 10 1\n14 17 1\n13 13 2\n5 9 1\n",
"5\n5 8 1\n1 3 2\n3 4 2\n6 6 1\n2 10 2\n",
"3\n1 3 1\n4 6 2\n2 5 1\n",
"10\n1 20 1\n11 17 2\n3 15 2\n3 9 2\n3 14 1\n16 18 2\n6 9 2\n13 17 2\n10 17 2\n7 13 1\n",
"12\n1 2 2\n6 7 2\n2 4 1\n3 7 2\n5 5 2\n1 5 1\n2 2 1\n4 7 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n]. Each segment has one of two colors: the i-th segment's color is t_i.
Let's call a pair of segments i and j bad if th... |
140_C. New Year Snowmen_37292 | As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made n snowballs with radii equal to r1, r2, ..., rn. To make a snowman, one needs any thr... | #!/usr/bin/env python3
from heapq import *
from collections import defaultdict
n = int(input())
r = map(int, input().split())
H = defaultdict(int)
for t in r:
H[t] += 1
D = [(-1 * v, k) for k, v in H.items()]
heapify(D)
ret = []
while len(D) > 2:
a, b, c = heappop(D), heappop(D), heappop(D)
ret.append(so... | {
"input": [
"7\n1 2 3 4 5 6 7\n",
"3\n2 2 3\n",
"6\n1 2 2 3 4 5\n",
"12\n1 1 1 2 2 2 3 3 3 4 4 4\n",
"20\n7 6 6 7 2 2 2 2 2 6 1 5 3 4 5 7 1 6 1 4\n",
"6\n1 1 2 2 2 2\n",
"12\n4 4 4 3 3 3 2 2 2 1 1 1\n",
"20\n4 2 2 2 5 2 4 2 2 3 5 2 1 3 1 2 2 5 4 3\n",
"12\n2 2 2 3 3 3 4 4 4 5 5 5\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small... |
1430_G. Yet Another DAG Problem_37295 | You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the weight w_i.
Your task is to select an integer a_v for each vertex v, and then write a number b_i on each arcs i such that b_i = a_{x_i} -... | from heapq import heappush, heappop
class MinCostFlow:
INF = 10**18
def __init__(self, N):
self.N = N
self.G = [[] for i in range(N)]
def add_edge(self, fr, to, cap, cost):
forward = [to, cap, cost, None]
backward = forward[3] = [fr, 0, -cost, forward]
self.G[fr].ap... | {
"input": [
"5 4\n1 2 1\n2 3 1\n1 3 6\n4 5 8\n",
"3 2\n2 1 4\n1 3 2\n",
"5 5\n1 2 1\n2 3 1\n3 4 1\n1 5 1\n5 4 10\n",
"18 27\n3 16 55467\n17 11 829\n5 12 15831\n14 6 24056\n5 2 63216\n15 6 38762\n2 6 10654\n12 6 51472\n11 9 79384\n1 6 67109\n5 13 86794\n7 6 74116\n10 3 44030\n5 7 71499\n16 17 33019\n5... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a directed acyclic graph (a directed graph that does not contain cycles) of n vertices and m arcs. The i-th arc leads from the vertex x_i to the vertex y_i and has the w... |
1454_C. Sequence Transformation_37299 | You are given a sequence a, initially consisting of n integers.
You want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the same element).
To achieve this, you choose some integer x that occurs at least once in a, and then perform the following operation any ... | for _ in range(int(input())):
n = int(input())
x = list(map(int, input().split()))
o = {x[0]: [0]}
for i in range(1, n):
if x[i] in o:
o[x[i]].append(i)
else:
o[x[i]] = [i]
m = n
if len(o) == 1:
print(0)
else:
for k, l in o.items():
... | {
"input": [
"5\n3\n1 1 1\n5\n1 2 3 4 5\n5\n1 2 3 2 1\n7\n1 2 3 1 2 3 1\n11\n2 2 1 2 3 2 1 2 3 1 2\n",
"1\n17\n1 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 1\n",
"1\n13\n12 12 12 12 12 12 12 12 12 12 12 12 13\n",
"1\n13\n12 12 12 12 12 12 12 12 3 12 12 12 13\n",
"1\n13\n12 12 12 13 12 5 12 12 3 7 1 12 13\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a sequence a, initially consisting of n integers.
You want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the... |
1478_A. Nezzar and Colorful Balls_37303 | Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that a_i ≤ a_{i+1} for all 1 ≤ i < n.
Nezzar wants to color the balls using the minimum number of colors, such that the following holds.
... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = set(a)
maxBall = 0
for i in b:
if a.count(i)>maxBall:
maxBall=a.count(i)
print(maxBall) | {
"input": [
"5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n1 2 3\n1\n1\n",
"5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n2 2 3\n1\n1\n",
"5\n6\n1 1 1 2 3 3\n5\n1 1 2 2 3\n4\n1 2 2 2\n3\n2 2 3\n1\n1\n",
"5\n6\n1 1 2 2 3 3\n5\n1 1 2 2 3\n4\n1 2 2 2\n3\n2 2 3\n1\n1\n",
"5\n6\n1 1 1 2 3 6\n5\n1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Nezzar has n balls, numbered with integers 1, 2, …, n. Numbers a_1, a_2, …, a_n are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means t... |
1505_D. Xenolith? Hippodrome?_37306 |
Input
The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.
Output
Output "YES" or "NO".
Examples
Input
2 3
Output
YES
Input
3 2
Output
NO
Input
33 16
Output
YES
Input
26 5
Output
NO | import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.... | {
"input": [
"2 3\n",
"33 16\n",
"26 5\n",
"3 2\n",
"4 3\n",
"33 6\n",
"10 5\n",
"2 2\n",
"5 3\n",
"33 9\n",
"14 5\n",
"2 4\n",
"12 9\n",
"10 6\n",
"2 5\n",
"16 9\n",
"10 3\n",
"1 9\n",
"11 3\n",
"1 2\n",
"11 5\n",
"11 6\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Input
The input contains two integers N, M (1 ≤ N ≤ 1024, 2 ≤ M ≤ 16), separated by a single space.
Output
Output "YES" or "NO".
Examples
Input
2 3
Output
YES
Input
3... |
1528_D. It's a bird! No, it's a plane! No, it's AaParsa!_37309 | There are n cities in Shaazzzland, numbered from 0 to n-1. Ghaazzzland, the immortal enemy of Shaazzzland, is ruled by AaParsa.
As the head of the Ghaazzzland's intelligence agency, AaParsa is carrying out the most important spying mission in Ghaazzzland's history on Shaazzzland.
AaParsa has planted m transport canno... | import sys
input = lambda: sys.stdin.readline().rstrip()
def dijkstra(n, E, i0=0):
D = [1 << 30] * n
D[i0] = 0
Q = set([i for i in range(n)])
while Q:
d = 1 << 30
for q in Q:
if D[q] < d:
i = q
d = D[q]
Q.remove(i)
for j, w in ... | {
"input": [
"6 6\n0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 1\n",
"4 5\n0 1 1\n1 3 2\n2 2 10\n3 0 1\n0 0 2\n",
"3 4\n0 1 1\n0 2 3\n1 0 1\n2 0 1\n",
"3 3\n0 0 1000000000\n1 1 1000000000\n2 2 1000000000\n",
"8 33\n0 5 1\n0 3 2\n0 7 9\n1 5 3\n1 7 6\n1 2 17\n1 4 3\n2 7 3\n2 0 1\n2 3 7\n2 5 6\n2 2 3\n3 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cities in Shaazzzland, numbered from 0 to n-1. Ghaazzzland, the immortal enemy of Shaazzzland, is ruled by AaParsa.
As the head of the Ghaazzzland's intelligence agency, ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.