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 |
|---|---|---|---|---|---|
285_B. Find Marble_14186 | Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position s. Then he performs some (pos... | from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
if arrber_of_variables>=2:
return map(int,sys.stdin.readline(... | {
"input": [
"4 3 4\n1 2 3 4\n",
"4 3 3\n4 1 3 2\n",
"4 2 1\n2 3 4 1\n",
"3 1 3\n2 1 3\n",
"100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note tha... |
30_B. Codeforces World Finals_14190 | The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for training and competing. Recently Copa understood that to conquer the world he needs to organize the world Codeforces tournament. He hopes that a... | from itertools import *
import sys
m=[32,29,32,31,32,31,32,32,31,32,31,32]
s,t=[map(int,input().split('.')) for _ in range(2)]
g=False
a,b,c=s
for d,e,f in permutations(t):
g|=b<13 and e<13 and a<m[b-1]+(b==2)*(c%4==0)and d<m[e-1]+(e==2)*(f%4==0)and(c-f>18 or(c-f==18 and(b>e or(b==e and(a>=d)))))
print(["NO","YES"][g]... | {
"input": [
"20.10.20\n10.02.30\n",
"28.02.74\n28.02.64\n",
"01.01.98\n01.01.80\n",
"02.05.90\n08.03.50\n",
"29.02.80\n29.02.60\n",
"15.12.62\n17.12.21\n",
"08.07.20\n27.01.01\n",
"09.05.55\n25.09.42\n",
"28.02.20\n11.01.29\n",
"06.08.91\n05.12.73\n",
"31.05.20\n02.12.04\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The king Copa often has been reported about the Codeforces site, which is rapidly getting more and more popular among the brightest minds of the humanity, who are using it for trainin... |
3_B. Lorry_14201 | A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times b... | n, v = map(int, input().split())
a = []
b = []
for i in range(n):
typ, carry = map(int, input().split())
if typ == 1:
a.append([carry, i + 1])
else:
b.append([carry, i + 1])
a.sort(reverse=True)
b.sort(reverse=True)
for i in range(1, len(a)):
a[i][0] += a[i - 1][0]
for i in range(1, min... | {
"input": [
"3 2\n1 2\n2 7\n1 3\n",
"20 19\n2 47\n1 37\n1 48\n2 42\n2 48\n1 38\n2 47\n1 48\n2 47\n1 41\n2 46\n1 28\n1 49\n1 45\n2 34\n1 43\n2 29\n1 46\n2 45\n2 18\n",
"10 14\n2 230\n2 516\n2 527\n2 172\n2 854\n2 61\n1 52\n2 154\n2 832\n2 774\n",
"5 3\n1 9\n2 9\n1 9\n2 10\n1 6\n",
"1 1\n1 600\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kay... |
471_C. MUH and House of Cards_14208 | Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make:
1. The house consists of some non-zero number of floors.
2. Each ... | print((lambda n: len([1 for x in range(1, int((-1 + (24 * n + 25) ** 0.5) / 6) + 1) if not (n - 2 * x) % 3]))(int(input())))
| {
"input": [
"13\n",
"6\n",
"153\n",
"99\n",
"154\n",
"3\n",
"98\n",
"1000000000000\n",
"571684826707\n",
"152\n",
"663938115190\n",
"903398973606\n",
"420182289478\n",
"155\n",
"1\n",
"4\n",
"178573947413\n",
"1894100308\n",
"2\n",
"156\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck... |
495_D. Obsessive String_14212 | Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how many ways are there to extract k ≥ 1 non-overlapping substrings from... | def main():
s, t = input(), input()
n, m = len(s), len(t)
t = '$'.join((t, s))
p = [0]
k = 0
for i in range(1, n + m + 1):
while k and t[k] != t[i]:
k = p[k - 1]
if t[k] == t[i]:
k += 1
p.append(k)
ans = [0] * n
sums = [0] * (n + 1)
cur... | {
"input": [
"ababa\naba\n",
"ddd\nd\n",
"welcometoroundtwohundredandeightytwo\nd\n",
"a\naa\n",
"a\na\n",
"vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns\n",
"ababababab\nabab\n",
"a\nb\n",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv\n",
"kpjmaw... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired an... |
51_B. bHTML Tables Analisys_14216 | In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
TABLE ::= <table>ROWS</table>
ROWS ::= ROW | ROW ROWS
ROW ::= <tr>CELLS</tr>
... | #amros
import sys
R=str.replace
s=R(R(R(R(R(''.join(sys.stdin.readlines()),'\n',''),'</tr>',''),'<tr>',''),'><',' '),'>','').split()[1:]
def f(k):
r=0;a=[]
while s[0]!='/table':
if s[0]=='table':
s.pop(0);a+=f(k+1)
else:r+=s[0]=='td';s.pop(0)
s.pop(0)
return[r]+a
print(' '.join(map(str,sorted(f(1))))) | {
"input": [
"<table><tr><td></td></tr></table>\n",
"<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></t... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it sa... |
546_C. Soldier and Cards_14220 | Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
The rules are following. On each turn a fi... | '''input
4
2 1 3
2 4 2
'''
n = int(input())
a = tuple(map(int, input().split()))[1:]
b = tuple(map(int, input().split()))[1:]
c = 0
s = set()
res = 0
while (a, b) not in s:
if not a:
res = 2
break
if not b:
res = 1
break
s.add((a, b))
x, y = a[0], b[0]
a, b =... | {
"input": [
"4\n2 1 3\n2 4 2\n",
"3\n1 2\n2 1 3\n",
"10\n8 1 6 5 3 8 7 10 4\n2 9 2\n",
"9\n8 4 8 5 6 3 2 7 1\n1 9\n",
"10\n2 7 5\n8 9 3 2 4 6 8 1 10\n",
"7\n6 3 5 2 1 6 4\n1 7\n",
"10\n9 8 7 6 2 3 5 4 10 1\n1 9\n",
"5\n4 1 5 3 2\n1 4\n",
"5\n2 2 1\n3 4 5 3\n",
"3\n2 3 2\n1 1\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it... |
594_C. Edo and Magnets_14224 | Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door must be rectangle, and both the length and the width of the door must be posit... | from sys import*
#
def check(u, d, l, r):
used = [pointsx[i][1] for i in range(l)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(set(used)) > k:
return DOHERA
dx = pointsx[-1 - r][0] - points... | {
"input": [
"4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n",
"3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n",
"3 0\n1 1 2 2\n1 1 1000000000 1000000000\n1 3 8 12\n",
"2 1\n1 1 1000000000 1000000000\n100 200 200 300\n",
"1 0\n1 1 100 100\n",
"2 1\n1 1 1000000000 2\n1 1 2 1000000000\n",
"1 0\n1 1 1000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door th... |
616_A. Comparing Two Long Integers_14228 | You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge... | a = input()
b = input()
if len(a)>len(b):
gap = len(a)-len(b)
new = ''
for _ in range(gap):
new+='0'
b = new + b
elif len(b)>len(a):
gap = len(b) - len(a)
new = ''
for _ in range(gap):
new+='0'
a = new + a
for i in range(0,len(a)):
if(a[i]>b[i]):
print('>')
... | {
"input": [
"11\n10\n",
"9\n10\n",
"0123\n9\n",
"0123\n111\n",
"00012345\n12345\n",
"02\n01\n",
"00\n01\n",
"0\n0\n",
"00\n10\n",
"8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n14601756337012016152850479758062064709937081... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large ... |
635_B. Island Puzzle_14232 | A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one o... | n=int(input())
a=input().split()
b=input().split()
a.remove('0')
b.remove('0')
k=a.index(b[0])
a=a[k:]+a[:k]
if a==b:
print('YES')
else:
print('NO')
# Made By Mostafa_Khaled | {
"input": [
"3\n1 0 2\n2 0 1\n",
"4\n1 2 3 0\n0 3 2 1\n",
"2\n1 0\n0 1\n",
"10\n2 4 8 3 6 1 9 0 5 7\n3 6 1 9 0 5 7 2 8 4\n",
"4\n1 2 3 0\n1 0 2 3\n",
"4\n0 2 3 1\n1 2 3 0\n",
"4\n0 1 2 3\n1 0 2 3\n",
"9\n3 8 4 6 7 1 5 2 0\n6 4 8 5 3 1 2 0 7\n",
"4\n1 0 2 3\n1 0 2 3\n",
"10\n2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, a... |
664_A. Complicated GCD_14236 | Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid algorithm.
Formally, find the biggest integer d, such that all int... | a,b=map(int,input().split())
print(a) if a==b else print(1) | {
"input": [
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n",
"1 2\n",
"12345 67890123456789123457\n",
"87 2938984237482934238\n",
"8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 4992490226229... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algor... |
688_D. Remainders Game_14240 | Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winnin... | from math import *
n,k=map(int,input().split())
arr=list(map(int,input().split()))
flag=0
if(k==1):
print('Yes')
else:
arr1=[]
temp=k
for i in range(2,k+1):
if(temp%i==0):
cnt=0
while(temp%i==0):
cnt+=1
temp=temp//i
arr1.append(... | {
"input": [
"4 5\n2 3 5 12\n",
"2 7\n2 3\n",
"10 4\n2 2 2 2 2 2 2 2 2 2\n",
"1 125\n5\n",
"8 32\n2 2 2 2 2 2 2 2\n",
"1 8\n2\n",
"12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766\n",
"2 16\n8 8\n",
"1 1\n1\n",
"2 16\n8 4\n",
"91 4900\n630 630 70 630 910 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today Pari and Arya are playing a game called Remainders.
Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n anci... |
710_C. Magic Odd Square_14244 | Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.
Input
The only line contains odd integer n (1 ≤ n ≤ 49).
Output
Print n lines with n integers. All the integers should be different and from 1 to n2. The sum in each row, column and both main di... | n = int(input())
if n==1:
print(1)
exit()
odd = 1
evn = 2
table = [[0 for i in range(n)] for i in range(n)]
#(x,y) x row, y col
for x in range(n):
for y in range(n):
x1 = min(x, n-1-x)
if y < (n - 1)/2-x1 or y > (n - 1)/2+x1: #even con
table[x][y] = evn
... | {
"input": [
"1\n",
"3\n",
"45\n",
"11\n",
"31\n",
"7\n",
"47\n",
"19\n",
"5\n",
"49\n",
"43\n",
"33\n",
"21\n",
"9\n",
"13\n",
"35\n",
"23\n",
"17\n",
"39\n",
"15\n",
"29\n",
"37\n",
"25\n",
"27\n",
"41\n",
"53\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd.
Input
The only line contains odd integer n (1 ≤ n ≤ 49).
O... |
731_C. Socks_14248 | Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.
Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clo... | from collections import defaultdict, deque
from sys import stdin, stdout
def dfs(visited, node_idx, graph, color_count, sock_colors):
visited[node_idx] = True
color_count[sock_colors[node_idx]] += 1
count = 1
for nbor_idx in graph[node_idx]:
if not visited[nbor_idx]:
count += dfs(v... | {
"input": [
"3 2 3\n1 2 3\n1 2\n2 3\n",
"3 2 2\n1 1 2\n1 2\n2 1\n",
"10 3 2\n2 1 1 2 1 1 2 1 2 2\n4 10\n9 3\n5 7\n",
"4 3 2\n1 1 2 2\n1 2\n3 4\n2 3\n",
"4 2 4\n1 2 3 4\n1 2\n3 4\n",
"3 3 3\n1 2 3\n1 2\n2 3\n3 1\n",
"10 3 3\n2 2 1 3 1 2 1 2 2 2\n10 8\n9 6\n8 10\n",
"4 3 4\n1 2 3 4\n1 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all A... |
755_E. PolandBall and White-Red graph_14252 | PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding some red edges. Then, he will add white edges in every remaining place. Therefore, the final graph will be a clique in two colors: white... |
def PolandBall(n, k):
# condiciones que no cumplen con los requisitos
if n < 4 or k > 3 or k == 1 or (k == 2 and n == 4):
print('-1')
return
# si k=2
if k == 2:
print(n-1)
for i in range(1, n):
print(str(i)+' '+str(i+1))
return
# si k=3 y n=4
... | {
"input": [
"4 1\n",
"5 2\n",
"107 2\n",
"3 2\n",
"683 3\n",
"3 1\n",
"494 2\n",
"1000 1\n",
"5 4\n",
"527 2\n",
"750 3\n",
"1000 2\n",
"999 1\n",
"2 2\n",
"416 3\n",
"3 3\n",
"1000 4\n",
"9 3\n",
"101 2\n",
"8 2\n",
"10 2\n",
"4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
PolandBall has an undirected simple graph consisting of n vertices. Unfortunately, it has no edges. The graph is very sad because of that. PolandBall wanted to make it happier, adding... |
801_B. Valued Keys_14258 | You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1... | x = input()
y = input()
z = ''
for i in range(len(x)):
if x[i] < y[i]:
print("-1")
exit(0)
else:
z = z + y[i]
print(z)
| {
"input": [
"ab\naa\n",
"ab\nba\n",
"nzwzl\nniwel\n",
"vkvkkv\nvkvkkv\n",
"jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej\n",
"zzz\nzzz\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of ... |
847_D. Dog Show_14265 | A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!
On the show a dog needs to eat as many bowls of dog food as poss... | # using the min-heap
from heapq import heappush,heappop
bowels,Time = map(int,input().split())
myLine = [-int(b) for b in input().split()]
gulp = []; eat = 0
for i in range(1,min(bowels+1,Time)):
# redundant (now that i look at it. the min does that already)
if i >= Time:
break
while gulp and -gulp... | {
"input": [
"1 1\n1\n",
"3 5\n1 5 3\n",
"1 2\n1\n",
"15 15\n2 1 2 3 2 3 4 5 6 5 6 5 6 5 6\n",
"5 3\n2 3 4 5 6\n",
"18 27\n2 3 4 3 4 5 6 7 8 9 10 9 8 9 8 9 10 9\n",
"14 14\n2 3 4 5 6 7 8 9 10 11 12 13 14 15\n",
"4 4\n2 3 2 3\n",
"9 9\n2 1 2 3 4 5 6 5 6\n",
"4 4\n2 1 2 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are in... |
868_F. Yet Another Minimization Problem_14268 | You are given an array of n integers a1... an. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split the given array into k non-intersecting non-empty subsegments so that the sum of their costs is minimum possible. Each element should be p... | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [0]+list(map(int, input().split()))
buc = [0]*(n+1)
dp_p = [n*(n-1)//2]*(n+1)
dp_c = [0]*(n+1)
dp_p[0] = 0
buc[a[1]] = 1
L = R = 1
ans = 0
def cal(l, r):
global L, R, ans
while L < l:
ans += 1-buc[a[L]]
buc[a[L]] -= 1
... | {
"input": [
"10 2\n1 2 1 2 1 2 1 2 1 2\n",
"13 3\n1 2 2 2 1 2 1 1 1 2 2 1 1\n",
"7 3\n1 1 3 3 3 2 1\n",
"128 5\n116 8 116 116 119 39 116 116 119 116 8 119 119 119 39 116 39 119 39 119 119 39 8 39 8 119 8 116 116 116 119 119 8 39 39 8 116 119 119 119 119 8 8 8 119 39 119 116 119 119 39 39 119 8 116 11... | 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 of n integers a1... an. The cost of a subsegment is the number of unordered pairs of distinct indices within the subsegment that contain equal elements. Split t... |
894_C. Marco and GCD Sequence_14272 | In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.
When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be... | from math import gcd
m = int(input())
s = [int(i) for i in input().split()]
gc = s[0]
for i in range(0,m):
gc = gcd(gc,s[i])
if gc not in s:
print(-1)
else:
print(2*m-1)
ans = [s[0]]*(2*m-1)
cur = 1
for i in range(2,2*m-1,2):
ans[i] = s[cur]
cur += 1
print(*ans)
"""
3
1 10 1... | {
"input": [
"4\n2 4 6 12\n",
"2\n2 3\n",
"2\n999996 1000000\n",
"3\n250000 750000 1000000\n",
"2\n99997 399988\n",
"4\n2 4 6 12\n",
"12\n8 9 10 11 12 13 14 15 16 17 18 19\n",
"6\n111111 222222 333333 666666 777777 999999\n",
"4\n19997 339949 539919 719892\n",
"3\n4 9 11\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.
When he woke up, he only remembe... |
964_B. Messages_14280 | There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ... | n,a,b,c,t = map(int,input().split())
arr = list()
arr = map(int,input().split())
Sum = int(0)
for num in arr:
Sum += t - num
ans = n * a
if b >= c:
print(ans)
else:
print(ans + Sum * int(c - b))
| {
"input": [
"4 5 5 3 5\n1 5 5 4\n",
"5 3 1 1 3\n2 2 2 1 1\n",
"5 5 3 4 5\n1 2 3 4 5\n",
"32 2 74 772 674\n598 426 358 191 471 667 412 44 183 358 436 654 572 489 79 191 374 33 1 627 154 132 101 236 443 112 77 93 553 53 260 498\n",
"10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3\n",
"49 175 330 522 242\n109 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cos... |
991_C. Candies_14284 | After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya choos... | import sys
import math
n = int(input())
l = 1
r = 2*n
while(l < r):
candies = n
numeaten = 0
k = (l+r)//2
# print(k)
while(candies > 0):
if candies > k:
numeaten += k
candies -= k
else:
numeaten += candies
break
c = candies//1... | {
"input": [
"68\n",
"505050505\n",
"999999999999999973\n",
"43\n",
"67\n",
"601\n",
"123456789\n",
"777777777\n",
"999999999999999999\n",
"257\n",
"99999999999999959\n",
"2\n",
"888888888888888887\n",
"99999999999999957\n",
"888888888888888854\n",
"9999... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
After passing a test, Vasya got himself a box of n candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the ... |
p02618 Introduction to Heuristics Contest - AtCoder Contest Scheduling_14297 | AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to sched... | from random import randint
for i in range(365):
print(randint(1,26)) | {
"input": [
"5\n86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82\n19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424\n6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the num... |
p02749 Social Infrastructure Information Systems Division Hitachi Programming Contest 2020 - ThREE_14300 | We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i.
Takahashi loves the number 3. He is seeking a permutation p_1, p_2, \ldots , p_N of integers from 1 to N satisfying the following condition:
* For every pair of vertices (i, j), if the distance betw... | import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
edge = [[] for i in range(n)]
ans = [-1] * n
odd = []
even =[]
nums = [[],[],[]]
for i in range(1,n+1):
nums[i % 3].append(i)
def dfs(x, last = -1, d = 0):
if d % 2 == 0: even.append(x)
else: odd.append(x)
for nxt in edge[x]:
if nxt =... | {
"input": [
"5\n1 2\n1 3\n3 4\n3 5",
"5\n1 2\n1 3\n2 4\n3 5",
"5\n1 2\n2 3\n2 4\n3 5",
"5\n1 3\n2 3\n2 4\n3 5",
"5\n1 2\n4 3\n2 3\n2 5",
"5\n5 2\n1 4\n2 4\n3 5",
"5\n3 2\n1 3\n3 4\n4 5",
"5\n1 3\n2 3\n1 4\n3 5",
"5\n3 2\n1 3\n2 4\n3 5",
"5\n3 2\n1 3\n2 4\n4 5",
"5\n3 2\n1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a tree with N vertices. The vertices are numbered 1 to N, and the i-th edge connects Vertex a_i and Vertex b_i.
Takahashi loves the number 3. He is seeking a permutation p_1,... |
p02884 AtCoder Beginner Contest 144 - Fork in the Road_14304 | There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.
Takahashi is now in Room 1, and Room N has the exit. The i-th passage connects Room s_i and Room t_i (s_i < t_i) and can only be traversed in the direction from Room s_i to Room t_i. It is known that, for each roo... | N, M = map(int, input().split())
G = [[] for _ in range(N)]
rG = [[] for _ in range(N)]
for _ in range(M):
s, t = map(int, input().split())
G[s-1].append(t-1)
E = [0]*N
for v in range(N-1)[::-1]:
n = len(G[v])
for nv in G[v]:
E[v]+=(E[nv]+1)*(1/n)
ans = E[0]
for v in range(N-1):
if len(G[v])... | {
"input": [
"4 6\n1 4\n2 3\n1 3\n1 2\n3 4\n2 4",
"3 2\n1 2\n2 3",
"10 33\n3 7\n5 10\n8 9\n1 10\n4 6\n2 5\n1 7\n6 10\n1 4\n1 3\n8 10\n1 5\n2 6\n6 9\n5 6\n5 8\n3 6\n4 8\n2 7\n2 9\n6 7\n1 2\n5 9\n6 8\n9 10\n3 9\n7 8\n4 5\n2 10\n5 7\n3 5\n4 7\n4 9",
"10 33\n3 7\n5 10\n8 9\n1 10\n4 6\n2 5\n1 7\n6 10\n1 4\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a cave consisting of N rooms and M one-directional passages. The rooms are numbered 1 through N.
Takahashi is now in Room 1, and Room N has the exit. The i-th passage connec... |
p03019 AtCoder Grand Contest 034 - Tests_14307 | Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exa... | import sys,heapq,time
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True and False
def ddprint(x):
if DBG:
print(x)
n,x = inm()
blu = []
pt = 0
for ... | {
"input": [
"2 100\n85 2 3\n60 1 1",
"10 1000\n451 4593 6263\n324 310 6991\n378 1431 7068\n71 1757 9218\n204 3676 4328\n840 6221 9080\n684 1545 8511\n709 5467 8674\n862 6504 9835\n283 4965 9980",
"2 100\n85 2 3\n60 10 10",
"1 100000\n31415 2718 2818",
"2 100\n85 2 6\n60 1 1",
"10 1000\n451 45... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its ... |
p03159 AISing Programming Contest 2019 - Attack to a Tree_14310 | The server in company A has a structure where N devices numbered 1, 2, ..., N are connected with N - 1 cables. The i-th cable connects Device U_i and Device V_i. Any two different devices are connected through some number of cables.
Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents the follo... | import sys
readline = sys.stdin.readline
inf = 10**18+3
def merge(d1a, d2a, d1b, d2b):
la = len(d1a)
lb = len(d1b)
k = la+lb
res1 = [inf]*k
res2 = [inf]*k
for i in range(la):
for j in range(lb):
res1[i+j] = min(res1[i+j], d1a[i]+d1b[j], d1a[i]+d2b[j], d2a[i]+d1b[j])
... | {
"input": [
"4\n1 2 3 4\n1 2\n1 3\n1 4",
"7\n-2 7 5 6 -8 3 4\n1 2\n2 3\n2 4\n1 5\n5 6\n5 7",
"10\n3 4 9 6 1 5 -1 10 -10 -10\n7 4\n5 6\n8 1\n9 5\n7 1\n10 3\n2 8\n4 10\n9 2",
"6\n10 -1 10 -1 10 -1\n1 2\n2 3\n3 4\n4 5\n5 6",
"8\n-2 3 6 -2 -2 -5 3 2\n3 4\n7 6\n6 2\n8 2\n5 3\n1 8\n3 7",
"4\n1 2 3 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The server in company A has a structure where N devices numbered 1, 2, ..., N are connected with N - 1 cables. The i-th cable connects Device U_i and Device V_i. Any two different dev... |
p03302 SoundHound Inc. Programming Contest 2018 -Masters Tournament- - F_14314 | You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds.
Note that a+b=15 and a\times b=15 do not hold at the same time.
Constraints
* 1 \leq a,b \leq 15
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If a+b=15,... | a,b = list(map(int,input().split()))
if a*b == 15:
print("*")
elif a+b == 15:
print("+")
else:
print("x")
| {
"input": [
"4 11",
"3 5",
"1 1",
"6 11",
"8 7",
"-3 -5",
"3 7",
"2 1",
"8 11",
"3 8",
"4 1",
"8 5",
"3 0",
"4 0",
"3 1",
"4 -1",
"16 7",
"6 1",
"6 -1",
"16 6",
"6 0",
"11 -1",
"18 6",
"9 0",
"7 -1",
"31 6",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers a and b. Determine if a+b=15 or a\times b=15 or neither holds.
Note that a+b=15 and a\times b=15 do not hold at the same time.
Constraints
* 1 \leq a,b \... |
p03780 AtCoder Beginner Contest 056 - No Need_14323 | AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary... | n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)[::-1]
ans = n
sm = 0
for i in range(n):
if sm + a[i] < k:
sm += a[i]
else:
ans = min(ans, n - i - 1)
print(ans)
| {
"input": [
"5 400\n3 1 4 1 5",
"3 6\n1 4 3",
"6 20\n10 4 3 10 25 2",
"1 400\n3 1 4 1 5",
"3 6\n1 7 3",
"3 6\n1 5 2",
"3 7\n1 5 0",
"4 590\n0 1 1 1 5",
"5 1135\n1 1 1 2 5",
"1 734\n3 1 4 1 5",
"3 6\n1 7 2",
"1 734\n3 1 4 0 5",
"1 1126\n3 1 4 0 5",
"3 6\n1 5 0",... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls a subset of the cards good whe... |
p00040 Affine Cipher_14328 | One of the simple ciphers is the affine cipher. First, replace the letters a to z with the numbers a = 0, b = 1, c = 2, ..., x = 23, y = 24, z = 25 and 0 to 25. Then replace the original alphabet with the following formula.
$ F (\ gamma) = (\ alpha \ cdot \ gamma + \ beta) $ mod $ 26 $
However, mod 26 represents the ... | z='abcdefghijklmnopqrstuvwxyz'
for _ in[0]*int(input()):
e=input()
for i in range(1,26,2):
for j in range(26):
a=''
for c in e:
if c in z:a+=z[(z.index(c)*i+j)%26]
else:a+=c
if'that'in a or'this'in a:print(a);break
| {
"input": [
"1\ny eazqyp pnop pngtg ye obmpngt xmybp mr lygw",
"1\nx eazqyp pnop pngtg ye obmpngt xmybp mr lygw",
"1\nx pyqzae pnop pngtg ye obmpngt xmybp mr lygw",
"1\nx pyqzae pnop pngtg ye onmpbgt xmybp mr lygw",
"1\nx pyqzae pnop pngtg ye pnmobgt xmybp mr lygw",
"1\nx pyqzae pnop pngtg ye... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One of the simple ciphers is the affine cipher. First, replace the letters a to z with the numbers a = 0, b = 1, c = 2, ..., x = 23, y = 24, z = 25 and 0 to 25. Then replace the origi... |
p00501 Signboard_14335 | problem
JOI decided to make a signboard for the store.
There are N old signboards with letters written at equal intervals. JOI makes a sign by erasing some letters from the old sign. I want the remaining characters to be the name of the store, and the remaining characters to be evenly spaced. Signs must be made from ... | n = int(input())
name = input()
length = len(name)
def check(ss):
ind = 0
end = len(ss)
while ind < end:
while ind < end and ss[ind] != name[0]:
ind += 1
for i in range(100):
j1 = ind
j2 = 0
while j1 < end and j2 < length and ss[j1] == name[j2]:
j1 += i
j2 += 1... | {
"input": [
"4\nbar\nabracadabra\nbear\nbar\nbaraxbara",
"4\nbar\nabracadabra\nbear\nbar\nbbraxbara",
"4\nrab\nabracadabra\nbear\nbar\nbbraxbara",
"4\nrab\nabracadabra\nbear\nbar\narabxarbb",
"4\nqab\nabracadabra\nbear\nbar\narabxarbb",
"4\nqab\nabracadabra\nbear\nbra\narabxarbb",
"4\nqab... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
problem
JOI decided to make a signboard for the store.
There are N old signboards with letters written at equal intervals. JOI makes a sign by erasing some letters from the old sign... |
p00685 Board Arrangements for Concentration Games_14338 | You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.
We have a 4x4 board and 8 pairs of cards (denoted by `A' to `H') for the concent... | # AOJ 1103: Board Arrangements for Concentration Gam...
# Python3 2018.7.14 bal4u
def combi(k):
global ans
if k == 9:
ans += 1
return
for y in range(4):
for x in range(4):
if arr[y][x]: continue
arr[y][x] = k
for i in range(4):
x2, y2 = x + a[i<<1], y + a[(i<<1)+1]
if x2 < 0 or x2 >= 4 or y2 ... | {
"input": [
"-2 1 -1 1 1 1 1 2\n1 0 2 1 2 2 3 3\n5",
"-2 1 -1 1 1 1 1 2\n1 0 2 1 2 2 0 3\n5",
"-4 1 -1 1 1 1 1 2\n1 0 2 1 2 2 3 3\n5",
"-2 1 -2 1 1 1 1 2\n1 0 2 1 2 2 0 3\n5",
"-4 1 -1 1 1 1 1 2\n1 0 1 1 2 2 3 3\n5",
"-2 1 -2 1 1 0 1 2\n1 0 2 1 2 2 0 3\n5",
"-2 1 -2 1 1 0 1 3\n1 0 2 1 2 2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be eas... |
p00827 The Balance_14342 | Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she can put one 700mg weight on the side of the medicine and three 300mg weights on the opposite side (Figure 1). Although she could put fou... | 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 = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.... | {
"input": [
"700 300 200\n500 200 300\n500 200 500\n275 110 330\n275 110 385\n648 375 4002\n3 1 10000\n0 0 0",
"700 300 200\n500 200 300\n500 200 500\n275 110 330\n275 010 385\n648 375 4002\n3 1 10000\n0 0 0",
"700 300 200\n500 200 300\n500 200 500\n275 110 330\n275 010 385\n1067 375 4002\n3 1 10000\n0 0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine.
For example, to measure 200mg of aspirin using 300mg weights and 700mg weights, she... |
p00958 Parallel Lines_14345 | Problem B Parallel Lines
Given an even number of distinct planar points, consider coupling all of the points into pairs. All the possible couplings are to be considered as long as all the given points are coupled to one and only one other point.
When lines are drawn connecting the two points of all the coupled point ... | m = int(input())
P = [list(map(int, input().split())) for i in range(m)]
s = set()
for i in range(m):
xi, yi = P[i]
for j in range(i+1, m):
xj, yj = P[j]
u = xj - xi; v = yj - yi
for x, y in s:
if x * v == y * u:
break
else:
s.add((u, v))
m... | {
"input": [
"4\n0 0\n1 1\n0 2\n2 4",
"4\n0 0\n1 1\n0 2\n2 5",
"4\n0 0\n1 1\n2 2\n2 2",
"4\n0 0\n1 1\n0 2\n2 2",
"4\n0 0\n1 1\n0 2\n2 3",
"4\n0 0\n1 1\n1 2\n2 2",
"4\n0 0\n1 1\n1 2\n3 2",
"4\n0 0\n1 1\n1 4\n3 2",
"4\n0 1\n1 1\n1 4\n3 2",
"4\n0 1\n1 1\n1 7\n3 2",
"4\n0 1\n1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem B Parallel Lines
Given an even number of distinct planar points, consider coupling all of the points into pairs. All the possible couplings are to be considered as long as al... |
p01227 Country Road_14350 | This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the generators wherever you like, but in order for electricity to be supp... |
NUM=int(input())
for sect in range(NUM):
n,k=list(map(int,input().strip().split()))
x=list(map(int,input().strip().split()))
x.sort()
diff=[]
for i in range(1,len(x)):
diff.append(x[i]-x[i-1])
diff.sort(reverse=True)
s=sum(diff[:k-1])
print(max(x)-min(x)-s)
| {
"input": [
"6\n5 2\n10 30 40 70 100\n7 3\n3 6 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50",
"6\n5 2\n10 30 40 70 100\n7 3\n3 4 10 17 21 26 28\n1 1\n100\n2 1\n0 1000000\n3 5\n30 70 150\n6 4\n0 10 20 30 40 50",
"6\n5 2\n10 30 40 70 100\n7 3\n3 5 10 17 21 26 28\n1 1\n100... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this ti... |
p01361 Dungeon Quest II_14353 | The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now.
One day, however, the hero was worrying about the rebirth of the devil king, so he decided to ask security agency to patrol inside the cave.
Th... | from bisect import bisect
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
cA = ord('A')
ds = "LURD"
hi, hm = map(int, readline().split())
if hi == hm == 0:
return False
R, C = map(int, readline().split())
A = [list(map(la... | {
"input": [
"1 10\n3 3\nAAA\nABA\nCCC\n3\nA 0\nB 5\nC 9\n3\nD 2\nR 1\nU 2\n5\n10\n10\n10\n10\n10\n100 100\n10 10\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\nTHISISAPEN\n8\nT 0\nH 1\nI 2\nS 3\nA 4\nP 5\nE 6\nN 7\n9\nR 1\nD 3\nR 8\nD 2\nL 9\nD 2\nR 9... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The cave, called "Mass of Darkness", had been a agitating point of the evil, but the devil king and all of his soldiers were destroyed by the hero and the peace is there now.
One day... |
p01543 marukaite_14356 | Taro is an elementary school student and has graffiti on the back of the leaflet. At one point, Taro came up with the next game.
* Write n × n grid-like squares.
* The initial state of each square is either marked or unmarked.
* Erase or write these circles so that there is always exactly one circle no matter which co... | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a... | {
"input": [
"4\n1 2 3 4\n1 2 3 4\n1 2 3 4\n1 2 3 4\n1 2 3 4\n1 2 3 4\n1 2 3 4\n1 2 3 4\noooo\noooo\noooo\noooo",
"3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\no..\n.o.\n..o",
"3\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\no.o\n...\n.o.",
"4\n1 2 3 4\n1 2 3 4\n1 2 3 4\n2 2 3 4\n1 2 3 4\n1 2 3 4\n1 2 3 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro is an elementary school student and has graffiti on the back of the leaflet. At one point, Taro came up with the next game.
* Write n × n grid-like squares.
* The initial state ... |
p01843 Campaign_14361 | E-Election campaign
Problem Statement
You are a supporter of Mr. X, a candidate for the next election. Mr. X is planning a street speech in front of the station and intends to give a speech in a place that can be seen by as many voters as possible.
The front of the station is given as a two-dimensional plane with $ ... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def cross3(p0, p1, q0):
return (p1[0] - p0[0])*(q0[1] - p0[1]) - (p1[1] - p0[1])*(q0[0] - p0[0])
def cross_point(p0, p1, q0, q1):
x0, y0 = p0; x1, y1 = p1
x2, y2 = q0; x3, y3 = q1
dx0 = x1 - x0
dy0 = y1 - y0
dx1 = x3 - x2
dy1 ... | {
"input": [
"1 2\n4\n5 5\n15 5\n15 15\n5 15\n0 10\n20 10",
"1 2\n4\n5 5\n15 5\n15 24\n5 15\n0 10\n20 10",
"1 3\n4\n10 6\n15 5\n15 24\n5 15\n0 10\n20 7",
"2 1\n4\n10 5\n29 1\n15 19\n5 20\n0 10\n20 7",
"2 4\n4\n10 5\n15 5\n15 24\n5 17\n0 10\n20 7",
"1 2\n4\n10 5\n15 5\n15 24\n5 15\n0 10\n20 10"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
E-Election campaign
Problem Statement
You are a supporter of Mr. X, a candidate for the next election. Mr. X is planning a street speech in front of the station and intends to give ... |
p02125 OOllOll_14366 | Problem
Let $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary.
Given a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $, ..., $ f (N) $.
Example of calculating the function $ f (5) $:
When 5 is expressed in binary, it is 101 and the sum of each digit is 1... | n = int(input())
ans = 0
tmp = 1
while tmp <= n+1 :
tmp *= 2
ans += 1
print(ans-1)
| {
"input": [
"2",
"9",
"14",
"22",
"41",
"70",
"6",
"1",
"170",
"264",
"585",
"1663",
"2604",
"5020",
"10830",
"18",
"21",
"37",
"36",
"11",
"19",
"10",
"5",
"12",
"4",
"75",
"3",
"39",
"13",
"17",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
Let $ f (x) $ be the sum of each digit when the non-negative integer $ x $ is expressed in binary.
Given a positive integer $ N $, output the largest of $ f (0) $, $ f (1) $,... |
p02265 Doubly Linked List_14370 | Your task is to implement a double linked list.
Write a program which performs the following operations:
* insert x: insert an element with key x into the front of the list.
* delete x: delete the first element which has the key of x from the list. If there is not such element, you need not do anything.
* deleteFirst... | from collections import deque
a = int(input())
dl = deque()
for i in range(a):
o = input().split()
if o[0] == 'delete':
try:
dl.remove(o[1])
except ValueError:
pass
elif o[0] == 'deleteFirst':
dl.popleft()
elif o[0] == 'deleteLast':
dl.pop()
... | {
"input": [
"9\ninsert 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5\ndeleteFirst\ndeleteLast",
"7\ninsert 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5",
"7\ntresni 5\ninsert 2\ninsert 3\ninsert 1\ndelete 3\ninsert 6\ndelete 5",
"7\ntresni 5\ninsert 2\ninsert 3\ninser... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your task is to implement a double linked list.
Write a program which performs the following operations:
* insert x: insert an element with key x into the front of the list.
* delet... |
p02413 Spreadsheet_14374 | Your task is to perform a simple table calculation.
Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes the total sum for each row and column.
Constraints
* 1 ≤ r, c ≤ 100
* 0 ≤ an element of the table ≤ 100
Input
In the first line, two ... | r,c = map(int,input().split())
a =[]
for i in range(r) :
a.append(list(map(int,input().split())))
a[i].append(sum(a[i]))
b = list(map(sum,zip(*a)))
for i in range(r) :
print(*a[i])
print(*b)
| {
"input": [
"4 5\n1 1 3 4 5\n2 2 2 4 5\n3 3 0 1 1\n2 3 4 4 6",
"4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 1\n2 3 4 4 6",
"4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 1\n2 3 4 8 6",
"4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 1\n2 6 4 8 6",
"4 5\n1 1 3 4 8\n2 2 2 4 5\n3 3 0 1 2\n2 6 4 8 6",
"4 5\n2 1 3 4 8\n2 2 2 4 5... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Your task is to perform a simple table calculation.
Write a program which reads the number of rows r, columns c and a table of r × c elements, and prints a new table, which includes ... |
1044_A. The Tower is Going Home_14386 | On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the coordinates (x,y), where x is the column number and y is the row number.
Ever... | n,m=[int(x) for x in input().split()]
v=[]
h=[]
for i in range(n):
x=int(input())
v.append(x)
for i in range(m):
x,y,z=[int(x) for x in input().split()]
if x==1:
h.append(y)
h.sort()
v.sort()
m=len(h)
n=len(v)
if n==0 or v[n-1]!=1000000000:
v.append(1000000000)
n+=1
mina=9999999999999
j=... | {
"input": [
"0 0\n",
"2 3\n4\n6\n1 4 3\n1 5 2\n1 6 5\n",
"2 3\n6\n8\n1 5 6\n1 9 4\n2 4 2\n",
"0 2\n1 1000000000 4\n1 1000000000 2\n",
"1 3\n4\n1 5 3\n1 9 4\n4 6 6\n",
"4 7\n1\n2\n3\n4\n1 1000000000 1\n1 1000000000 2\n1 1000000000 3\n1 1000000000 4\n1 1000000000 5\n1 1000000000 6\n1 1000000000... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. The... |
1066_F. Yet another 2D Walking_14390 | Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point (0, 0), he can go to any of the following points in one move:
* (1, 0);
* (0, 1);
* (-1, 0);
* (0, -... | def dista(a, b):
return abs(lista[a][0]-lista[b][0]) + abs(lista[a][1]-lista[b][1])
lista = []
ne = 0
n = int(input())
dist = [0] * (n+1)
lista.append((0, 0))
for _ in range(n):
x, y = map(int, input().split())
lista.append((x, y))
lista = sorted(lista, key= lambda x: min(x))
lista = sorted(lista, key= lambda x: m... | {
"input": [
"5\n2 1\n1 0\n2 0\n3 2\n0 3\n",
"8\n2 2\n1 4\n2 3\n3 1\n3 4\n1 1\n4 3\n1 2\n",
"9\n1 4\n2 3\n3 4\n4 3\n2 2\n1 2\n1 1\n3 1\n5 3\n",
"1\n1000000000 1000000000\n",
"9\n1 1\n3 4\n4 3\n1 4\n1 2\n3 1\n2 3\n2 2\n1 5\n",
"39\n27 47\n30 9\n18 28\n49 16\n10 12\n25 13\n44 11\n13 9\n3 8\n30 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Maksim walks on a Cartesian plane. Initially, he stands at the point (0, 0) and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is... |
1089_J. JS Minification_14393 | International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source form. Sources contain comments, extra whitespace (including trailing and leading spaces), and other non-essential features that make them qu... | def main():
t = int(input())
reserved = set(input().split())
lines = int(input())
code = ''
for i in range(lines):
code += input() + '\n'
def is_word(suspect):
if suspect[0].isdigit(): return False
for x in suspect:
if (not x.isalpha()) and (not x in {'_', '$'}) and (not x.isdigit()):
return False
... | {
"input": [
"16\nfun while return var { } ( ) , ; > = + ++ - --\n9\nfun fib(num) { # compute fibs\n var return_value = 1, prev = 0, temp;\n while (num > 0) {\n temp = return_value; return_value = return_value + prev;\n prev = temp;\n num--;\n }\n return return_value;\n}\n",
"10\n( ) + ++ :... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source for... |
1108_D. Diverse Garland_14397 | You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garlan... | n = int(input())
w = list(input())
count = 0
for i in range(1,len(w)):
if w[i] != w[i-1]:
continue
else:
if i != len(w) - 1:
next = ['R','G','B']
next.remove(w[i-1])
if w[i+1] in next: next.remove(w[i+1])
w[i] = next[0]
count += 1
else:
next = ['R','G','B']
next.remove(w[i-1])
w[i] = nex... | {
"input": [
"8\nBBBGBRRR\n",
"9\nRBGRRBRGG\n",
"13\nBBRRRRGGGGGRR\n",
"5\nGBBRG\n",
"3\nRGG\n",
"500\nBRGRRBBGGRBBRBBGGGRBGBGRGRRBRRRBGRBGBRGGGRBBRRBBBRGGBGBBBGGGRGRBBBRBGGBRGGGBRGGRBRGBBGBRRGGBGRGBGGGGGRBBRGBGGRBGGGRBRGGBBGRBBRRRGBRRBGGBGBGGGGRBGRGRRGGGBRBRRGBGGGRBRBBGBBGGBRBGBRRGGRRBGGRRRRB... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a garland consisting of n lamps. Each lamp is colored red, green or blue. The color of the i-th lamp is s_i ('R', 'G' and 'B' — colors of lamps in the garland).
You have to ... |
1156_B. Ugly Pairs_14403 | You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions (1, 2) — "ab" and (2, 3) — "ba". Letters 'a' and 'z' aren't considered neighbou... | T = int(input())
for _ in range(T):
s = input()
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
k = sorted(list(d.keys()))
n = len(k)
if n == 2:
if abs(ord(k[0]) - ord(k[1])) == 1:
ans = "No answer"
else:
ans = s
elif n == 3:
if abs(ord(k[0])... | {
"input": [
"4\nabcd\ngg\ncodeforces\nabaca\n",
"1\nheaghhcgfb\n",
"1\ndgeegbeabh\n",
"1\neefbhgeabache\n",
"1\nzcbacx\n",
"4\nabcd\ngg\ncodeforces\nabaca\n",
"1\nzyy\n",
"100\nc\nda\na\nee\ned\ndb\nece\nab\nabe\nd\neeb\na\nbab\nbbd\nc\ncab\nc\nbda\ndb\ncca\nbcd\nbae\neb\nde\ndc\naee\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For... |
1178_E. Archaeology_14407 | Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it?
The book contains a single string of characters "a", "... | s=input()
n=len(s)
b=[]
for j in s:
b.append(j)
x=[]
y=[]
j=0
i=n-1
while(j<i):
if b[j]==b[i]:
if i!=j:
x.append(b[j])
y.append(b[i])
else:
x.append(b[j])
i+=-1
j+=1
elif b[j]==b[i-1]:
if (i-1) != j:
x.append(b[j])
... | {
"input": [
"cbacacacbcbababacbcb\n",
"abc\n",
"cacbac\n",
"bcacabcbabacacbcbcbcbabacbcacacbcacababc\n",
"abababacacacbcbcbc\n",
"babababcbcbacacac\n",
"acab\n",
"abacbc\n",
"acbcbabacacbcbab\n",
"bacbac\n",
"abababcbacacacbcbc\n",
"bcb\n",
"ababacacacbc\n",
"c... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found ... |
1196_D2. RGB Substring (hard version)_14411 | The only difference between easy and hard versions is the size of the input.
You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'.
You are also given an integer k. Your task is to change the minimum number of characters in the initial string s so that after the changes there will be ... | import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_1(): r... | {
"input": [
"3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n",
"3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBRBR\n",
"3\n5 3\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n",
"3\n5 2\nBGGGG\n5 4\nRBRGR\n5 5\nBBRBR\n",
"3\n5 3\nBGGGG\n5 3\nRBRGR\n5 2\nBBBRR\n",
"3\n5 2\nBGGGG\n5 4\nRBRGR\n5 5\nBRBRB\n",
"3\n5 1\nBGGGG\n5 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 the size of the input.
You are given a string s consisting of n characters, each character is 'R', 'G' or 'B'.
You are also giv... |
1213_F. Unstable String Sort_14415 | Authors have come up with the string s consisting of n lowercase Latin letters.
You are given two permutations of its indices (not necessary equal) p and q (both of length n). Recall that the permutation is the array of length n which contains each integer from 1 to n exactly once.
For all i from 1 to n-1 the followi... | import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify
from copy import deepcopy
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline()... | {
"input": [
"3 2\n1 2 3\n1 3 2\n",
"3 2\n3 1 2\n3 2 1\n",
"5 4\n1 3 2 4 5\n2 3 5 1 4\n",
"5 2\n5 2 4 3 1\n5 4 3 1 2\n",
"6 5\n5 6 1 2 3 4\n6 5 1 2 3 4\n",
"5 1\n1 3 2 4 5\n2 3 5 1 4\n",
"5 5\n1 3 2 4 5\n2 3 5 1 4\n",
"3 3\n3 1 2\n3 2 1\n",
"3 4\n1 2 3\n1 3 2\n",
"5 2\n1 3 2 4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Authors have come up with the string s consisting of n lowercase Latin letters.
You are given two permutations of its indices (not necessary equal) p and q (both of length n). Recall... |
1237_B. Balanced Tunnel_14419 | Consider a tunnel on a one-way road. During a particular day, n cars numbered from 1 to n entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds.
A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel ex... | n = int(input())
pre = map(int, input().split())
post = map(int, input().split())
pre_map = {}
for i, p in enumerate(pre):
pre_map[p] = i
post_ = [] # ordered 0, 1, 2, ... n-1
for p in post:
post_.append(pre_map[p])
#print(post_)
current_min = n
ans = 0
for p in post_[::-1]:
if current_min < p:
ans += 1
... | {
"input": [
"2\n1 2\n1 2\n",
"7\n5 2 3 6 7 1 4\n2 3 6 7 1 4 5\n",
"5\n3 5 2 1 4\n4 3 2 5 1\n",
"2\n1 2\n2 1\n",
"2\n0 2\n0 2\n",
"2\n2 1\n1 2\n",
"2\n0 1\n0 1\n",
"2\n2 1\n2 1\n"
],
"output": [
"0\n",
"6\n",
"2\n",
"1\n",
"0\n",
"1\n",
"0\n",
"0\n"
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider a tunnel on a one-way road. During a particular day, n cars numbered from 1 to n entered and exited the tunnel exactly once. All the cars passed through the tunnel at constan... |
1255_A. Changing Volume_14423 | Bob watches TV every day. He always sets the volume of his TV to b. However, today he is angry to find out someone has changed the volume to a. Of course, Bob has a remote control that can change the volume.
There are six buttons (-5, -2, -1, +1, +2, +5) on the control, which in one press can either increase or decrea... | """
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
n = int(input())
return(n)
def inlt():
a = list(map(int,input().split()))
return(a)
def insr():
s = input()
return(... | {
"input": [
"3\n4 0\n5 14\n3 9\n",
"3\n4 0\n5 14\n3 13\n",
"3\n4 0\n5 14\n3 2\n",
"3\n6 0\n5 14\n2 13\n",
"3\n4 0\n4 14\n0 2\n",
"3\n6 0\n2 8\n2 13\n",
"3\n2 0\n6 14\n0 1\n",
"3\n2 0\n6 25\n0 1\n",
"3\n6 -1\n6 8\n2 13\n",
"3\n2 -1\n6 25\n0 1\n",
"3\n6 -1\n6 8\n3 13\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob watches TV every day. He always sets the volume of his TV to b. However, today he is angry to find out someone has changed the volume to a. Of course, Bob has a remote control tha... |
1278_F. Cards_14427 | Consider the following experiment. You have a deck of m cards, and exactly one card is a joker. n times, you do the following: shuffle the deck, take the top card of the deck, look at it and return it into the deck.
Let x be the number of times you have taken the joker out of the deck during this experiment. Assuming ... | class UnionFindVerSize():
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
self.group = N
def find_root(self, x):
if self._parent[x] == x: return x
self._parent[x] = self.find_root(self._parent[x])
stack = [x]
while self... | {
"input": [
"998244352 1337 5000\n",
"1 1 1\n",
"1 1 5000\n",
"2 2 2\n",
"213292922 8067309 5000\n",
"569716410 849619604 5000\n",
"232213466 585535513 4789\n",
"251134010 189925189 5000\n",
"588636954 730833344 5000\n",
"232213466 585535513 5000\n",
"213292922 8067309 44\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider the following experiment. You have a deck of m cards, and exactly one card is a joker. n times, you do the following: shuffle the deck, take the top card of the deck, look at... |
1299_C. Water Balance_14431 | There are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right.
You can perform the following operation: choose some subsegment [l, r] (1≤ l ≤ r ≤ n), and redistribute water in tanks l, l+1, ..., r evenly. In other words, replace each of a_l, a_{l+1},... | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a... | {
"input": [
"4\n7 5 5 7\n",
"5\n7 8 8 10 12\n",
"10\n3 9 5 5 1 7 5 3 8 7\n",
"3\n20 90 100\n",
"65\n1000000 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right.
You can perform the following operation: choose so... |
1322_A. Unusual Competitions_14435 | A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher gave Dmitry's class a very strange task — she asked every student... | n=int(input())
l=input()
e=[]
p=0
for i in l:
if i=='(':
p+=1
e.append(p)
else:
p-=1
e.append(p)
if e[-1]!=0:
print(-1)
else:
ans=0
z=0
for i in range(n):
if e[i]<0:
z+=1
else:
if z>0:
ans+=z+1
... | {
"input": [
"3\n(()\n",
"8\n))((())(\n",
"51\n))((((((((()))(())()(()(()())()(()(())(())()())))))\n",
"4\n((()\n",
"100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n",
"10\n))))((((()\n",
"10\n)()()()()(\n",
"100\n)))))))((((((... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(... |
1383_B. GameGame_14442 | Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of... | import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
base=0
for A in a:
base^=A
if base==0:
print("DRAW")
else:
m=base.bit_length()-1
count=0
for A in a:
count+=(A>>m &1==1)
... | {
"input": [
"3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 1 2 2\n",
"3\n3\n1 2 2\n3\n3 2 3\n5\n0 0 0 2 2\n",
"3\n3\n1 2 3\n3\n2 2 3\n5\n0 0 0 2 2\n",
"4\n5\n4 1 5 1 3\n4\n1 0 1 12\n1\n0\n2\n5 4\n",
"3\n3\n1 2 2\n3\n2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each... |
1404_B. Tree Tag_14446 | Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph with n-1 edges.
Initially, Alice is located at vertex a, and Bob at vertex b. They take turns alternately, and Alice makes the first mov... | diameter = 0
def dfs(u, tree, depth):
global diameter
length = 0
level[u] = depth
isCheck[u] = True
for vertex in tree[u]:
if isCheck[vertex] != True:
isCheck[vertex] = True
cur = dfs(vertex, tree, depth + 1) + 1
diameter = max(diameter, cur + length)
... | {
"input": [
"4\n4 3 2 1 2\n1 2\n1 3\n1 4\n6 6 1 2 5\n1 2\n6 5\n2 3\n3 4\n4 5\n9 3 9 2 5\n1 2\n1 6\n1 9\n1 3\n9 5\n7 9\n4 8\n4 3\n11 8 11 3 3\n1 2\n11 9\n4 9\n6 5\n2 10\n3 2\n5 9\n8 3\n7 4\n7 10\n",
"10\n10 9 10 6 6\n6 1\n7 6\n4 2\n4 10\n5 1\n9 5\n6 8\n3 4\n4 5\n2 1 2 1 1\n2 1\n9 7 4 2 3\n5 1\n2 4\n4 8\n8 6\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of n vertices numbered from 1 to n. Recall that a tree on n vertices is an undirected, connected graph ... |
1425_H. Huge Boxes of Animal Toys_14450 | Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification:
* The first box stores toys with fun values in range of (-∞,-1].
* The second box stores toys with fun values in range of (-1, 0).
* The third box s... | for k in range(int(input())):
a, b, c, d = list(map(int, input().split()))
s = ''
if (a+b)%2==1 and (a > 0 or d > 0):
s += 'Ya '
else:
s += 'Tidak '
if (a+b)%2 == 1 and (b > 0 or c > 0):
s += 'Ya '
else:
s += 'Tidak '
if (a+b)%2 == 0 and (b > 0 or c > 0):
... | {
"input": [
"2\n1 2 0 1\n0 1 0 0\n",
"2\n2 2 0 1\n0 1 0 0\n",
"2\n1 2 -1 1\n0 1 0 0\n",
"2\n2 1 0 1\n0 1 0 1\n",
"2\n2 1 1 -1\n1 1 0 0\n",
"2\n4 0 1 1\n0 0 1 0\n",
"2\n4 0 0 1\n0 0 1 0\n",
"2\n4 0 0 1\n0 1 1 0\n",
"2\n1 2 0 1\n0 2 0 0\n",
"2\n0 2 0 1\n0 1 0 1\n",
"2\n9 1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Chaneka has a hobby of playing with animal toys. Every toy has a different fun value, a real number. Chaneka has four boxes to store the toys with specification:
* The first box s... |
1447_E. Xor Tree_14453 | For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way:
* Consider a graph on k nodes, with numbers from b_1 to b_k written on them.
* For every i from 1 to k: find such j (1 ≤ j ≤ k, j≠ i), for which (b_i ⊕ b_j) is the smallest among all such j,... | import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def costs(l, bit = 32):
if len(l) <= 2:
return 0
left = []
right = []
for el in l:
if el & (1<<bit):
left.append(el)
else:
right.append(el)
return min(costs(left, b... | {
"input": [
"5\n0 1 5 2 6\n",
"7\n6 9 8 7 3 5 2\n",
"7\n32 35 2 20 52 59 28\n",
"3\n4 9 1\n",
"109\n74 18 237 179 195 112 156 11 72 68 173 202 78 250 224 251 107 55 186 144 57 62 28 210 132 64 93 6 211 0 174 163 248 226 167 246 46 102 253 180 121 56 151 35 150 254 168 201 242 118 190 158 196 30 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For a given sequence of distinct non-negative integers (b_1, b_2, ..., b_k) we determine if it is good in the following way:
* Consider a graph on k nodes, with numbers from b_1 to... |
1472_E. Correct Placement_14457 | Polycarp has invited n friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side.
Each friend is characterized by two values h_i (their height) and w_i (their width). On the photo the i-th friend will occupy a rectangle h_i ... |
from collections import deque, defaultdict, Counter
import sys
#import numpy as np
mod = 10**9 + 7
#mod =998244353
def input():
return sys.stdin.readline().rstrip()
def sol():
#start coding here...
#print("Hello CodeForces!")
#bad implemention, what a shame...
n = int(input())
Friends_stand... | {
"input": [
"4\n3\n3 4\n5 4\n3 3\n3\n1 3\n2 2\n3 1\n4\n2 2\n3 1\n6 3\n5 4\n4\n2 2\n2 3\n1 1\n4 4\n",
"4\n3\n3 4\n5 4\n3 3\n3\n1 3\n2 2\n3 1\n4\n2 2\n3 1\n6 5\n5 4\n4\n2 2\n2 3\n1 1\n4 4\n",
"4\n3\n6 4\n5 4\n3 3\n3\n1 3\n2 2\n3 0\n4\n2 2\n3 1\n6 5\n5 4\n4\n2 2\n2 3\n1 1\n4 4\n",
"4\n3\n3 4\n5 4\n3 3\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp has invited n friends to celebrate the New Year. During the celebration, he decided to take a group photo of all his friends. Each friend can stand or lie on the side.
Each ... |
1498_F. Christmas Game_14460 | Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents are hanging from the i-th node.
Before beginning the game, a special integer k is chosen. The game proceeds as follows:
* Alice begin... | import sys
from sys import stdin
from collections import deque
n,k = map(int,stdin.readline().split())
N,K = n,k
lis = [ [] for i in range(N) ]
for i in range(N-1):
x,y = map(int,stdin.readline().split())
x -= 1
y -= 1
lis[x].append(y)
lis[y].append(x)
a = list(map(int,stdin.readline().split()))... | {
"input": [
"5 1\n1 2\n1 3\n5 2\n4 3\n0 3 2 4 4\n",
"3 3\n1 3\n1 2\n1 2 3\n",
"3 1\n3 1\n3 2\n1 2 3\n",
"4 3\n1 2\n1 3\n3 4\n1000000000 999999999 0 1\n",
"3 20\n1 2\n1 3\n1 2 3\n",
"6 1\n1 2\n1 3\n3 4\n2 5\n5 6\n1 3 3 4 5 0\n",
"3 3\n1 3\n1 2\n1 3 3\n",
"6 1\n1 2\n1 3\n3 4\n2 5\n5 6\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alice and Bob are going to celebrate Christmas by playing a game with a tree of presents. The tree has n nodes (numbered 1 to n, with some node r as its root). There are a_i presents ... |
1520_E. Arranging The Sheep_14464 | You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length n, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the co... | t=int(input())
for i in range(t):
n=int(input())
s=input();y=0;b=[]
for i in range(n):
if s[i]=='*':y+=1;b.append(i)
x=y//2
if len(b)==n or len(b)==0 or len(b)==1 : print(0)
else:
moves=0
for i in range(len(b)):
moves+=abs(abs(b[x]-b[i]-1)-abs(x-i-1))
... | {
"input": [
"5\n6\n**.*..\n5\n*****\n3\n.*.\n3\n...\n10\n*.*...*.**\n",
"2\n6\n**..**\n4\n**..\n",
"2\n10\n*.*...*.**\n3\n...\n",
"2\n10\n**.*...*.*\n3\n...\n",
"2\n10\n*..*..**.*\n3\n...\n",
"2\n6\n**..**\n4\n..**\n",
"2\n6\n**.**.\n4\n..**\n",
"5\n6\n..*.**\n5\n*****\n3\n.*.\n3\n...... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length n, consisting of the chara... |
176_A. Trading Business_14470 | To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin... |
n,m,k = [int(s) for s in input().split()]
BuyingPrice = []
SellingPrice = []
Number_of_items = []
for i in range(n):
input()
x = []
y = []
z = []
for j in range(m):
a,b,c = [int(s) for s in input().split()]
x.append(a)
y.append(b)
z.append(c)
BuyingPrice.append(... | {
"input": [
"3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n",
"2 2 1\nQwe\n900 800 1\n5 1 1\nEwq\n1000 999 0\n11 10 0\n",
"3 2 11\nMars\n15 10 4\n7 6 3\nSnickers\n20 17 2\n10 8 0\nBounty\n21 18 5\n9 7 3\n",
"2 2 5\nAbcdefghij\n20 15 20\n10 5 13\nKlmopq... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of th... |
21_C. Stripe 2_14476 | 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 three pieces so that the sum of numbers from each piece is equal to the sum of numbers from any other piece,... | n = int(input())
lis = list(map(int,input().split()))
pre=[0]*(n+1)
for i in range(1,n+1):
pre[i]=pre[i-1]+lis[i-1]
if pre[-1]%3:
print(0)
else:
s=pre[-1]//3
ans=t=0
for i in range(1,n):
if pre[i]==2*s:
ans+=t
if pre[i]==s:
t+=1
print(ans) ... | {
"input": [
"5\n1 2 3 4 5\n",
"4\n1 2 3 3\n",
"5\n-6 3 -1 2 -7\n",
"4\n-2 3 3 2\n",
"3\n0 0 0\n",
"9\n-5 -2 1 1 5 0 -4 4 0\n",
"100\n3 0 -5 2 -3 -1 -1 0 -2 -5 -4 2 1 2 -2 -1 -1 -4 3 -1 -3 -1 5 0 -4 -4 -1 0 -2 -2 0 1 -1 -2 -1 -5 -4 -2 3 1 -3 0 -1 1 0 -1 2 0 -2 -1 -3 1 -2 2 3 2 -3 -5 2 2 -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... |
33_C. Wonderful Randomized Sum_14489 | Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th... | from sys import stdin
n = int(stdin.readline())
nums = [int(x) for x in stdin.readline().split()]
total = sum(nums)*-1
best = 0
left = 0
right = 0
current = 0
while right < n:
while current >= 0 and right < n:
current += nums[right]
best = max(best,current)
right += 1
while curren... | {
"input": [
"5\n-4 2 0 5 0\n",
"3\n-1 -2 -3\n",
"5\n-1 10 -5 10 -2\n",
"4\n-83 -87 42 -96\n",
"100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline ... |
407_B. Long Path_14497 | One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to get to the (n + 1)-th one.
The maze is organized as follows. Each room of the maze has two one-way portals. Let's consider room number i (... | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ... | {
"input": [
"4\n1 1 2 3\n",
"5\n1 1 1 1 1\n",
"2\n1 2\n",
"3\n1 1 3\n",
"1\n1\n",
"30\n1 1 2 2 5 6 4 3 4 7 3 5 12 12 2 15 3 8 3 10 12 3 14 1 10 4 22 11 22 27\n",
"20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20\n",
"129\n1 1 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day, little Vasya found himself in a maze consisting of (n + 1) rooms, numbered from 1 to (n + 1). Initially, Vasya is at the first room and to get out of the maze, he needs to ge... |
479_C. Exams_14505 | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a stud... | n = int(input())
listd = []
res = 0
for i in range(n):
listd.append(tuple(map(int, input().split())))
listd.sort()
for a, b in listd:
res = b if res<=b else a
print(res)
| {
"input": [
"3\n5 2\n3 1\n4 2\n",
"3\n6 1\n5 2\n4 3\n",
"1\n1000000000 999999999\n",
"5\n4 3\n4 2\n4 1\n4 1\n4 1\n",
"6\n12 11\n10 9\n8 7\n6 5\n4 3\n2 1\n",
"2\n3 1\n3 2\n",
"3\n3 2\n4 1\n100 10\n",
"2\n4 2\n4 1\n",
"4\n7 1\n7 3\n8 2\n9 8\n",
"3\n3 2\n4 1\n10 5\n",
"2\n5 2... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pas... |
501_C. Misha and Forest_14509 | Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 to n - 1 he wrote down two integers, degreev and sv, were the first integer is the number of vertices adjacent to vertex v, and the secon... | from collections import defaultdict
def main():
n = int(input())
bydegree = defaultdict(set)
bys = defaultdict(set)
l = []
for i in range(n):
degree, s = map(int, input().split())
bydegree[degree].add(i)
bys[s].add(i)
l.append((degree, s))
res = []
ones = by... | {
"input": [
"2\n1 1\n1 0\n",
"3\n2 3\n1 0\n1 0\n",
"12\n0 0\n1 3\n0 0\n1 1\n0 0\n1 7\n0 0\n1 5\n0 0\n0 0\n0 0\n0 0\n",
"14\n1 10\n1 9\n3 4\n1 2\n0 0\n1 11\n1 12\n1 10\n1 10\n2 10\n3 15\n3 14\n2 4\n0 0\n",
"13\n2 7\n0 0\n0 0\n2 11\n2 7\n2 14\n2 3\n2 1\n1 11\n3 15\n1 6\n2 11\n1 9\n",
"19\n1 13\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One day Misha played with the forest consisting of n vertices. For each vertex v from 0 ... |
527_A. Playing with Paper_14513 | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting t... | import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import (
accumulate, combinations, combinations_with_replacemen... | {
"input": [
"2 1\n",
"10 7\n",
"1000000000000 1\n",
"3 2\n",
"4 2\n",
"1000 998\n",
"8 5\n",
"442 42\n",
"3 1\n",
"695928431619 424778620208\n",
"13 8\n",
"1000000000000 3\n",
"628625247282 464807889701\n",
"293 210\n",
"1000000000000 999999999998\n",
"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm × b mm sheet of paper (a > b). Usually the first step in making an origa... |
552_D. Vanya and Triangles_14517 | Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer ... | import sys
from math import gcd
from collections import defaultdict
input=sys.stdin.readline
n=int(input())
p=[list(map(int,input().split())) for i in range(n)]
ans=0
for xi,yi in p:
angle=defaultdict(int)
for x,y in p:
if xi==x and yi==y:
continue
x-=xi;y-=yi
if x<0 or (x==0... | {
"input": [
"4\n0 0\n1 1\n2 0\n2 2\n",
"1\n1 1\n",
"3\n0 0\n1 1\n2 0\n",
"5\n-100 -100\n-100 100\n100 -100\n100 100\n0 0\n",
"61\n83 52\n28 91\n-45 -68\n-84 -8\n-59 -28\n-98 -72\n38 -38\n-51 -96\n-66 11\n-76 45\n95 45\n-89 5\n-60 -66\n73 26\n9 94\n-5 -80\n44 41\n66 -22\n61 26\n-58 -84\n62 -73\n18... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the... |
579_D. "Or" Game_14521 | You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
I... | n, k, x = map(int, input().split())
A = list(map(int, input().split()))
L, R = [0]*(n+1), [0]*(n+1)
for i in range(n):
L[i+1] = A[i] | L[i]
for i in range(n-1, -1, -1):
R[i] = A[i] | R[i+1]
x = x**k
ans = 0
for i in range(n):
ans = max(ans, L[i] | (A[i]*x) | R[i+1])
print(ans)
| {
"input": [
"3 1 2\n1 1 1\n",
"4 2 3\n1 2 4 8\n",
"2 1 2\n12 9\n",
"2 2 2\n60 59\n",
"5 1 3\n1 5 13 8 16\n",
"5 10 8\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"3 1 2\n20 17 8\n",
"2 1 8\n18 17\n",
"5 10 8\n0 0 0 0 0\n",
"3 1 3\n3 2 0\n",
"3 1 8\n10 17 18\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possibl... |
600_C. Make Palindrome_14525 | A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in th... | import sys
input=sys.stdin.readline
s=input().rstrip()
n=len(s)
ans=[""]*n
c={}
for i in range(n):
c[s[i]]=c.get(s[i],0)+1
idx=0
l=[]
for i in range(26):
al=chr(ord("a")+i)
if al in c:
while c[al]-2>=0:
ans[idx]=ans[n-1-idx]=al
c[al]-=2
idx+=1
if c[al]==1:... | {
"input": [
"aabcd\n",
"aabc\n",
"bbbcccddd\n",
"asbbsha\n",
"aabbcccdd\n",
"qqqqaaaccdd\n",
"abcd\n",
"aaabbbcccdddeee\n",
"aaabb\n",
"acc\n",
"azz\n",
"aaaabbcccccdd\n",
"aaacccb\n",
"bababab\n",
"ttttt\n",
"aaadd\n",
"aaabbbccc\n",
"aaabbccdd... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but... |
644_B. Processing Queries_14532 | In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment ti and needs to be processed for di units of time. All ti are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If server is free and... | import queue
n, b = list(map(int, input().split()))
class Task:
def __init__(self, time: int, duration: int, index: int) -> None:
super().__init__()
self.time = time
self.duration = duration
self.index = index
remaining = queue.Queue()
running = False
finish_time = 0 # Runnin... | {
"input": [
"4 1\n2 8\n4 8\n10 9\n15 2\n",
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"6 3\n1 2\n2 3\n100 200\n200 300\n10000 20000\n20000 30000\n",
"1 1\n1000000000 1000000000\n",
"5 2\n2 7\n3 3\n7 4\n9 1\n10 2\n",
"4 1\n1 2\n2 1\n3 1\n4 3\n",
"10 2\n4 14\n5 2\n6 6\n7 11\n8 6\n9 5\n10 13\n11 8... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment ti and needs to be processed for di units o... |
671_B. Robin Hood_14536 | We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekoland, each person has ci coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give it to t... | import sys
inp = sys.stdin.read().splitlines()
n,k = list(map(int,inp[0].split()))
lst = list(map(int,inp[1].split()))
lst.sort()
total = sum(lst)
lower = int(total/n)
nupper = total%n
if nupper == 0:
upper = lower;
else:
upper = lower+1;
nlower = n - nupper;
i = 0;
while i<n and lst[i]<lower:
i+=1
low1st = i;
... | {
"input": [
"4 1\n1 1 4 2\n",
"3 1\n2 2 2\n",
"10 1000\n1000000000 999999994 999999992 1000000000 999999994 999999999 999999990 999999997 999999995 1000000000\n",
"100 20\n2 5 3 3 2 7 6 2 2 2 6 7 2 1 8 10 2 4 10 6 10 2 1 1 4 7 1 2 9 7 5 3 7 4 6 3 10 10 3 7 6 8 2 2 10 3 1 2 1 3 1 6 3 1 4 10 3 10 9 5 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are n citizens in Kekol... |
739_B. Alyona and a tree_14543 | Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).
Let's define dist(v, u) as the sum of the inte... | #!/usr/bin/env python3
import sys
import threading
from bisect import *
#def ri():
# return map(int, input().split())
def dfs(v, d, c, w):
d += 1
dist[d] = w[v] + dist[d-1]
add[d] = 0
for i in c[v]:
dfs(i, d, c, w)
x = bisect_left(dist, dist[d] - a[v], 0, d)
add[x-1] -= 1
add[... | {
"input": [
"5\n9 7 8 6 5\n1 1\n2 1\n3 1\n4 1\n",
"5\n2 5 1 4 6\n1 7\n1 1\n3 5\n3 6\n",
"5\n1000000000 1000000000 1000000000 1000000000 1000000000\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n",
"10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a posi... |
762_A. k-th divisor_14547 | You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.
Divisor of n is any such natural number, that n can be divided by it without remainder.
Input
The first line contains two integers n and k (1 ≤ n ≤ 1015, 1 ≤ k ≤ 109).
Output
If n has less than k divisors, output ... | #
# Yet I'm feeling like
# There is no better place than right by your side
# I had a little taste
# And I'll only spoil the party anyway
# 'Cause all the girls are looking fine
# But you're the only one on my mind
import sys
# import re
# inf = float("inf")
# sys.setrecursionlimit(1000000)
# abc='abc... | {
"input": [
"12 5\n",
"4 2\n",
"5 3\n",
"4 3\n",
"1998 1\n",
"9 3\n",
"99999999999931 2\n",
"1234 2\n",
"151491429961 4\n",
"100 7\n",
"1048576 12\n",
"16 6\n",
"1000000000000 100\n",
"4567890 14\n",
"1999967841 15\n",
"1998 2\n",
"1996 2\n",
"1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.
Divisor of n is any such natural number, that n can be divided by it without rem... |
785_B. Anton and Classes_14551 | Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th v... | n = int(input())
refA = []
for i in range(n):
refA.append([int(x) for x in input().split()])
m = int(input())
refB = []
for i in range(m):
refB.append([int(x) for x in input().split()])
refA_early = sorted(refA,key = lambda x:x[1])
refA_late = sorted(refA,key = lambda x:x[0],reverse = True)
refB_early = sorte... | {
"input": [
"3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n",
"3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n",
"1\n200000000 200000001\n1\n200000000 200000001\n",
"1\n999999995 999999996\n1\n999999998 999999999\n",
"1\n999999997 999999997\n1\n999999999 999999999\n",
"1\n999999999 999999999\n1\n1000000000 1000000000\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess ... |
807_B. T-Shirt Hunt_14555 | Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.
Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.
Now the elimination rou... | #!/usr/bin/env python
import sys
def eligible(score, position, thresh):
if score < thresh:
return False
i = (score // 50) % 475
for __ in range(25):
i = (i * 96 + 42) % 475
if position == 26 + i:
return True
return False
def main():
p, x, y= map(int, sys.stdin.re... | {
"input": [
"493 8000 8000\n",
"239 10880 9889\n",
"329 19913 19900\n",
"101 6800 6500\n",
"26 7258 6123\n",
"186 18666 18329\n",
"31 12956 10515\n",
"198 6550 6549\n",
"176 9670 9174\n",
"26 20000 1\n",
"180 4213 4207\n",
"173 7017 4512\n",
"412 5027 4975\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Cod... |
831_C. Jury Marks_14559 | Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the i-th jury member gave ai points.
P... | def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
n,k = map_input()
a = list_input()
b = list_input()
pos = set()
pref = []
cur = 0
for i in a:
cur += i
pref.append(cur)
for j in pref:
pos.add(b[... | {
"input": [
"4 1\n-5 5 0 20\n10\n",
"2 2\n-2000 -2000\n3998000 4000000\n",
"2 1\n614 -1943\n3874445\n",
"1 1\n-577\n1273042\n",
"1 1\n1\n-4000000\n",
"3 1\n1416 -1483 1844\n3261895\n",
"10 10\n-25 746 298 1602 -1453 -541 -442 1174 976 -1857\n-548062 -548253 -546800 -548943 -548402 -548794... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the pa... |
876_E. National Property_14565 | You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library.
Some long and uninteresting story was removed...
The alphabet of Bookland is so large that its letters are denoted by positive integers. Each letter can be small or large, the large ve... | # ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod... | {
"input": [
"6 5\n2 1 2\n2 1 2\n3 1 2 3\n2 1 5\n2 4 4\n2 4 4\n",
"4 3\n4 3 2 2 1\n3 1 1 3\n3 2 3 3\n2 3 1\n",
"4 3\n1 2\n1 1\n3 1 3 2\n2 1 1\n",
"3 5\n2 1 2\n2 1 5\n2 4 4\n",
"6 100\n1 3\n1 5\n2 7 5\n2 7 2\n3 7 7 2\n3 7 7 3\n",
"10 4\n2 1 4\n2 1 4\n9 1 4 1 2 3 1 4 4 2\n1 4\n4 4 1 4 3\n7 4 4 4... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You all know that the Library of Bookland is the largest library in the world. There are dozens of thousands of books in the library.
Some long and uninteresting story was removed...... |
8_E. Beads_14569 | One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if on... | __author__ = 'Darren'
def solve():
def calc(lower, upper, record, eq, eq_i):
if lower > upper:
return 1
key = lower, eq, eq_i
if key in record:
return record[key]
t = 0
for x in (['0', '1'] if result[lower] == '?' else [result[lower]]):
... | {
"input": [
"4 4\n",
"3 2\n",
"50 57129577186267\n",
"6 12\n",
"50 161245081749292\n",
"5 3\n",
"49 40394027154620\n",
"7 15\n",
"49 36309684494664\n",
"50 250144743882708\n",
"49 140149194635018\n",
"5 10\n",
"6 2\n",
"6 19\n",
"50 8840088596980\n",
"6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One Martian boy called Zorg wants to present a string of beads to his friend from the Earth — Masha. He knows that Masha likes two colours: blue and red, — and right in the shop where... |
922_D. Robot Vacuum Cleaner_14573 | Pushok the dog has been chasing Imp for a few hours already.
<image>
Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.
While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of strin... | n=int(input())
a=[]
for i in range(n):
b=input()
a.append([b.count("h")/len(b),b])
a.sort()
b=""
for i in range(n):
b=b+a[i][1]
c=0
s=0
for i in range(len(b)):
if b[i]=="s":
c=c+1
if b[i]=="h":
s=s+c
print(s) | {
"input": [
"2\nh\ns\n",
"4\nssh\nhs\ns\nhhhs\n",
"100\nh\nshh\nh\nhs\nshh\nhh\nh\nssh\nhss\nh\nhh\nh\nh\nh\nh\nh\nh\nh\nh\nh\nhh\nh\nh\nh\nh\nhhh\nh\nh\nhhh\nsh\nhh\nhs\nh\nh\nshs\nh\nh\nh\nshh\nhs\nhs\nh\nh\nh\nhhh\nh\nhhs\nhh\nh\nssh\nh\nh\nhh\nsh\nh\nhss\nh\nhh\nsh\nhh\nhh\nhhh\nhs\nh\nh\nh\nshs\nhs\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Pushok the dog has been chasing Imp for a few hours already.
<image>
Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner.
While moving, the robot generates a st... |
978_C. Letters_14579 | There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in i-th dormitory are numbered from 1 to a_i.
A postman delivers letters. Sometimes there is no specific dormitory and room number in it o... | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# aa = [sum(a[:i+1]) for i in range(len(a))]
j = 0
s = a[0]
for i in range(len(b)):
while b[i] > s: # aa[j]:
j += 1
s += a[j]
print(j+1, b[i]- (s-a[j]) if j > 0 else b[i])
| {
"input": [
"2 3\n5 10000000000\n5 6 9999999999\n",
"3 6\n10 15 12\n1 9 12 23 26 37\n",
"3 10\n1000000000 1000000000 1000000000\n543678543 567869543 1000000000 1000000001 1500000000 1999999999 2000000000 2000000001 2754432345 3000000000\n",
"5 8\n10 1 1 1 10\n9 10 11 12 13 14 15 23\n",
"4 18\n5 6... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n dormitories in Berland State University, they are numbered with integers from 1 to n. Each dormitory consists of rooms, there are a_i rooms in i-th dormitory. The rooms in... |
998_B. Cutting_14583 | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti... | n, b = input().split()
n = int(n)
b = int(b)
a = [int(x) for x in input().split()]
odd = 0
not_odd = 0
pos = list()
for i in range(n-1):
if a[i] % 2 == 0:
not_odd += 1
else:
odd += 1
if not_odd == odd:
pos.append(abs(a[i+1] - a[i]))
pos.sort()
sum = 0
count = 0
for i in range(len(p... | {
"input": [
"6 100\n1 2 3 4 5 6\n",
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"100 50\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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains ... |
p02659 AtCoder Beginner Contest 169 - Multiplication 3_14597 | Compute A \times B, truncate its fractional part, and print the result as an integer.
Constraints
* 0 \leq A \leq 10^{15}
* 0 \leq B < 10
* A is an integer.
* B is a number with two digits after the decimal point.
Input
Input is given from Standard Input in the following format:
A B
Output
Print the answer as ... | a, b = input().split()
print((int(a)*round(float(b)*100))//100) | {
"input": [
"1000000000000000 9.99",
"1 0.01",
"198 1.10",
"1000000000000001 9.99",
"2 0.01",
"74 1.10",
"1000000000000101 9.99",
"1000001000000000 9.99",
"1010000000000101 9.99",
"1010000000100101 9.99",
"1000000001000000 9.99",
"1000010000000001 9.99",
"100001010... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Compute A \times B, truncate its fractional part, and print the result as an integer.
Constraints
* 0 \leq A \leq 10^{15}
* 0 \leq B < 10
* A is an integer.
* B is a number with two... |
p02788 AtCoder Beginner Contest 153 - Silver Fox vs Monster_14601 | Silver Fox is fighting with N monsters.
The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.
Silver Fox can use bombs to attack the monsters. Using a bomb at the coordinate x decreases the healths of all mo... | from math import *
import sys
input = sys.stdin.readline
def main():
N, D, A = list(map(int, input().split()))
XH = sorted([list(map(int, input().split())) for i in range(N)])
t = 0
q = []
ans = 0
for X, H in XH:
while q and q[0][0] < X-D:
x, c = q.pop(0)
t -= ... | {
"input": [
"9 4 1\n1 5\n2 4\n3 3\n4 2\n5 1\n6 2\n7 3\n8 4\n9 5",
"3 3 2\n1 2\n5 4\n9 2",
"3 0 1\n300000000 1000000000\n100000000 1000000000\n200000000 1000000000",
"9 4 1\n1 5\n2 4\n3 3\n4 2\n5 1\n6 2\n7 3\n8 4\n9 0",
"3 3 2\n1 4\n5 4\n9 2",
"3 0 1\n77888184 1000000000\n100000000 1000000000\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Silver Fox is fighting with N monsters.
The monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, ... |
p02924 AtCoder Beginner Contest 139 - ModSum_14605 | For an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.
Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.
Find the maximum possible value of M_1 + M_2 + \cdots + M_N.
Constraints
* N is an integer satisfying 1 \leq N \leq 10^9.
Input
Input is giv... | n = int(input())
m = (n-1)*n//2
print(m) | {
"input": [
"13",
"2",
"1",
"21",
"3",
"4",
"30",
"6",
"0",
"-1",
"8",
"-4",
"9",
"15",
"14",
"16",
"17",
"11",
"10",
"7",
"-17",
"25",
"-19",
"-12",
"29",
"-27",
"36",
"-23",
"-18",
"-25",
"-3... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
For an integer N, we will choose a permutation \\{P_1, P_2, ..., P_N\\} of \\{1, 2, ..., N\\}.
Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i.
Find th... |
p03059 AtCoder Beginner Contest 125 - Biscuit Generator_14609 | A biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.
Find the total number of biscuits produced within T + 0.5 seconds after activation.
Constraints
* All values in input are integers.
* 1 \leq A, B, T \le... | A, B, T = map(int,input().split(' '))
print(int(T/A)*B) | {
"input": [
"3 5 7",
"20 20 19",
"3 2 9",
"20 20 8",
"4 2 9",
"8 2 9",
"2 -2 6",
"2 -3 6",
"2 -3 10",
"2 -4 10",
"2 -8 10",
"2 -8 13",
"2 -7 13",
"2 -7 14",
"1 -7 14",
"1 -7 15",
"1 -7 3",
"38 1 -1",
"38 2 -1",
"1 -1 -1",
"3 5 11",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A biscuit making machine produces B biscuits at the following moments: A seconds, 2A seconds, 3A seconds and each subsequent multiple of A seconds after activation.
Find the total nu... |
p03203 AtCoder Grand Contest 029 - Grid game_14613 | Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i-th obstacle is at (X_i,Y_i). Here, we represent the cell at the i-th row and j-th column (1 \leq i \leq H, 1 \leq j \leq W) by (i,j). There is no obstacle at (1,1), and there is a piece ... | from operator import itemgetter
import bisect
h, w, n = map(int, input().split())
info = [tuple(map(int, input().split())) for i in range(n)]
memo = set()
for i, j in info:
memo.add(i * 10**6 + j)
pos = [[] for _ in range(w + 1)]
info = sorted(info, key = itemgetter(0))
for i, j in info:
pos[j].append(i)
a... | {
"input": [
"3 3 1\n3 2",
"100000 100000 0",
"10 10 14\n4 3\n2 2\n7 3\n9 10\n7 7\n8 1\n10 10\n5 4\n3 4\n2 8\n6 4\n4 4\n5 8\n9 2",
"3 6 1\n3 2",
"100001 100000 0",
"10 10 14\n4 3\n2 2\n7 3\n9 10\n7 9\n8 1\n10 10\n5 4\n3 4\n2 8\n6 4\n4 4\n5 8\n9 2",
"100101 100000 0",
"10 10 14\n4 3\n2 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i-th obstacle is at (X_i,Y_i). Here, we represent t... |
p03350 AtCoder Grand Contest 024 - Simple Subsequence Problem_14616 | You are given a set S of strings consisting of `0` and `1`, and an integer K.
Find the longest string that is a subsequence of K or more different strings in S. If there are multiple strings that satisfy this condition, find the lexicographically smallest such string.
Here, S is given in the format below:
* The data... | R=range;N,K=map(int,input().split());Q=R(N+1);d=[[0]*2**N for _ in Q];f=[[0]*2**N for _ in Q]
for i in Q:
for j,c in enumerate(input()):d[i][j]=int(c)
for i in R(1,N+1):
for j in R(1<<i):
t=j>>i-1&1;r=0
while r<i and j>>i-1-r&1==t:r+=1
f[i][j]=r
for i in Q:
for k in R(i+1,N+1):
z=k-i;m=(1<<z)-1
for j in R(... | {
"input": [
"4 6\n1\n01\n1011\n10111010\n1101110011111101",
"2 5\n0\n11\n1111",
"3 4\n1\n01\n1011\n01001110",
"3 4\n2\n01\n1011\n01001110",
"4 6\n1\n01\n1111\n10111010\n1101110011111101",
"3 2\n1\n01\n1011\n01001110",
"3 0\n1\n3\n1111\n01000110",
"3 4\n2\n01\n1001\n01001110",
"4 1... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set S of strings consisting of `0` and `1`, and an integer K.
Find the longest string that is a subsequence of K or more different strings in S. If there are multiple... |
p03510 Code Festival Team Relay (Parallel) - Capture_14619 | In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p. The i-th beast from the west (1 ≤ i ≤ N) is at Point x_i, and can be sold for s_i yen (the currency of Japan) if captured.
You will choose two integers L and R (L ≤ R), and throw ... | n = int(input())
ans = 0
tmp = 0
prev = 0
for x, s in (map(int, input().split()) for _ in range(n)):
dx = x - prev
if dx > tmp:
tmp = s
else:
tmp += s - dx
ans = max(ans, tmp)
prev = x
ans = max(ans, tmp)
print(ans)
| {
"input": [
"4\n1 100\n3 200\n999999999999999 150\n1000000000000000 150",
"5\n10 2\n40 5\n60 3\n70 4\n90 1",
"5\n10 20\n40 50\n60 30\n70 40\n90 10",
"4\n1 100\n3 200\n999999999999999 44\n1000000000000000 150",
"5\n10 20\n40 50\n60 35\n70 40\n90 10",
"4\n1 101\n3 200\n999999999999999 61\n10000... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p. The i-th beast from the west (1 ≤ i ≤ N) is... |
p03671 AtCoder Beginner Contest 066 - ringring_14623 | Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately.
He has very high awareness of safety, and decides to buy two bells, one for each hand.
The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the m... | print(sum(sorted([int(tok) for tok in input().split()])[:2])) | {
"input": [
"10000 10000 10000",
"700 600 780",
"10000 10100 10000",
"55 600 780",
"10000 00100 10000",
"95 600 780",
"95 652 780",
"11000 10100 10000",
"11000 10110 10000",
"57 652 734",
"11000 10111 10000",
"88 652 734",
"11000 10111 10100",
"88 102 734",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately.
He has very high awareness of safety, and decides to buy two bells, o... |
p03826 AtCoder Beginner Contest 052 - Two Rectangles_14627 | There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
Print the area of the r... | A, B, C, D = [int(_) for _ in input().split()]
print(max(A * B, C * D)) | {
"input": [
"100 600 200 300",
"3 5 2 7",
"100 600 200 6",
"3 3 2 7",
"100 480 244 6",
"0 3 0 7",
"100 169 362 6",
"100 311 362 6",
"000 311 50 6",
"110 311 50 6",
"110 222 182 6",
"-1 1 -1 10",
"111 222 182 6",
"-2 1 -1 10",
"101 222 131 6",
"-2 2 1 10... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vert... |
p03993 CODE FESTIVAL 2016 qual A - Friendly Rabbits_14631 | There are N rabbits, numbered 1 through N.
The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.
For a pair of rabbits i and j (i<j), we call the pair (i,j) a friendly pair if the following condition is met.
* Rabbit i likes rabbit j and rabbit j likes rabbit i.
Calculate ... | n = int(input())
la = [int(w)-1 for w in input().split()]
ans = 0
for i in range(n):
if la[la[i]] == i:
ans += 1
print(ans//2)
| {
"input": [
"3\n2 3 1",
"5\n5 5 5 5 1",
"4\n2 1 4 3",
"3\n3 3 1",
"5\n3 5 5 5 1",
"5\n5 4 5 2 1",
"5\n5 5 5 5 2",
"5\n5 5 5 1 1",
"4\n3 1 4 3",
"5\n5 3 5 1 1",
"4\n4 1 4 3",
"5\n5 3 5 2 1",
"5\n5 5 5 2 1",
"5\n5 5 5 1 2",
"4\n0 1 4 3",
"5\n4 3 5 2 1",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N rabbits, numbered 1 through N.
The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i.
For a pair of rabbits i and j (i<j), we cal... |
p00081 A Symmetric Point_14635 | Read a set of coordinates of three different points P1 (x1, y1), P2 (x2, y2), Q (xq, yq) on the plane, and line symmetry with point Q with the straight line passing through point P1 point P2 as the axis of symmetry. Create a program that outputs the point R (x, y) at the position of. Note that the point Q is not on its... | import math
def get_input():
while True:
try:
yield ''.join(input())
except EOFError:
break
N = list(get_input())
for l in range(len(N)):
x1,y1,x2,y2,xq,yq = [float(i) for i in N[l].split(",")]
# l: a*x + b*y + c = 0
a = y2-y1
b = x1-x2
c = y1*(x2-x1) ... | {
"input": [
"1.0,0.0,-1.0,0.0,1.0,1.0\n1.0,0.0,0.0,-1.0,3.0,0.0\n0.0,1.0,0.0,-1.0,1.0,1.0",
"1.0,0.0,-1.0,0.0,1.0,1.0\n1.0,0.0,0.0,-1.0,0.0,0.3\n0.0,1.0,0.0,-1.0,1.0,1.0",
"1.0,0.0,-1.0,0.0,1.0,1.0\n1.0,0.0,0.0,-1.0,3.0,0.0\n1.0,1.0,0.0,-1.0,1.0,1.0",
"1.0,0.0,-1.0,0.0,1.0,2.0\n1.0,0.0,0.0,-1.0,3.0,0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Read a set of coordinates of three different points P1 (x1, y1), P2 (x2, y2), Q (xq, yq) on the plane, and line symmetry with point Q with the straight line passing through point P1 p... |
p00213 Subdivide The Land_14638 | Housing maker Yamada House has launched a new featured product, a land for sale in a green home town with a rich environment such as schools and hospitals. This lot is divided into multiple lots and you can buy as many as you like, but the shape of the land with the lots you buy must be rectangular (including squares).... | from itertools import product
# from line_profiler import LineProfiler
def putpiece(X,Y,bitmap,unused,pieces,numans,pcsans,FINFLAG):
if FINFLAG:
return numans,pcsans
if not unused:
pcsans = pieces
return numans + 1, pcsans
if numans > 1:
return 2, pieces
b,k,y,x = unuse... | {
"input": [
"5 4 6\n1 6\n2 4\n3 3\n4 4\n5 1\n6 2\n0 0 1 0 0\n0 0 0 2 0\n0 0 0 3 0\n0 4 5 0 6\n3 3 1\n1 9\n0 0 1\n0 0 0\n0 0 0\n4 4 4\n1 6\n2 2\n3 4\n4 4\n0 1 0 0\n0 0 0 2\n0 0 3 0\n0 4 0 0\n0 0 0",
"5 4 6\n1 6\n2 4\n3 3\n4 4\n5 1\n6 2\n0 0 1 0 0\n0 0 0 2 0\n0 0 0 3 0\n0 4 5 0 6\n3 3 1\n1 9\n0 0 1\n0 0 0\n0 0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Housing maker Yamada House has launched a new featured product, a land for sale in a green home town with a rich environment such as schools and hospitals. This lot is divided into mu... |
p00590 Pair of Primes_14643 | We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this:
1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1
Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime.
Input
Input cont... | primes = [0, 0] + [1]*9999
for i in range(2, 101):
if primes[i]:
for j in range(i*i, 10001, i):
primes[j] = 0
while True:
try:
n = int(input())
print(sum([1 for a, b in zip(list(range(1,n+1)), list(range(1,n+1)[::-1])) if primes[a] and primes[b]]))
except:
break | {
"input": [
"1\n4\n7\n51",
"1\n8\n7\n51",
"1\n10\n7\n51",
"1\n10\n7\n65",
"1\n12\n7\n115",
"1\n12\n9\n115",
"1\n12\n9\n15",
"1\n26\n9\n15",
"1\n26\n11\n15",
"1\n26\n11\n20",
"1\n27\n11\n20",
"1\n26\n5\n20",
"1\n37\n5\n20",
"1\n37\n10\n20",
"1\n37\n20\n8",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this:
1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1
Two numbers faced ... |
p00867 Digits on the Floor_14648 | Taro attempts to tell digits to Hanako by putting straight bars on the floor. Taro wants to express each digit by making one of the forms shown in Figure 1.
Since Taro may not have bars of desired lengths, Taro cannot always make forms exactly as shown in Figure 1. Fortunately, Hanako can recognize a form as a digit i... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def dot3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)
def cross3(O, A, B):
ox, oy = O; ax, ay = A; bx, by = B
return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy)
def dist2(A, B):
... | {
"input": [
"9\n60 140 200 300\n300 105 330 135\n330 135 250 215\n240 205 250 215\n298 167 285 154\n30 40 30 90\n30 90 150 90\n150 90 150 20\n30 40 150 40\n8\n320 20 300 60\n320 20 380 50\n380 50 240 330\n10 50 40 20\n10 50 110 150\n110 150 180 80\n40 20 37 17\n37 17 27 27\n20\n72 222 132 182\n204 154 204 54\n51... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro attempts to tell digits to Hanako by putting straight bars on the floor. Taro wants to express each digit by making one of the forms shown in Figure 1.
Since Taro may not have b... |
p00998 RMQ_14651 | Given n numbers a0, a1, ..., an-1 and q.
I want you to perform appropriate processing for q queries.
The query has the following three types of operations.
* Shift the value
Given a pair of l and r. (l <r) Circular shift the value from al to ar.
0 1 2 3 4 5 6 7 8 9
Is given the query l = 2, r = 5.
The shifted numb... | INF = 10**9
def update(nd):
if nd:
l = nd[0]; r = nd[1]
nd[4] = min((l[4] if l else INF), (r[4] if r else INF), nd[2])
# splay a node nd
def __splay(st, dr, nd):
l = nd[0]; r = nd[1]
L = (l[3] if l else 0); R = (r[3] if r else 0)
c = len(st) >> 1
while c:
# y(d1)-x(d)-nd
... | {
"input": [
"10 3\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1 5 7\n0 2 5\n1 5 7",
"10 10\n289383\n930886\n692777\n636915\n747793\n238335\n885386\n760492\n516649\n641421\n2 7 368690\n1 3 6\n0 2 6\n1 1 8\n0 2 9\n2 2 665123\n1 5 9\n0 2 8\n2 7 961393\n1 1 2",
"10 3\n0\n1\n2\n3\n4\n5\n6\n7\n8\n10\n1 5 7\n0 2 5\n1 5 7",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given n numbers a0, a1, ..., an-1 and q.
I want you to perform appropriate processing for q queries.
The query has the following three types of operations.
* Shift the value
Given a... |
p01130 Water Pipe Construction_14655 | In 21XX, humanity finally began a plan to relocate to Mars. Selected as the first group of immigrants to Mars, you are assigned to the Administrative Center of Mars to deal with various problems that occur on Mars. The biggest problem at the moment of the Central Bureau is securing an independent supply and demand cycl... | 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": [
"4 5 1 3 4\n1 2 5\n2 3 5\n2 4 5\n1 3 8\n1 4 8\n0 0 0 0 0",
"4 5 1 3 4\n1 2 5\n2 3 9\n2 4 5\n1 3 8\n1 4 8\n0 0 0 0 0",
"4 5 1 3 4\n1 2 5\n2 3 9\n2 4 5\n1 3 3\n1 4 8\n0 0 0 0 0",
"6 5 1 3 4\n1 2 5\n4 3 5\n2 3 5\n1 3 8\n1 4 8\n0 0 0 0 0",
"4 5 1 3 4\n1 2 5\n2 3 5\n2 4 5\n1 3 8\n2 4 8\n0 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In 21XX, humanity finally began a plan to relocate to Mars. Selected as the first group of immigrants to Mars, you are assigned to the Administrative Center of Mars to deal with vario... |
p01269 Brave Princess Revisited_14659 | A brave princess in a poor country's tomboy is married to another country for a political marriage. However, a villain who is trying to kill the princess is releasing a thug on the way to his wife.
You have already decided on a safe route to safely deliver the princess to the other country, but with the wish of the pr... | from heapq import heappush, heappop
INF = 10 ** 20
while True:
n, m, l = map(int, input().split())
if n == 0:
break
edges = [[] for _ in range(n * (l + 1))]
for _ in range(m):
a, b, d, e = map(int, input().split())
a -= 1
b -= 1
for i in range(d, l + 1):
edges[i * n + a].append((0, (... | {
"input": [
"3 2 10\n1 2 8 6\n2 3 10 3\n3 2 10\n1 2 3 8\n2 3 7 7\n3 3 10\n1 3 17 6\n1 2 2 4\n2 3 9 13\n4 4 5\n1 3 9 3\n1 4 7 25\n2 3 8 2\n2 4 9 3\n0 0 0",
"3 2 10\n1 2 8 6\n2 3 10 0\n3 2 10\n1 2 3 8\n2 3 7 7\n3 3 10\n1 3 17 6\n1 2 2 4\n2 3 9 13\n4 4 5\n1 3 9 3\n1 4 7 25\n2 3 8 2\n2 4 9 3\n0 0 0",
"3 2 10... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A brave princess in a poor country's tomboy is married to another country for a political marriage. However, a villain who is trying to kill the princess is releasing a thug on the wa... |
p01439 Chinese Classics_14662 | Taro, a junior high school student, is working on his homework. Today's homework is to read Chinese classic texts.
As you know, Japanese language shares the (mostly) same Chinese characters but the order of words is a bit different. Therefore the notation called "returning marks" was invented in order to read Chinese ... | import re
num = re.compile(r'\d+$')
def testcase_ends():
n = int(input())
if n == 0:
return 1
marks = [input().replace('-', '') for i in range(n)]
links = {}
bares = []
labels = {}
for i, mark in enumerate(marks, 1):
if not mark:
bares.append(i)
con... | {
"input": [
"6\nonetwo2\n-\nonetwo1\nonetwo2\n-\nonetwo1\n7\nv\ntopbottom2\nonetwo2\n-\nonetwo1\ntopbottom1\n-\n6\nbaz2\nfoo2\nbaz1v\nbar2\nfoo1\nbar1\n0",
"6\nonetwo2\n-\nonetwo1\nonetwo2\n-\nonetwo1\n7\nv\ntopbottom2\nonetwo2\n-\nonetwo1\ntopbottom1\n-\n6\nbaz2\nfoo2\nbaz1v\nbar1\nfoo1\nbar1\n0",
"6\no... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Taro, a junior high school student, is working on his homework. Today's homework is to read Chinese classic texts.
As you know, Japanese language shares the (mostly) same Chinese cha... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.