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 |
|---|---|---|---|---|---|
313_C. Ilya and Matrix_28319 | Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got a square 2n × 2n-sized matrix and 4n integers. You need to arrange all these numbers in the matrix (put each number in a single individua... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self... | {
"input": [
"1\n13\n",
"4\n1 2 3 4\n",
"16\n521848329 105907607 414661942 473600423 264555612 186332345 774233687 736918178 456150336 216550357 568433949 135218174 18789799 324141005 617635501 149674864\n",
"1\n6\n",
"16\n666766712 653140033 670637874 170909587 210382562 358152171 128926299 75068... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve.
He's got ... |
335_F. Buy One, Get One Free_28322 | A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.
Input
Input will begin with an integer n (1 ≤ n... | #https://codeforces.com/problemset/problem/335/F
h = [i for i in range(500001)]
t = [i for i in range(500001)]
ans = 0
len = 0
nw = 0
tot = 0
cnt = 0
a = []
def work(x):
y = x >> 1
while y and h[y] > h[x]:
tmp = h[x]
h[x] = h[y]
h[y] = tmp
x = y
y = x >> 1
def pop():
... | {
"input": [
"4\n309999 6000 2080 2080\n",
"5\n5 5 5 5 5\n",
"6\n3 4 5 3 4 5\n",
"30\n3 6 3 8 6 4 4 2 4 10 8 5 9 6 7 7 9 4 7 4 10 1 9 10 4 7 7 4 2 3\n",
"1\n1\n",
"50\n4 2 6 7 2 6 3 8 8 2 4 8 4 4 1 4 5 2 2 5 6 4 3 3 3 6 8 2 1 3 1 8 2 3 7 4 7 5 4 8 3 5 7 8 6 7 5 8 7 1\n",
"40\n2 6 5 5 6 6 7... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies yo... |
359_A. Table_28325 | Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1... | n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
if (i==0 or i==n-1) and sum(l[i]): print(2); break
elif l[i][0]==1 or l[i][-1]==1: print(2); break
else: print(4)
| {
"input": [
"4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n",
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"4 32\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\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\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\n0 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:
Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starti... |
452_C. Magic Trick_28336 | Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs n cards at random and performs the trick with those. The resulting deck looks like a normal deck, but m... | import sys
import os
n,m = map(float, sys.stdin.readline().split())
res = 0
if (n == 1):
res = 1
else:
res = (1+(n-1)*(m-1)/(n*m-1))/n
print(res) | {
"input": [
"4 4\n",
"1 2\n",
"2 2\n",
"1000 1000\n",
"998 1\n",
"999 999\n",
"555 543\n",
"2 987\n",
"1 999\n",
"321 123\n",
"1 1\n",
"987 123\n",
"678 231\n",
"10 10\n",
"2 1\n",
"461 1000\n",
"2 3\n",
"998 2\n",
"999 504\n",
"555 907\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wish... |
475_A. Bayan Bus_28340 | The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
<image>
The event coordinator has a list of k participants who should be picked up at the airport.... | def main():
n = int(input())
print("+------------------------+")
b1 = 0
if n == 0:
b1 = 0
elif 1 <= n <= 4:
b1 = 1
else:
b1 = (n + 1) // 3
if 0 <= n <= 1:
b2 = 0
elif 2 <= n <= 5:
b2 = 1
else:
b2 = n // 3
b3 = 0
if n < 3:
... | {
"input": [
"9\n",
"20\n",
"10\n",
"18\n",
"0\n",
"23\n",
"21\n",
"1\n",
"11\n",
"13\n",
"6\n",
"3\n",
"22\n",
"5\n",
"19\n",
"30\n",
"16\n",
"2\n",
"15\n",
"28\n",
"31\n",
"33\n",
"14\n",
"12\n",
"32\n",
"8\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last... |
499_A. Watching a movie_28344 | You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.
2. Skip exactly x minutes of the movi... | class CodeforcesTask499ASolution:
def __init__(self):
self.result = ''
self.n_x = []
self.best_moments = []
def read_input(self):
self.n_x = [int(x) for x in input().split(" ")]
for x in range(self.n_x[0]):
self.best_moments.append([int(j) for j in input().sp... | {
"input": [
"2 3\n5 6\n10 12\n",
"1 1\n1 100000\n",
"1 100\n5 6\n",
"1 3\n4 100000\n",
"1 2\n2 100000\n",
"2 100\n5 6\n7 7\n",
"12 14\n2156 3497\n4784 7775\n14575 23857\n29211 30739\n31932 33447\n35902 36426\n47202 48772\n60522 63982\n68417 78537\n79445 86918\n90081 90629\n94325 95728\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have decided to watch the best moments of some movie. There are two buttons on your player:
1. Watch the current minute of the movie. By pressing this button, you watch the cu... |
522_B. Photo to Remember_28348 | One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of... | h,w=[],[]
n=int(input())
for i in range(n):
a,b=map(int,input().split())
w.append(a)
h.append(b)
maxh=max(h)
maxh2=-1
if h.count(maxh)>1: maxh2=maxh
else:
for i in h:
if i<maxh:
maxh2=max(maxh2,i)
sumw=sum(w)
for i in range(n):
W=sumw-w[i]
if h[i]==maxh: H=maxh2
else: H=m... | {
"input": [
"3\n1 10\n5 5\n10 1\n",
"3\n2 1\n1 2\n2 1\n",
"10\n6 386\n9 816\n9 268\n9 481\n8 284\n10 715\n9 351\n7 580\n4 327\n7 392\n",
"10\n9 292\n4 6\n6 638\n8 461\n10 970\n10 488\n9 769\n10 644\n8 280\n5 334\n",
"3\n1 11\n1 12\n1 13\n",
"10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can b... |
549_D. Haar Features_28352 | The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.
Let's consider a rectangular image that is represent... | n,m=map(int,input().strip().split())
s=[]
for i in range(n):
s.append(input())
f=[[0 for i in range(m+1)] for j in range(n+1)]
ans=0
for k in range(n+m,1,-1):
for i in range(n,0,-1):
j=k-i
if (j>m or j<1):
continue
#print(str(i)+" "+str(j)+s[i-1][j-1])
tmp=0
i... | {
"input": [
"3 3\nWBW\nBWW\nWWW\n",
"3 6\nWWBBWW\nWWBBWW\nWWBBWW\n",
"6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n",
"4 4\nBBBB\nBBBB\nBBBB\nBBBW\n",
"1 52\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n",
"2 10\nBBWBWWBWBB\nBBBBBBBBBW\n",
"4 5\nBWWBB\nBWBBW\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes H... |
598_A. Tricky Sum_28359 | In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for t values of n.
Input
The first line of... | t = int(input())
while(t):
n = int(input())
s = n*(n+1) // 2
k = len(format(n, "b"))
s_pair = 2**k - 1
print(s - 2*s_pair)
t-=1 | {
"input": [
"2\n4\n1000000000\n",
"1\n414232\n",
"10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n",
"13\n1\n19\n31\n19\n19\n92\n74\n69\n32\n32\n91\n42\n73\n",
"1\n121\n",
"100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1... |
667_A. Pouring Rain_28367 | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | from math import pi
d,h,v,e=map(int,input().split())
v=v/(pi*((d/2)**2))
d=h/(v-e)
if v-e>0 and d<=10000:
print('YES')
print(d)
else:
print('NO') | {
"input": [
"1 1 1 1\n",
"1 2 3 100\n",
"5 2797 5925 9\n",
"6 1976 8455 3\n",
"72 8534 7042 65\n",
"4 495 8813 1\n",
"100 5635 9099 23\n",
"72 6791 8546 46\n",
"72 5272 4552 64\n",
"1 47 80 68\n",
"10000 10000 10000 10000\n",
"48 7946 7992 72\n",
"48 6428 9807 83\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the st... |
690_B2. Recover Polygon (medium)_28370 | Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of the lattice, Heidi knows the level of Zombie Contamination – the number of ... | import math
def lexComp(a, b):
if a[0] != b[0]:
return -1 if a[0] < b[0] else 1
if a[1] != b[1]:
return -1 if a[1] < b[1] else 1
return 0
def turn(a, b, c):
return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])
def dist2(a, b):
return (a[0] - b[0]) ** 2 + (a[1] ... | {
"input": [
"8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0\n",
"8 19\n2 3 2 4 2 5 3 3 3 5 4 3 4 5 4 6 5 2 5 3 5 6 6 2 6 3 6 4 6 5 6 6 6 7 7 6 7 7\n5 8\n2 2 2 3 2 4 3 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of ... |
713_C. Sonya and Problem Wihtout a Legend_28374 | Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati... | # Idea:
# convert the problem to making array a non decreasing by decreasing each ai by i
# Now we can argue that the optimal final array must have
# each element equal to some element of the array a.
# Proof is to assume optimal solution does not satisfy this then you can
# always increase or decrease one element whi... | {
"input": [
"5\n5 4 3 2 1\n",
"7\n2 1 5 11 5 9 11\n",
"5\n850 840 521 42 169\n",
"1\n1000\n",
"2\n1000 1\n",
"75\n392 593 98 533 515 448 220 310 386 79 539 294 208 828 75 534 875 493 94 205 656 105 546 493 60 188 222 108 788 504 809 621 934 455 307 212 630 298 938 62 850 421 839 134 950 256 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any elem... |
734_A. Anton and Danik_28378 | Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
Input
The first line of the input contains a... | n=int(input())
s=input()
c=0
c1=0
for i in s:
if i=="D":
c=c+1
else:
c1=c1+1
if c>c1:
print("Danik")
elif c<c1:
print("Anton")
else:
print("Friendship") | {
"input": [
"7\nDDDAADA\n",
"6\nDADADA\n",
"6\nADAAAA\n",
"40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA\n",
"3\nDAD\n",
"200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADAD... | 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, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended... |
758_A. Holiday Of Equality_28382 | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in ai burles (burle is the currency in Berland).
... | n = int(input())
s = 0
mx = 0
a = list((map(int,input().split())))
for i in range(n):
s+=a[i]
mx = max(mx,a[i])
print(mx*n-s) | {
"input": [
"1\n12\n",
"5\n0 1 2 3 4\n",
"3\n1 3 1\n",
"5\n1 1 0 1 1\n",
"45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 7868... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally i... |
779_E. Bitwise Formula_28386 | Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.
Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, ... | n, m = map(int, input().split())
v = [('?', '')]
temp = [(0, 1)]
d = {}
d['?'] = 0
mn, mx = '', ''
for i in range(n):
name, val = input().split(' := ')
v.append((name, val.split()))
temp.append((-1, -1))
d[name] = i + 1
def eval(expr, bit1, bit2):
if expr == 'OR':
return bit1 | bit2
... | {
"input": [
"3 3\na := 101\nb := 011\nc := ? XOR b\n",
"5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n",
"1 6\na := ? OR ?\n",
"29 2\naa := 10\nba := 11\nca := 01\nda := aa AND ?\nea := ba OR ?\nfa := da XOR ?\nga := 11\nha := fa XOR ea\nia := 01\nja := ca OR ha\nka := ha XOR ia\nl... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game.
Initially, Bob chooses integer m, bit depth o... |
802_M. April Fools' Problem (easy)_28390 | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea... | n,k=map(int,input().split());print(sum(sorted(list(map(int,input().split())))[:k])) | {
"input": [
"8 5\n1 1 1 1 1 1 1 1\n",
"10 3\n16 8 2 4 512 256 32 128 64 1\n",
"6 6\n6 6 6 6 6 6\n",
"1 1\n100\n",
"5 1\n20 10 50 30 46\n",
"10 5\n147 1917 5539 7159 5763 416 711 1412 6733 4402\n",
"100 60\n1443 3849 6174 8249 696 8715 3461 9159 4468 2496 3044 2301 2437 7559 7235 7956 8959... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a ... |
827_B. High Load_28394 | Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k of the nodes should be exit-nodes, that means that each of them should be ... | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writab... | {
"input": [
"5 3\n",
"3 2\n",
"5 2\n",
"1013 2\n",
"1000 999\n",
"4 2\n",
"1000 5\n",
"7 6\n",
"1024 511\n",
"7 5\n",
"1024 512\n",
"6 4\n",
"7 4\n",
"1013 16\n",
"1024 513\n",
"7 3\n",
"1000 670\n",
"100 99\n",
"10 6\n",
"1013 23\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires in... |
849_B. Tell Your World_28398 | Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible to draw two parallel and non-overlapping lines, such that every point in the set lies on exactly one of them, and each of them passes th... | def run():
n = int(input())
a = [int(x) for x in input().split()]
_s = set(a)
if len(_s) == 1:
print('No')
return
if len(_s) == 2:
print('Yes')
return
def check(dy, base):
st = [False] * n
for i in range(n):
if (a[i] - a[base]) * 2 =... | {
"input": [
"5\n7 5 8 6 9\n",
"5\n-1 -2 0 0 -5\n",
"5\n1000000000 0 0 0 0\n",
"5\n5 4 3 2 1\n",
"5\n-954618456 -522919664 -248330428 -130850748 300848044\n",
"6\n1 2 4 5 7 9\n",
"5\n7 5 9 10 8\n",
"5\n7 5 8 6 3\n",
"5\n1 2 3 3 3\n",
"4\n1 3 4 4\n",
"10\n-6568 -5920 -5272 -... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Connect the countless points with lines, till we reach the faraway yonder.
There are n points on a coordinate plane, the i-th of which being (i, yi).
Determine whether it's possible... |
870_E. Points, Lines and Ready-made Titles_28402 | You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.
You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109 + 7.... | import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
n = mint()
p = [0]*n
x = dict()
y = dict()
for i in range(n):
a = tuple(mints())
p[i] = a
if a[0] in x:
x[a[0]].append(i)
else:
x[a[0]] = [i]
if a[1] ... | {
"input": [
"2\n-1 -1\n0 1\n",
"4\n1 1\n1 2\n2 1\n2 2\n",
"6\n0 2\n-1 1\n1 -2\n2 1\n-2 1\n-2 0\n",
"6\n-1 2\n0 -1\n-1 -2\n0 1\n-1 0\n1 0\n",
"1\n0 0\n",
"10\n504155727 -77293021\n-155983273 -43296260\n-548837441 -43296260\n88335251 -77293021\n970294418 -43296260\n-155983273 850521645\n-852404... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.
... |
897_D. Ithea Plays With Chtholly_28406 | This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight.
<image>
Initially, Ithea puts n clear sheets of paper in a line. They are numbered from 1 to n from left to right.
This game ... | import sys
n, m, c = map(int, input().split())
free = n
nums = [0] * n
for i in range(m):
pi = int(input())
if(pi > c//2):
current = n - 1
while(nums[current] > 0 and nums[current] >= pi and current >= 0):current -= 1
if(current == -1):current = 0
if(nums[current] == 0):free -=... | {
"input": [
"2 4 4\n2\n1\n3\n",
"4 4 2\n2\n2\n2\n1\n",
"3 6 3\n3\n3\n2\n2\n1\n1\n",
"2 2 1\n1\n1\n",
"3 6 3\n1\n2\n1\n3\n1\n3\n",
"4 8 4\n2\n3\n2\n3\n2\n3\n2\n3\n",
"10 100 20\n4\n1\n15\n2\n11\n1\n18\n9\n17\n5\n17\n12\n20\n6\n14\n19\n20\n3\n6\n14\n12\n17\n17\n10\n11\n8\n6\n6\n19\n16\n20\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem. Refer to the Interaction section below for better understanding.
Ithea and Chtholly want to play a game in order to determine who can use the kitchen ... |
940_E. Cashback_28412 | Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount.
You are given an array a of length n and an integer c.
The value of some array b of length k is the sum of its elements except for the <image> smallest. For example, the value of the array [3, 1, 6, 5, 2]... | from heapq import *
f = lambda: map(int, input().split())
n, c = f()
a = list(f()) + [0] * c
b = [0] * (n + c)
s = 0
h = [(0, -1)]
for i in range(n):
s += a[i] - a[i - c]
heappush(h, (a[i], i))
while h[0][1] <= i - c: heappop(h)
b[i] = min(b[i - 1] + a[i], b[i - c] + s - h[0][0])
print(b[n - 1]) | {
"input": [
"3 5\n1 2 3\n",
"7 2\n2 3 6 4 5 7 1\n",
"8 4\n1 3 4 5 5 3 4 1\n",
"12 10\n1 1 10 10 10 10 10 10 9 10 10 10\n",
"15 10\n4 5 5 5 5 5 5 5 5 5 5 5 5 5 1\n",
"15 5\n1 67 1 100 67 34 67 34 34 1 1 34 34 1 67\n",
"15 5\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"9 10\n20 54 35 72 35 35 64... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount.
You are given an array a of length n and an integer c.
The value of... |
96_B. Lucky Numbers (easy)_28416 | Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo... | gh=set()
def rep(n,four,seven):
global gh
if n>10000000000 :return
if (four==seven):gh|={n}
rep(n*10+4,four+1,seven)
rep(n*10+7,four,seven+1)
rep(0,0,0)
gh=sorted(gh)
def bin_s(a):
lo=0;hi=len(gh);ans=0
while lo<=hi:
mid=(lo+hi)//2
if gh[mid]>=a:ans=gh[mid];hi=mid-1
e... | {
"input": [
"4500\n",
"47\n",
"447777\n",
"444000000\n",
"99\n",
"48\n",
"7773\n",
"7748\n",
"10\n",
"1\n",
"7474747\n",
"50\n",
"4\n",
"147474747\n",
"444444444\n",
"4700007\n",
"87584777\n",
"123\n",
"4777\n",
"19\n",
"1024\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 ... |
994_B. Knights of a Polygonal Table_28420 | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
x=a[i]
y=b[i]
l.append((x,y))
l.sort()
ans=[]
j=0
if k==0:
print(*b)
else:
for i in range(n):
if i<k:
ans.append(l[i][1])
ans.sort()
... | {
"input": [
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n",
"4 2\n4 5 9 7\n1 2 11 33\n",
"3 0\n1 2 3\n10 20 30\n",
"2 0\n2 3\n3 3\n",
"11 10\n1 2 3 4 5 6 7 8 9 10 11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if... |
p02634 AtCoder Grand Contest 046 - Extension_28433 | We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation:
* Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical" or "horizontal".
* If we choose "vertical", insert one row at th... | a, b, c, d = map(int,input().split())
mod = 998244353
A = [[0] * (d+1) for i in range(c+1)]
A[a][b] = 1
for i in range(a, c+1):
for j in range(b, d+1):
A[i][j] = (A[i][j] + A[i][j-1] * i + A[i-1][j] * j ) % mod
if i!=a and j!=b:
A[i][j] = (A[i][j] - A[i-1][j-1] * (i-1)*(j-1)) % mod
pri... | {
"input": [
"2 1 3 4",
"31 41 59 265",
"1 1 2 2",
"2 0 3 4",
"54 41 59 265",
"1 0 2 2",
"2 0 3 0",
"54 41 59 202",
"1 0 2 3",
"2 0 3 1",
"41 41 59 202",
"2 0 3 2",
"50 41 59 202",
"1 0 2 1",
"2 0 6 2",
"4 0 6 2",
"4 0 6 4",
"4 0 6 7",
"3 0 6... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation:
* Assume that the grid c... |
p02765 AtCoder Beginner Contest 156 - Beginner_28437 | Takahashi is a member of a programming competition site, ButCoder.
Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating.
The Displayed Rating of a member is equal to their Inner Rating if the member has participated in 10 or more contests. Otherwise, the Displayed Rating will be their Inn... | N, R = map(int, input().split())
print(R + max(0, 100 * (10 - N))) | {
"input": [
"2 2919",
"22 3051",
"2 4162",
"17 3051",
"1 4162",
"17 3619",
"1 1703",
"1 1051",
"0 1051",
"0 1885",
"76 6963",
"0 1615",
"76 3451",
"0 2265",
"76 835",
"-1 2265",
"76 1018",
"1 2265",
"76 170",
"0 503",
"-1 503",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi is a member of a programming competition site, ButCoder.
Each member of ButCoder is assigned two values: Inner Rating and Displayed Rating.
The Displayed Rating of a membe... |
p02900 AtCoder Beginner Contest 142 - Disjoint Set of Common Divisors_28441 | Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divisors can we choose?
Definition of common divisor
An integer d is said to be a common divisor of integers x and y when d divides both x a... | import fractions
a,b=map(int,input().split())
g=fractions.gcd(a,b)
#print(g)
ans=1
i=2
while i*i<=g:
if(g%i==0):
ans+=1
while g%i==0:
g/=i
i=i+1
if(g!=1):ans+=1
print(ans) | {
"input": [
"1 2019",
"12 18",
"420 660",
"2 2019",
"420 324",
"3 2019",
"19 18",
"19 16",
"420 71",
"6 2019",
"19 9",
"420 47",
"6 949",
"31 9",
"411 47",
"6 1591",
"40 9",
"411 17",
"8 1591",
"66 9",
"442 17",
"4 1591",
"66... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are positive integers A and B.
Let us choose some number of positive common divisors of A and B.
Here, any two of the chosen divisors must be coprime.
At most, how many divis... |
p03035 AtCoder Beginner Contest 127 - Ferris Wheel_28445 | Takahashi, who is A years old, is riding a Ferris wheel.
It costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12 years old (inclusive) can ride it for half the cost, and children who are 5 years old or younger are free of charge. (Yen is the currenc... | a,b = map(int,input().split())
if a > 12:
print(b)
elif a < 6:
print(0)
else:
print(b//2) | {
"input": [
"0 100",
"30 100",
"12 100",
"-1 100",
"15 100",
"6 111",
"9 100",
"16 110",
"17 101",
"25 111",
"59 011",
"89 001",
"30 010",
"9 010",
"1 100",
"-2 100",
"17 100",
"2 100",
"-2 000",
"2 101",
"0 000",
"-2 001",
"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Takahashi, who is A years old, is riding a Ferris wheel.
It costs B yen (B is an even number) to ride the Ferris wheel if you are 13 years old or older, but children between 6 and 12... |
p03176 Educational DP Contest - Flowers_28449 | There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct.
Taro is pulling out some flowers so that the following condition is met:
* The heights of the remaining flowers ar... | class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s = max(s, self.tree[i])
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] = max... | {
"input": [
"5\n1 2 3 4 5\n1000000000 1000000000 1000000000 1000000000 1000000000",
"4\n3 1 4 2\n10 20 30 40",
"1\n1\n10",
"9\n4 2 5 8 3 6 1 7 9\n6 8 8 4 6 3 5 7 5",
"5\n1 2 3 4 5\n1000000000 1000000010 1000000000 1000000000 1000000000",
"4\n3 1 4 2\n10 20 2 40",
"9\n4 2 5 8 3 6 1 7 9\n6 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h... |
p03324 AtCoder Beginner Contest 100 - Ringo's Favorite Numbers_28453 | Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.
Find the N-th smallest intege... | D, N = map(int, input().split(" "))
print(((100**D)*(N+(N//100))))
| {
"input": [
"2 85",
"1 11",
"0 5",
"2 37",
"2 11",
"-1 5",
"2 40",
"2 19",
"-1 9",
"2 57",
"3 19",
"0 9",
"2 86",
"0 19",
"-1 2",
"2 63",
"-1 19",
"2 71",
"-1 35",
"2 84",
"-1 66",
"1 84",
"-1 43",
"1 63",
"-1 8",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.
As the name of the contest is AtCoder Beginner Conte... |
p03478 AtCoder Beginner Contest 083 - Some Sums_28457 | Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
Constraints
* 1 \leq N \leq 10^4
* 1 \leq A \leq B \leq 36
* All input values are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the s... | N, A, B = map(int, input().split())
print(sum(i for i in range(1, N+1) if A <= sum(int(c) for c in str(i)) <= B))
| {
"input": [
"10 1 2",
"20 2 5",
"100 4 16",
"10 1 0",
"20 2 6",
"100 4 12",
"20 3 6",
"100 5 12",
"20 1 6",
"37 2 6",
"101 3 12",
"37 1 6",
"37 1 9",
"37 1 18",
"001 1 12",
"37 1 2",
"37 1 3",
"4 1 6",
"101 -1 6",
"6 -2 6",
"5 -3 10"... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
Constraints
* 1 \leq N \leq 10^4
* 1 \leq A \leq B \... |
p03643 AtCoder Beginner Contest 068 - ABCxxx_28461 | This contest, AtCoder Beginner Contest, is abbreviated as ABC.
When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.
What is the abbreviation for the N-th round of ABC? Write a program to output the answer.
Constraints
* 100 ≤ N ≤ 999
I... | S = input()
print("ABC"+S) | {
"input": [
"999",
"425",
"100",
"1530",
"820",
"110",
"2825",
"293",
"5621",
"258",
"238",
"411",
"87",
"789",
"33",
"415",
"36",
"542",
"34",
"205",
"52",
"294",
"74",
"105",
"97",
"186",
"183",
"292",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This contest, AtCoder Beginner Contest, is abbreviated as ABC.
When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th ... |
p03801 AtCoder Regular Contest 069 - Frequency_28465 | Snuke loves constructing integer sequences.
There are N piles of stones, numbered 1 through N. The pile numbered i consists of a_i stones.
Snuke will construct an integer sequence s of length Σa_i, as follows:
1. Among the piles with the largest number of stones remaining, let x be the index of the pile with the sma... | N = int(input())
As = list(map(int, input().split()))
sorted_iAs = sorted(map(tuple, enumerate(As)), key = lambda t: (t[1], t[0]), reverse = True)
#if As = 1 2 1 3 2 4 2 5 8 1
#then sorted_iAs is:
# i | 8 7 5 3 6 4 1 9 2 0
# A | 8 5 4 3 2 2 2 1 1 1
#I'll look at:
# x x x x x x
#where the next A decr... | {
"input": [
"2\n1 2",
"10\n1 2 1 3 2 4 2 5 8 1",
"10\n1 2 2 3 2 4 2 5 8 1",
"10\n1 3 2 3 2 4 2 5 8 1",
"10\n1 3 2 3 2 4 4 5 8 1",
"2\n1 0",
"10\n1 2 1 3 2 4 1 5 8 1",
"10\n1 2 1 3 2 4 2 5 8 0",
"10\n1 3 2 4 2 4 2 5 8 1",
"10\n1 3 2 6 2 4 4 5 8 1",
"2\n1 1",
"10\n1 2 1 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Snuke loves constructing integer sequences.
There are N piles of stones, numbered 1 through N. The pile numbered i consists of a_i stones.
Snuke will construct an integer sequence s... |
p00058 Orthogonal_28471 | Read the coordinates of four different points on the plane, $ A (x_A, y_A) $, $ B (x_B, y_B) $, $ C (x_C, y_C) $, $ D (x_D, y_D) $, and straight line $ Create a program that outputs YES if AB $ and $ CD $ are orthogonal, and NO if they are not orthogonal. Here, "straight line" does not mean a line segment. Please refer... | E = 10 ** -10
while True:
try:
xa, ya, xb, yb, xc, yc, xd, yd = map(float, input().split())
vabx, vaby = xb - xa, yb - ya
vcdx, vcdy = xd - xc, yd - yc
print("YES" if abs(vabx * vcdx + vaby * vcdy) < E else "NO")
except EOFError:
break
| {
"input": [
"1.0 1.0 2.0 2.0 0.0 0.0 1.0 -1.0\n0.0 0.0 2.0 0.0 -1.0 2.0 2.0 2.0\n10.0 6.0 3.4 5.2 6.8 9.5 4.3 2.1\n2.5 3.5 2.5 4.5 -3.3 -2.3 6.8 -2.3",
"1.0 1.0 2.0 2.0 0.0 0.0 1.0 -1.0\n0.0 0.0 2.0 0.0 -1.0 2.0 2.0 2.0\n10.0 6.0 3.4 5.2 6.8 9.5 4.3 2.1\n2.5 3.5 2.5 5.324353001023156 -3.3 -2.3 6.8 -2.3",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Read the coordinates of four different points on the plane, $ A (x_A, y_A) $, $ B (x_B, y_B) $, $ C (x_C, y_C) $, $ D (x_D, y_D) $, and straight line $ Create a program that outputs Y... |
p00189 Convenient Location_28475 | Mr. A, who will graduate next spring, decided to move when he got a job. The company that finds a job has offices in several towns, and the offices that go to work differ depending on the day. So Mr. A decided to live in a town where he had a short time to go to any office.
So you decided to find the most convenient t... | INF = 10 ** 10
while True:
n = int(input())
if n == 0:
break
costs = [[INF] * 10 for _ in range(10)]
for i in range(10):
costs[i][i] = 0
city = set()
for _ in range(n):
a, b, c = map(int, input().split())
city = city | {a, b}
costs[a][b] = c
costs[b][a] = c
city = sorted(li... | {
"input": [
"6\n0 1 80\n1 2 20\n0 2 60\n2 3 50\n3 4 60\n1 4 90\n2\n0 1 1\n1 2 1\n0",
"6\n0 1 80\n1 2 20\n0 2 60\n2 3 50\n3 4 66\n1 4 90\n2\n0 1 1\n1 2 1\n0",
"6\n0 1 80\n1 2 20\n0 2 60\n2 3 50\n3 4 66\n0 4 90\n2\n0 1 1\n1 2 1\n0",
"6\n0 1 80\n1 2 20\n0 2 60\n2 2 50\n3 4 66\n0 4 90\n2\n0 1 1\n1 2 1\n0... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Mr. A, who will graduate next spring, decided to move when he got a job. The company that finds a job has offices in several towns, and the offices that go to work differ depending on... |
p00344 Cyclic Sugoroku_28478 | Yuki made a sugoroku so that everyone can play at the children's association event. In this sugoroku, squares are lined up in a ring, and each square has an integer of 1 or more written on it.
The player chooses a square as a starting point and places his piece. Advance the pieces clockwise by the number written on th... | import sys
sys.setrecursionlimit(1000000)
def dfs(x, order, edges, visited):
visited[x] = True
for e in edges[x]:
if not visited[e]:
dfs(e, order, edges, visited)
order.append(x)
def dfs_rev(x, rev_edges, visited):
visited[x] = True
ret = 0
for e in rev_edges[x]:
if not visited[e]:
ret... | {
"input": [
"3\n1 1 1",
"8\n2 3 7 3 3 3 4 4",
"3\n1 1 2",
"3\n2 1 1",
"8\n2 3 7 3 3 1 4 4",
"3\n1 1 3",
"3\n1 2 3",
"8\n2 4 4 0 3 4 4 4",
"8\n0 3 6 0 5 4 4 4",
"8\n0 3 5 1 6 0 0 4",
"8\n1 1 1 2 11 1 -2 1",
"3\n2 1 0",
"8\n2 3 4 3 3 1 4 4",
"3\n1 1 0",
"8\n2... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Yuki made a sugoroku so that everyone can play at the children's association event. In this sugoroku, squares are lined up in a ring, and each square has an integer of 1 or more writt... |
p00843 Bingo_28485 | A Bingo game is played by one gamemaster and several players. At the beginning of a game, each player is given a card with M × M numbers in a matrix (See Figure 10).
<image>
As the game proceeds, the gamemaster announces a series of numbers one by one. Each player punches a hole in his card on the announced number, i... | def solve():
from itertools import product
from sys import stdin
f_i = stdin
while True:
P, M = map(int, f_i.readline().split())
if P == 0:
break
bingo = []
for i in range(P):
b = []
card = list(map(int, f_i.readline().spl... | {
"input": [
"4 3\n10 25 11 20 6 2 1 15 23\n5 21 3 12 23 17 7 26 2\n8 18 4 22 13 27 16 5 11\n19 9 24 2 11 5 14 28 16\n4 3\n12 13 20 24 28 32 15 16 17\n12 13 21 25 29 33 16 17 18\n12 13 22 26 30 34 17 18 15\n12 13 23 27 31 35 18 15 16\n4 3\n11 12 13 14 15 16 17 18 19\n21 22 23 24 25 26 27 28 29\n31 32 33 34 35 36 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A Bingo game is played by one gamemaster and several players. At the beginning of a game, each player is given a card with M × M numbers in a matrix (See Figure 10).
<image>
As the ... |
p01107 Go around the Labyrinth_28488 | Go around the Labyrinth
Explorer Taro got a floor plan of a labyrinth. The floor of this labyrinth is in the form of a two-dimensional grid. Each of the cells on the floor plan corresponds to a room and is indicated whether it can be entered or not. The labyrinth has only one entrance located at the northwest corner, ... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import copy
def rdp_connect() -> bool:
global n, m, c
n, m = map(int, input().split())
if n == m == 0:
return False
c = [list(input()) for _ in range(n)]
return True
def rdp_check() -> bool:
DY = (0, 1, 0, -1)
DX = (1, 0, -1, 0)
... | {
"input": [
"3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n.....\n.....\n3 8\n..#.....\n........\n.....#..\n3 5\n..#..\n.....\n..#..\n4 4\n....\n....\n..##\n..#.\n0 0",
"3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n.....\n.....\n3 8\n..#.....\n........\n.....#..\n3 5\n..#..\n-....\n..#..\n4 4\n....\n....\n.... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Go around the Labyrinth
Explorer Taro got a floor plan of a labyrinth. The floor of this labyrinth is in the form of a two-dimensional grid. Each of the cells on the floor plan corre... |
p01560 Enumeration_28493 | Given n integers a1, a2,…, an and n integers p1, p2,…, pn, integer m. The operation of selecting the kth integer ak with a probability of pk [%] is performed for each k (1 ≤ k ≤ n), and 0 or more and n or less integers are selected. Find the expected number of integers between 1 and m that are divisible by at least one... | 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": [
"2 15\n3 5\n50 50",
"4 100\n2 3 5 7\n80 60 40 20",
"4 210\n2 3 5 7\n80 60 40 20",
"2 15\n3 5\n50 72",
"4 100\n1 3 5 7\n80 60 40 20",
"4 210\n2 2 5 7\n80 60 40 20",
"2 15\n3 5\n32 72",
"4 100\n1 3 8 7\n80 60 40 20",
"2 210\n2 2 5 7\n80 60 40 20",
"2 15\n3 5\n32 64",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given n integers a1, a2,…, an and n integers p1, p2,…, pn, integer m. The operation of selecting the kth integer ak with a probability of pk [%] is performed for each k (1 ≤ k ≤ n), a... |
p01722 Fast Division_28497 | Ikta loves fast programs. Recently, I'm trying to speed up the division program. However, it doesn't get much faster, so I thought it would be better to make it faster only for "common sense and typical" inputs. The problem Ikta is trying to solve is as follows.
For a given non-negative integer n, divide p (n) − 1-dig... | # p(n) = 2^^n より大きい最小の素数 (ただし^^はクヌースの二重矢印記号) と定義したとき、
# x = (10^(p(n)-1)-1)/9 (mod p(n)) を求めよ
# 「フェルマーの小定理」
# pが素数ならば、a^p == a (mod p(n))
# とくに、aとpが互いに素 (gcd(a,p)=1) のとき
# a^p * a^-1 == a * a^-1 (mod p(n))
# a^(p-1) == 1 (mod p)
#
# 9とp(n)が互いに素ならば
# x * 9^-1 = 10^(p(n)-1)-1 (mod p(n))
# 10とp(n)が互いに素ならば
# 10^(p(n)-1) = ... | {
"input": [
"0",
"1",
"2",
"3",
"001",
"000",
"6",
"4",
"10",
"5",
"7",
"17",
"11",
"12",
"18",
"9",
"35",
"15",
"8",
"29",
"14",
"41",
"27",
"62",
"30",
"25",
"42",
"58",
"21",
"83",
"98",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ikta loves fast programs. Recently, I'm trying to speed up the division program. However, it doesn't get much faster, so I thought it would be better to make it faster only for "commo... |
p01995 Palindromic Subsequences_28501 | G: Palindromic Subsequences
problem
Given a string S consisting only of lowercase letters, find out how many subsequences of this string S are not necessarily continuous and are palindromes.
Here, a subsequence that is not necessarily continuous with S is an arbitrary selection of one or more characters | S | charac... | def main():
from bisect import bisect_left as bl
from bisect import bisect_right as br
s=input()
alpha="abcdefghijklmnopqrstuvwxyz"
l=len(s)
alpha2={j:i for i,j in enumerate(alpha)}
memo=[[] for _ in [0]*26]
mod=10**9+7
for i in range(l):
memo[alpha2[s[i]]].append(i)
dp=[... | {
"input": [
"acpc",
"ccpa",
"cnbc",
"emec",
"ccoa",
"aocc",
"pcca",
"ccao",
"pcda",
"ccbo",
"qcda",
"ccbn",
"qbda",
"adbq",
"dnbc",
"dobc",
"dobd",
"cobd",
"dboc",
"cbod",
"cboe",
"eobc",
"cobe",
"boce",
"bode",
"... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
G: Palindromic Subsequences
problem
Given a string S consisting only of lowercase letters, find out how many subsequences of this string S are not necessarily continuous and are pal... |
p02141 Donut Hole_28504 | Problem
You brought a flat, holeless donut with a $ W $ horizontal $ H $ vertical $ H $ rectangle for ACPC.
Place this donut on the $ 2 $ dimension plane coordinate $ (0,0) $ with the center of the donut so that the side of length H and the $ y $ axis are parallel.
On the ACPC $ 1 $ day you ate a donut that was in t... | def inpl(): return list(map(int, input().split()))
W, H, w, h, x, y = inpl()
a = (min(W//2 , x + w//2) + max(-W//2, x-w//2))
b = (min(H//2 , y + h//2) + max(-H//2, y-h//2))
print(b/a)
| {
"input": [
"6000 5000 20 10 400 300",
"10 10 8 8 8 8",
"6000 5000 20 2 400 300",
"6000 5000 20 2 400 204",
"6000 5000 20 2 499 204",
"274 5000 28 1 499 204",
"274 4268 28 0 499 209",
"274 8140 32 0 499 209",
"274 14753 32 0 499 132",
"6000 5000 20 10 400 575",
"16 16 8 8 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Problem
You brought a flat, holeless donut with a $ W $ horizontal $ H $ vertical $ H $ rectangle for ACPC.
Place this donut on the $ 2 $ dimension plane coordinate $ (0,0) $ with th... |
p02282 Reconstruction of a Tree_28507 | Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree.
Constraints
* $1 \leq n \leq 40$
Input
In the first line, an integer $n$, which is... | class BinaryTree:
class Node:
def __init__(self, nid, left, right):
self.id = nid
self.left = left
self.right = right
def has_left(self):
return self.left is not None
def has_right(self):
return self.right is not None
def... | {
"input": [
"5\n1 2 3 4 5\n3 2 4 1 5",
"4\n1 2 3 4\n1 2 3 4",
"4\n1 2 3 4\n2 1 3 4",
"4\n2 1 3 4\n2 1 3 4",
"4\n2 1 3 4\n3 1 2 4",
"5\n1 2 3 4 5\n1 2 4 3 5",
"4\n2 1 3 4\n1 2 3 4",
"5\n1 3 2 4 5\n3 2 4 1 5",
"4\n1 4 3 2\n1 2 3 4",
"5\n1 2 3 4 5\n3 4 2 1 5",
"4\n1 2 3 4\n1 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtai... |
p02429 Enumeration of Subsets III_28510 | You are given a set $T$, which is a subset of $S$. The set $S$ consists of $0, 1, ... n-1$. Print all subsets of $T$. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elemen... | n=int(input())
ind='0'+str(n)+'b'
t=list(map(int,input().split()))
k=t[0]
t.pop(0)
T=t
T.reverse()
ind='0'+str(k)+'b'
for i in range(2**k):
compare=[int(j) for j in format(i,ind)]
disp=[T[j] for j in range(k) if compare[j]==1]
disp.reverse()
if len(disp)==0:
print("0:")
else:
calc=... | {
"input": [
"4\n2 0 2",
"4\n2 0 3",
"4\n2 1 2",
"4\n0 0 3",
"4\n2 0 1",
"4\n1 0 2",
"4\n1 1 0",
"4\n1 2 -2",
"4\n1 3 0",
"4\n2 1 3",
"4\n0 0 1",
"4\n0 1 3",
"4\n0 1 1",
"4\n0 1 5",
"4\n0 1 2",
"4\n0 2 1",
"4\n0 1 0",
"4\n0 2 0",
"4\n0 0 0",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a set $T$, which is a subset of $S$. The set $S$ consists of $0, 1, ... n-1$. Print all subsets of $T$. Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 0... |
1023_B. Pair of Toys_28520 | Tanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total cost is k burles. How many ways to do that does she have?
Each toy appears in the shop exactly once. Pairs (a, b) and (b, a) are conside... | n,k = [int(x) for x in input().split()]
if k>n:
if k>=2*n:
print(0)
else:
print((2*n-k+1)//2)
else:
if k%2==0:
k-=1
print(k//2) | {
"input": [
"8 15\n",
"1000000000000 1000000000001\n",
"7 20\n",
"8 5\n",
"99999999999999 100000000000000\n",
"100000000000000 100000000000000\n",
"4 7\n",
"50000000000000 99999999999999\n",
"3 1\n",
"1 100000000000000\n",
"4 4\n",
"49999999999996 99999999999999\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Tanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total ... |
1044_C. Optimal Polygon Perimeter_28524 | You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n, in clockwise order.
We define the distance between two points p_1 = (x_1... | n = int(input())
north = -100000000
south = 100000000
east = -100000000
west = 100000000
ne = -200000000
nw = -200000000
se = -200000000
sw = -200000000
for i in range(n):
x,y = map(int,input().split())
north = max(north,y)
east = max(east,x)
south = min(south,y)
west = min(west,x)
ne = max(ne,x... | {
"input": [
"4\n2 4\n4 3\n3 0\n1 3\n",
"3\n0 0\n0 2\n2 0\n",
"12\n-83240790 -33942371\n-83240805 -33942145\n-83240821 -33941752\n-83240424 -33941833\n-83240107 -33942105\n-83239958 -33942314\n-83239777 -33942699\n-83239762 -33942925\n-83239746 -33943318\n-83240143 -33943237\n-83240460 -33942965\n-8324060... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying i... |
1067_B. Multihedgehog_28528 | Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself k-multihedgehog.
Let us define k-multihedgehog as fol... | from sys import stdin
from collections import deque
n, k = map(int, stdin.readline().split())
graph = [[] for _ in range(n)]
leaf = -1
for _ in range(n-1):
a,b = map(int,stdin.readline().split())
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
def bfs(G, s):
# la cola comienza con el vertice ... | {
"input": [
"3 1\n1 3\n2 3\n",
"14 2\n1 4\n2 4\n3 4\n4 13\n10 5\n11 5\n12 5\n14 5\n5 13\n6 7\n8 6\n13 6\n9 6\n",
"13 2\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n",
"14 3\n1 4\n2 4\n3 4\n4 13\n10 5\n11 5\n12 5\n14 5\n5 13\n6 7\n8 6\n13 6\n9 6\n",
"18 2\n1 4\n2 4\n3 4\n4 13\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices ... |
1089_L. Lazyland_28532 | The kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland.
Today k important jobs for the kingdom (k ≤ n) should be performed. Every job should be done by one person and every person can do at most one job. The King allowed e... | n,k = map(int,input().split())
s = list(map(int,input().split()))
p = list(map(int,input().split()))
r = {}
r2 = []
for i in range(n):
if s[i] in r:
if r[s[i]]>p[i]:
r2.append(p[i])
else:
r2.append(r[s[i]])
r[s[i]] = p[i]
else:
r[s[i]] = p[i]
r1 = k-le... | {
"input": [
"3 3\n3 1 2\n5 3 4\n",
"8 7\n1 1 3 1 5 3 7 1\n5 7 4 8 1 3 5 2\n",
"2 2\n1 1\n1117 13\n",
"2 1\n1 1\n7 13\n",
"13 11\n6 1 9 9 10 7 3 11 1 4 11 4 11\n48 19 90 85 6 46 38 99 41 67 79 1 27\n",
"1 1\n1\n1000000000\n",
"13 3\n3 1 3 1 1 1 3 3 1 3 3 3 3\n38 75 29 50 99 5 44 33 45 71 3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland.
Today k important jobs for th... |
1108_E2. Array and Segments (Hard version)_28536 | The only difference between easy and hard versions is a number of elements in the array.
You are given an array a consisting of n integers. The value of the i-th element of the array is a_i.
You are also given a set of m segments. The j-th segment is [l_j; r_j], where 1 ≤ l_j ≤ r_j ≤ n.
You can choose some subset of... | def main():
n, m = map(int, input().split())
aa = list(map(int, input().split()))
res = max(aa) - min(aa)
ll, rr = [n + 1], [n + 1]
segments = res_segments = [False] * (m + 1)
bounds = {0, n, n + 1}
for _ in range(m):
l, r = map(int, input().split())
l -= 1
ll.append(... | {
"input": [
"5 4\n2 -2 3 1 4\n3 5\n3 4\n2 4\n2 5\n",
"1 0\n1000000\n",
"5 4\n2 -2 3 1 2\n1 3\n4 5\n2 5\n1 3\n",
"5 50\n-5 4 -4 -1 5\n4 5\n4 5\n1 1\n1 5\n1 1\n1 1\n3 5\n4 5\n5 5\n1 1\n3 3\n1 4\n1 3\n4 5\n4 5\n5 5\n1 3\n2 3\n3 4\n5 5\n1 2\n4 4\n2 2\n1 3\n5 5\n2 5\n2 2\n3 3\n1 1\n4 4\n2 3\n3 4\n5 5\n5 5... | 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 a number of elements in the array.
You are given an array a consisting of n integers. The value of the i-th element of the array... |
1138_B. Circus_28540 | Polycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes, then a_i = 1, otherwise a_i = 0).
Split the artists into two performance... | import sys
import random
N = int(input())
C = list(map(int, input()))
A = list(map(int, input()))
# N = random.randint(20, 40) * 2
# C = [random.randint(0, 1) for i in range(N)]
# A = [random.randint(0, 1) for i in range(N)]
def build_solution(i, j, x, y):
I = (0, 0)
J = (0, 1)
X = (1, 0)
Y = (1, 1)
ans = []
f... | {
"input": [
"4\n0011\n1100\n",
"4\n0011\n0101\n",
"8\n00100101\n01111100\n",
"6\n000000\n111111\n",
"10\n0011101001\n1000101110\n",
"4\n0011\n1100\n",
"6\n111100\n111000\n",
"8\n11111111\n11110000\n",
"2\n10\n10\n",
"8\n11100000\n00101111\n",
"2\n10\n01\n",
"8\n0111111... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwis... |
1156_D. 0-1-Tree_28544 | You are given a tree (an undirected connected acyclic graph) consisting of n vertices and n - 1 edges. A number is written on each edge, each number is either 0 (let's call such edges 0-edges) or 1 (those are 1-edges).
Let's call an ordered pair of vertices (x, y) (x ≠ y) valid if, while traversing the simple path fro... | import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n):
self.parent = [-1] * n
self.cnt = n
def root(self, x):
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(self.parent[x])
return self.parent[x]
... | {
"input": [
"7\n2 1 1\n3 2 0\n4 2 1\n5 2 0\n6 7 1\n7 2 1\n",
"2\n1 2 1\n",
"2\n1 2 0\n",
"7\n2 1 1\n3 2 0\n4 2 1\n5 4 0\n6 7 1\n7 2 1\n",
"7\n2 1 1\n3 2 1\n4 2 1\n5 2 0\n6 7 1\n7 2 1\n",
"7\n2 1 1\n3 2 0\n4 2 1\n5 2 0\n6 7 0\n7 2 1\n",
"7\n3 1 1\n3 2 0\n4 2 1\n5 2 0\n6 7 1\n7 2 1\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a tree (an undirected connected acyclic graph) consisting of n vertices and n - 1 edges. A number is written on each edge, each number is either 0 (let's call such edges... |
1196_F. K-th Path_28551 | You are given a connected undirected weighted graph consisting of n vertices and m edges.
You need to print the k-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from i to j and from j to i are counted as one).
More formally, if d is the matrix of shortest paths, where ... | import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
X = []
for _ in range(M):
x, y, w = map(int, input().split())
X.append([min(x,y), max(x,y), w])
X = (sorted(X, key = lambda x: x[2])+[[0, 0, 10**20] for _ in range(K)])[:K]
D = {}
for x, y, w in X:
if x: D[x*10**6+y] = w
flg = 1
whil... | {
"input": [
"7 15 18\n2 6 3\n5 7 4\n6 5 4\n3 6 9\n6 7 7\n1 6 4\n7 1 6\n7 2 1\n4 3 2\n3 2 8\n5 3 6\n2 5 5\n3 7 9\n4 1 8\n2 1 1\n",
"6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n",
"2 1 1\n1 2 123456789\n",
"28 27 378\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a connected undirected weighted graph consisting of n vertices and m edges.
You need to print the k-th smallest shortest path in this graph (paths from the vertex to it... |
1214_A. Optimal Currency Exchange_28555 | Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar i... | n=int(input())
d=int(input())
e=int(input())
arr=100
a,b=min(d,5*e),max(d,5*e)
for i in range(0,n//b+1):
arr=min(arr,(n-i*b)%a)
print(arr)
| {
"input": [
"410\n55\n70\n",
"600\n60\n70\n",
"100\n60\n70\n",
"8642\n70\n90\n",
"999\n66\n74\n",
"1000\n60\n80\n",
"90852542\n95\n34\n",
"100000000\n31\n33\n",
"99999998\n60\n75\n",
"99\n100\n100\n",
"10000\n68\n78\n",
"11750\n49\n50\n",
"13795\n97\n31\n",
"15... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like ... |
1237_C2. Balanced Removals (Harder)_28559 | This is a harder version of the problem. In this version, n ≤ 50 000.
There are n distinct points in three-dimensional space numbered from 1 to n. The i-th point has coordinates (x_i, y_i, z_i). The number of points n is even.
You'd like to remove all n points using a sequence of n/2 snaps. In one snap, you can remov... | def solve_z(points):
cur = None
d = {}
for p in points:
if p[0] not in d:
d[p[0]] = []
d[p[0]].append(p)
for k in d:
d[k] = sorted(d[k], key = lambda x: x[1])
for k in sorted(d.keys()):
n = len(d[k])
for i in range... | {
"input": [
"6\n3 1 0\n0 3 0\n2 2 0\n1 0 0\n1 3 0\n0 1 0\n",
"8\n0 1 1\n1 0 1\n1 1 0\n1 1 1\n2 2 2\n3 2 2\n2 3 2\n2 2 3\n",
"4\n-42939263 80157803 90523514\n-42939263 94977529 90523514\n-42939263 94977529 -3280468\n-42939263 80157803 -3280468\n",
"2\n34319950 -11299623 -19866275\n34319950 -11299623 9... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is a harder version of the problem. In this version, n ≤ 50 000.
There are n distinct points in three-dimensional space numbered from 1 to n. The i-th point has coordinates (x_i... |
1255_C. League of Leesins_28563 | Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end!
The tournament consisted of n (n ≥ 5) teams around the world. Before the tournament starts, Bob has made a prediction of the rankings of each team, from 1-st to n-th. After th... | def zip_sorted(a,b):
# sorted by a
a,b = zip(*sorted(zip(a,b)))
# sorted by b
sorted(zip(a, b), key=lambda x: x[1])
return a,b
def return_nxt(i,a,b):
visited.add(i)
c = (set(mem2[i])-set([a,b])).pop()
final.append(c)
if len(final)==n:
return -1,b,c
new_idx = ((set(mem1[b])-visited)&(set(mem1[c])... | {
"input": [
"5\n4 3 2\n2 3 5\n4 1 2\n",
"5\n4 5 3\n2 5 1\n1 3 5\n",
"9\n7 5 3\n8 9 4\n8 1 7\n8 9 1\n1 5 7\n2 3 5\n6 3 2\n",
"5\n2 3 4\n2 4 1\n5 3 2\n",
"8\n3 7 6\n6 2 3\n2 6 8\n2 4 8\n4 1 8\n1 5 4\n",
"6\n1 6 5\n4 5 1\n2 4 1\n4 2 3\n",
"9\n1 8 9\n9 6 4\n2 1 3\n1 2 8\n3 5 2\n6 7 4\n8 9 4\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end!
The tournament consisted of n (n ≥ 5) ... |
1279_B. Verse For Santa_28567 | New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus.
Vasya's verse contains n parts. It takes a_i seconds to recite the i-th part. Vasya can't change the order of parts in the verse: firstly he recites the part which takes a_1 seconds, secondly — the part which take... | import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
n, s = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
if a[ans] < a[i]:
ans = i
s -= a[i]
if (s < 0): break
if s >= 0:
ans = -1
print(ans ... | {
"input": [
"3\n7 11\n2 9 1 3 18 1 4\n4 35\n11 9 10 7\n1 8\n5\n",
"7\n10 11\n2 2 2 6 5 3 4 4 4 100000000\n4 102\n98 1 3 99\n4 103\n5 98 1 97\n11 1000000000\n100000000 100000002 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 99999999\n8 90\n20 8 20 20 20 20 1 1\n3 1000000000\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus.
Vasya's verse contains n parts. It takes a_i seconds to recite the i-th part... |
1322_C. Instant Noodles_28573 | Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You are given a bipartite graph with positive integers in all vertices of the right half. For a subset S of vertices of the left ha... | from sys import stdin
from math import gcd
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
T = int(input())
for _ in range(T):
n, m = map(int, input().split())
values = list(map(int, input().split()))
neigh_values = [0]*n
y_neigh = [[] for i in range(n)]
di = [[] for i in range(n)]
for... | {
"input": [
"3\n2 4\n1 1\n1 1\n1 2\n2 1\n2 2\n\n3 4\n1 1 1\n1 1\n1 2\n2 2\n2 3\n\n4 7\n36 31 96 29\n1 2\n1 3\n1 4\n2 2\n2 4\n3 1\n4 3\n",
"1\n100 31\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting t... |
1341_B. Nastya and Door_28577 | On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.
Mountains are described by a sequence of heights... | from sys import stdin, stdout
def find(A,N,K):
arr=[0]*N
for i in range(1,N-1):
if A[i-1]<A[i]>A[i+1]: arr[i]=1
i,j=0,2
c=0
# print(arr)
while(j<K):
if arr[j-1]: c+=1
# print(j,c)
j+=1
m=[c,i]
# print(c,i,j)
while(j<N):
if arr[i+1]: c-=1
... | {
"input": [
"5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 0 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n",
"5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 -1 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n",
"5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very co... |
1363_B. Subsequence Hate_28581 | Shubham has a binary string s. A binary string is a string containing only characters "0" and "1".
He can perform the following operation on the string any amount of times:
* Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa.
... | for t in range(int(input())):
s=input()
one=s.count("1")
z=s.count("0")
if one==0 or z==0:
print(0)
else:
cost=one
mi=10**9
for i in s:
if i=="0":
cost+=1
else:
cost-=1
if mi>cost:
mi=... | {
"input": [
"7\n001\n100\n101\n010\n0\n1\n001100\n",
"14\n110\n110011011110100111\n10111101000010100\n001111\n0\n00\n0111000\n1010111011110011011\n11100100011101101\n010100000111\n1111101\n000101100101111100\n01001101000\n0110\n",
"18\n010\n100100011010\n001\n010101\n101\n1100111101101110\n101100\n000110... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Shubham has a binary string s. A binary string is a string containing only characters "0" and "1".
He can perform the following operation on the string any amount of times:
* Sel... |
1404_D. Game of Pairs_28586 | This is an interactive problem.
Consider a fixed positive integer n. Two players, First and Second play a game as follows:
1. First considers the 2n numbers 1, 2, ..., 2n, and partitions them as he wants into n disjoint pairs.
2. Then, Second chooses exactly one element from each of the pairs that First created (... | import sys
n = int(input())
if n % 2:
print('Second')
sys.stdout.flush()
l = list(map(lambda x: int(x)-1,input().split()))
rev1 = [-1]*n
rev2 = [-1]*n
revs = [0]*n
for i in range(2 * n):
revs[l[i]] += i
if rev1[l[i]] == -1:
rev1[l[i]] = i
else:
... | {
"input": [
"2\n\n\n0",
"2\n\n1 1 2 2\n\n0\n",
"2\n1 2 1 2\n",
"4\n2 4 3 1 3 4 2 1\n",
"10\n1 10 6 4 3 5 10 9 3 8 1 2 6 4 7 5 2 9 7 8\n",
"1\n1 1\n",
"5\n2 4 2 1 5 3 3 1 5 4\n",
"10\n10 1 9 8 7 2 4 5 6 3 10 1 9 8 7 2 4 5 6 3\n",
"4\n1 4 4 2 3 1 2 3\n",
"5\n5 3 4 2 1 2 1 4 5 3\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This is an interactive problem.
Consider a fixed positive integer n. Two players, First and Second play a game as follows:
1. First considers the 2n numbers 1, 2, ..., 2n, and par... |
1426_A. Floor Number_28590 | Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n.
There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains 2 apartments, every other floor contains x apartments each. Apartments are numbered starting from one, from... | from functools import reduce
import os
import sys
from collections import *
#from fractions import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value(): return tuple(map(int, input().split())) # multiple values
def a... | {
"input": [
"4\n7 3\n1 5\n22 5\n987 13\n",
"7\n7 3\n1 5\n22 5\n987 13\n7 3\n1 5\n22 5\n",
"7\n7 3\n1 5\n12 5\n987 13\n7 3\n1 5\n22 5\n",
"4\n8 3\n1 5\n22 5\n987 13\n",
"7\n7 3\n1 5\n12 5\n987 3\n7 3\n1 5\n22 5\n",
"4\n8 3\n1 5\n22 5\n987 5\n",
"7\n7 3\n1 5\n12 5\n987 3\n7 5\n1 5\n22 5\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is n.
There is only one entrance in Petya's house and the distribution of apartments is the follow... |
1472_G. Moving to the Capital_28594 | There are n cities in Berland. The city numbered 1 is the capital. Some pairs of cities are connected by a one-way road of length 1.
Before the trip, Polycarp for each city found out the value of d_i — the shortest distance from the capital (the 1-st city) to the i-th city.
Polycarp begins his journey in the city wit... | import sys
from sys import stdin
from collections import deque
def NC_Dij(lis,start):
ret = [float("inf")] * len(lis)
ret[start] = 0
q = deque([start])
plis = [i for i in range(len(lis))]
while len(q) > 0:
now = q.popleft()
for nex in lis[now]:
if ret[nex] > ret... | {
"input": [
"3\n\n6 7\n1 2\n1 3\n2 5\n2 4\n5 1\n3 6\n6 2\n\n2 2\n1 2\n2 1\n\n6 8\n1 2\n1 5\n2 6\n6 1\n2 3\n3 4\n4 2\n5 4\n",
"3\n\n6 7\n1 2\n1 3\n2 5\n2 4\n5 1\n3 6\n6 2\n\n2 2\n1 2\n2 1\n\n6 8\n1 2\n1 5\n2 6\n6 1\n2 3\n2 4\n4 2\n5 4\n",
"3\n\n6 7\n1 2\n1 3\n2 5\n2 4\n3 1\n3 6\n6 2\n\n2 2\n1 2\n2 1\n\n6 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are n cities in Berland. The city numbered 1 is the capital. Some pairs of cities are connected by a one-way road of length 1.
Before the trip, Polycarp for each city found out... |
1499_B. Binary Removals_28598 | You are given a string s, consisting only of characters '0' or '1'. Let |s| be the length of s.
You are asked to choose some integer k (k > 0) and find a sequence a of length k such that:
* 1 ≤ a_1 < a_2 < ... < a_k ≤ |s|;
* a_{i-1} + 1 < a_i for all i from 2 to k.
The characters at positions a_1, a_2, ...,... | for q in range(int(input())):
n=input()
s=0
s1=0
p=0
l=len(n)
for i in range(l-1,0,-1):
if(n[i]=='0' and n[i-1]=='0' ):
s=1
p=i-1
break
for i in range(p,0,-1):
if(n[i]=='1' and n[i-1]=='1'):
s1=1
break
if(s1... | {
"input": [
"5\n10101011011\n0000\n11111\n110\n1100\n",
"9\n11\n11\n11\n11\n11\n11\n11\n11\n11\n",
"1\n0000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100\n",
"1\n00000111111111111111111111111111111111111111111111111111111111111111111011111111111111111... | 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 s, consisting only of characters '0' or '1'. Let |s| be the length of s.
You are asked to choose some integer k (k > 0) and find a sequence a of length k such ... |
1520_G. To Go Or Not To Go?_28602 | Dima overslept the alarm clock, which was supposed to raise him to school.
Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school.
The city where Dima lives is a rectangular field of n × m size. Each cell (i, j) on this ... | #!/usr/bin/env python3
import io
import os
from collections import deque
# input = sys.stdin.readline # to read input quickly
from math import inf
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
# available on Google, AtCoder Python3, not available on Codeforces
# import numpy as np
# import scipy
M9 = ... | {
"input": [
"5 5 1\n0 -1 0 1 -1\n0 20 0 0 -1\n-1 -1 -1 -1 -1\n3 0 0 0 0\n-1 0 0 0 0\n",
"2 3 1000000000\n0 0 0\n0 0 0\n",
"10 5 2\n0 3 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n-1 0 0 0 0\n0 0 0 6 0\n0 0 0 0 8\n0 0 5 6 0\n0 0 0 5 -1\n0 0 0 0 10\n0 0 0 0 0\n",
"10 2 2\n0 -1\n0 10\n8 4\n0 0\n0 0\n-1 0\n0 0\n0 0\n0 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Dima overslept the alarm clock, which was supposed to raise him to school.
Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum tim... |
176_C. Playing with Superglue_28607 | Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second player aims to stop the first one with a tube of superglue.
We'll describe ... | n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[1]<5 and a[0]+a[1]<7 else "Second")
# Made By Mostafa_Khaled | {
"input": [
"6 5 4 3 2 1\n",
"10 10 1 1 10 10\n",
"1 6 1 2 1 6\n",
"24 32 6 2 7 4\n",
"45 62 28 48 28 50\n",
"100 32 71 12 71 22\n",
"57 85 29 40 29 69\n",
"95 28 50 12 50 13\n",
"5 4 1 1 5 4\n",
"100 100 1 1 100 100\n",
"51 76 50 5 45 76\n",
"37 100 33 13 32 30\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player... |
220_A. Little Elephant and Problem_28613 | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ... |
def main():
n = int(input())
arr = list(map(int, input().split()))
copy = arr[:]
copy.sort()
missed = 0
for i in range(n):
if arr[i] != copy[i]:
missed += 1
if missed == 2:
print('YES')
elif missed == 0:
print('YES')
else:
print('NO')
... | {
"input": [
"4\n4 3 2 1\n",
"2\n1 2\n",
"3\n3 2 1\n",
"5\n1 4 3 2 1\n",
"6\n3 4 5 6 7 2\n",
"3\n1 3 2\n",
"50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 9 5\n",
"3\n2 3 1\n",
"5\n1 1 3 2 2\n",
"5\n1 4 5 2 3\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elepha... |
244_B. Undoubtedly Lucky Numbers_28617 | Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are lucky.
Let's call a positive integer a undoubtedly lucky, if there are suc... | def func(num):
if 0 < num <= n:
result.add(num)
num *= 10
func(num+x)
func(num+y)
if __name__ == "__main__":
n = int(input())
result = set()
for x in range(10):
for y in range(10):
func(x)
print(len(result))
| {
"input": [
"123\n",
"10\n",
"784262\n",
"68\n",
"101\n",
"132\n",
"999999998\n",
"468390\n",
"603356456\n",
"820040584\n",
"2\n",
"909090901\n",
"642678\n",
"999999999\n",
"940\n",
"326806\n",
"4\n",
"6\n",
"1000\n",
"356\n",
"99999... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. ... |
292_B. Network Topology_28623 | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them a... | n,m=map(int,input().split())
arr=[0]*(n+1)
for w in range(m):
a,b=map(int,input().split())
arr[a]+=1
arr[b]+=1
c1=0
c2=0
cs=0
for i in range(1,n+1):
if arr[i]==1:
c1+=1
if arr[i]==2:
c2+=1
if arr[i]==n-1:
cs+=1
if c1==2 and c2==n-2:
print("bus topology")
elif c2==n:
... | {
"input": [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 4\n4 2\n",
"10 9\n10 6\n3 4\n8 9\n8 4\n6 1\n2 9\n5 1\n7 5\n10 3\n",
"10 14\n3 2\n7 2\n6 4\n8 1\n3 9\n5 6\n6 3\n4 1\n2 5\n7 10\n9 5\n7 1\n8 10\n3 4\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues w... |
363_B. Fence_28631 | There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights.
<image> Fence for n = 7 and h = [1, 2, 6, 1, 1, 7, 1]
Polycarpus has bought a posh piano... | n,k=map(int,input().split())
A = list(map(int,input().split()))
B = [0]
for i in range(k):
B[0]+=A[i]
for i in range(1,n-k+1):
B.append(B[i-1]-A[i-1]+A[i+k-1])
print(B.index(min(B))+1) | {
"input": [
"7 3\n1 2 6 1 1 7 1\n",
"2 1\n10 20\n",
"3 1\n1 2 3\n",
"10 2\n3 1 4 1 4 6 2 1 4 6\n",
"2 2\n20 10\n",
"4 1\n1 5 2 2\n",
"6 3\n1 2 1 3 1 1\n",
"8 3\n1 1 1 1 2 60 90 1\n",
"6 3\n56 56 56 2 1 2\n",
"3 3\n1 2 3\n",
"5 2\n100 100 100 1 1\n",
"10 4\n1 1 1 4 4 4 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi mete... |
387_A. George and Sleep_28635 | George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second... | def tmins():
sh, sm = map(int, input().split(':'))
return 60 * sh + sm
t = tmins() - tmins()
if t < 0:
t += 60*24
print('%02d:%02d' % (t//60, t%60))
| {
"input": [
"00:01\n00:00\n",
"05:50\n05:44\n",
"00:00\n01:00\n",
"12:33\n23:33\n",
"10:05\n00:00\n",
"09:09\n00:00\n",
"13:04\n09:58\n",
"01:00\n00:00\n",
"03:48\n00:41\n",
"12:21\n21:12\n",
"12:44\n12:44\n",
"00:00\n00:01\n",
"12:59\n00:45\n",
"05:55\n07:12\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t.
Help George! Write a program that will, given time s and t, deter... |
457_B. Distributed Join_28642 | Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different number of partitions. Table A is distributed on the first cluster consisting... | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
sumA = sum(A)
sumB = sum(B)
ansA = sumB
ansB = sumA
for i in range(1, n):
ansA += min(A[i],sumB)
for i in range(1, m):
ansB += min(B[i], sumA)
print(min(ansA,... | {
"input": [
"2 2\n2 6\n3 100\n",
"2 3\n10 10\n1 1 1\n",
"10 10\n269584761 865524829 265226347 963092340 261501474 16861445 221090297 746538035 842020225 649641719\n49728483 423679832 107851851 179960003 345895125 400584885 460489835 377856735 506736683 676996548\n",
"3 4\n337369924 278848730 65493367... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic.
Suppose she wants to join two tables, A and B. Each of them h... |
479_E. Riding in a Lift_28646 | Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. Howe... | def solve(n, st, k):
MOD = int(1e9 + 7)
prev = [0] * (n + 1)
current = [0] * (n + 1)
prefix_sum = [0] * (n + 1)
prev[st] = 1
for times in range(k):
prefix_sum[0] = 0
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + prev[i]
if prefix_sum[i] >= ... | {
"input": [
"5 3 4 1\n",
"5 2 4 1\n",
"5 2 4 2\n",
"500 1 500 500\n",
"300 300 1 300\n",
"5000 1 5000 5000\n",
"232 195 193 322\n",
"5000 5000 1 5000\n",
"2 2 1 1\n",
"500 499 500 500\n",
"1000 500 1 2000\n",
"3 2 3 1\n",
"300 1 300 300\n",
"500 498 500 499\n",... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you'... |
527_C. Glass Carving_28652 | Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice t... | w,h,n=map(int,input().split())
l=[-1]*(w+1)
r=[-1]*(w+1)
t=[-1]*(h+1)
b=[-1]*(h+1)
l[0]=0
b[0]=0
t[h]=h
r[w]=w
V=[0]*(n)
H=[0]*(n)
for i in range(n):
line,index=input().split()
index=int(index)
if line=="V":
r[index]=w
V[i]=index
else:
t[index]=h
H[i]=index
le... | {
"input": [
"4 3 4\nH 2\nV 2\nV 3\nV 1\n",
"7 6 5\nH 4\nV 3\nV 5\nH 2\nV 1\n",
"5 15 10\nH 8\nH 9\nV 1\nH 2\nH 6\nH 4\nH 1\nV 2\nH 13\nV 3\n",
"200000 200000 1\nH 1\n",
"2 2 2\nH 1\nV 1\n",
"2 2 1\nH 1\n",
"2 2 2\nV 1\nH 1\n",
"2 2 1\nV 1\n",
"2 4 1\nH 2\n",
"15 5 10\nV 13\nV ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutt... |
553_A. Kyoya and Colored Balls_28656 | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | #!/usr/bin/python3
import sys
from functools import lru_cache
MOD = 1000000007
cnk = [[1 for i in range(1001)] for j in range(1001)]
for i in range(1, 1001):
for j in range(1, i):
cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j]
k = int(input())
cs = [int(input()) for i in range(k)]
ans = 1
sm = 0
for c ... | {
"input": [
"4\n1\n2\n3\n4\n",
"3\n2\n2\n1\n",
"1\n5\n",
"10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n",
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n",
"5\n10\n10\n10\n10\n10\n",
"1\n1\n",
"11\n291\n381\n126\n39\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls... |
579_F. LCS Again_28659 | You are given a string S of length n with each character being one of the first m lowercase English letters.
Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of LCS (longest common subsequence) between S and T is n - 1.
Recall that LCS ... | def main():
n, m = map(int, input().split())
s = input()
k = sum(s[i] != s[i - 1] for i in range(1, n)) + 1
x = i = 0
while i < n - 1:
if s[i] != s[i + 1]:
j = i
while i + 2 < n and s[i] == s[i + 2]:
i += 1
j = (i - j) + 2
x += ... | {
"input": [
"3 3\naaa\n",
"10 9\nabacadefgh\n",
"1 2\na\n",
"3 3\naab\n",
"1 26\nz\n",
"100 26\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\n",
"15 3\nabababababababa\n",
"100 27\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvf... | 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 S of length n with each character being one of the first m lowercase English letters.
Calculate how many different strings T of length n composed from the fir... |
600_E. Lomsat gelral_28661 | You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour.
Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's possible that two or more colours will be dominating in the subtree... | import sys
input = sys.stdin.buffer.readline
class SegmentTree:
def __init__(self, n, op, e):
self.n = n
self.op = op
self.e = e
self.size = 2 ** ((n - 1).bit_length())
self.node = [self.e] * (2 * self.size)
def __getitem__(self, i):
return self.node[i + self.s... | {
"input": [
"4\n1 2 3 4\n1 2\n2 3\n2 4\n",
"15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n",
"4\n1 2 3 4\n1 2\n2 3\n1 4\n",
"4\n2 2 3 4\n1 2\n2 3\n2 4\n",
"15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour.
Let's call colour c dominating in the subtree of vertex v if there are no other colours tha... |
645_A. Amity Assessment_28667 | Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the em... | def read_ints():
return [int(x) for x in input(' ').split()]
def evaluate(top, bot):
res = 1 if 'X' in top else 2
perm = top + bot
perm = [x for x in perm if x != 'X']
for i in range(len(perm)):
for j in range(i+1, len(perm)):
if perm[i] > perm[j]:
res += 1
... | {
"input": [
"AB\nXC\nAC\nBX\n",
"AB\nXC\nXB\nAC\n",
"CX\nBA\nAX\nBC\n",
"XB\nAC\nBX\nAC\n",
"BA\nXC\nXB\nAC\n",
"CA\nBX\nCB\nXA\n",
"AC\nBX\nCB\nAX\n",
"BC\nXA\nXC\nAB\n",
"XA\nCB\nBA\nCX\n",
"CA\nXB\nXB\nCA\n",
"AC\nXB\nBA\nCX\n",
"AX\nCB\nBC\nAX\n",
"BA\nXC\nBC\n... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit... |
697_A. Pineapple Incident_28673 | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc.
<image>
Barney woke up in the morning and wants to eat the ... | t,s,x=(int(z) for z in input().split())
x-=t
if x>=0 and x%s in [0,1] and x!=1:
print("YES")
else:
print("NO") | {
"input": [
"3 10 4\n",
"3 8 52\n",
"3 10 3\n",
"3 8 51\n",
"4 2 6\n",
"3 743604 201724\n",
"6947541 698167 6\n",
"688051712 67 51\n",
"29318 787017 587931018\n",
"0 2 1000000000\n",
"0 2 3\n",
"0 2 0\n",
"6 5 3\n",
"556888 514614196 515171084\n",
"6 328006... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second int... |
762_C. Two strings_28681 | You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of th... | from sys import stdin
def main():
t = stdin.readline()
s = stdin.readline()
n = len(s) - 1
m = len(t) - 1
post = [-1] * n
ss = n - 1
st = m - 1
while st >= 0 and ss >= 0:
if t[st] == s[ss]:
post[ss] = st
ss -= 1
st -= 1
pre = [-1] * n
ss ... | {
"input": [
"hi\nbob\n",
"abca\naccepted\n",
"abacaba\nabcdcba\n",
"edbcd\nd\n",
"aa\nzzaa\n",
"aaaaaaaaaaaa\naaa\n",
"aaaaaabbbbbbaaaaaa\naba\n",
"a\naaa\n",
"ab\naba\n",
"aaaaaaaaa\na\n",
"njtdhyqundyedsjyvy\nypjrs\n",
"bacb\nccacacbacbccbbccccaccccccbcbabbbaababa\n"... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a ... |
785_D. Anton and School - 2_28685 | As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)).
On the last lesson Anton learned about the regular simple bracket s... | mod = 10 ** 9 + 7
fact, inv, invfact = [1, 1], [0, 1], [1, 1]
for i in range(2, 200200):
fact.append(fact[-1] * i % mod)
inv.append(inv[mod % i] * (mod - mod // i) % mod)
invfact.append(invfact[-1] * inv[-1] % mod)
def C(n, k):
if k < 0 or k > n:
return 0
return fact[n] * invfact[k] * invf... | {
"input": [
")(()()\n",
"()()()\n",
")))\n",
"())(()(())(()()))()()(()((()(())()))(()()(()()(())()()())))()()(()(((((()())(((())(((())((()(()()())()(()())()((((())()()(((()(((()(())()()((()(()(((()(((()()())(()((())()))())((()()())(()())(((((((()((((()())(()(\n",
"((\n",
"()))))))))))))))))))... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that ... |
807_D. Dynamic Problem Scoring_28689 | Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends... | import sys
inf = 10**9 + 7
def solve():
n = int(sys.stdin.readline())
v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya
p = [int(pi) for pi in sys.stdin.readline().split()] # Petya
cnt = [0]*5
for i in range(5):
if v[i] != -1:
cnt[i] += 1
if p[i] != -1:
... | {
"input": [
"2\n5 15 40 70 115\n50 45 40 30 15\n",
"5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62\n",
"4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1\n",
"3\n55 80 10 -1 -1\n15 -1 79 60 -1\n42 -1 13 -1 -1\n",
"2\n33 15 51 7 101\n41 80 40... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.
For this round the dynamic problem scoring is used. If you were lucky not t... |
831_E. Cards Sorting_28693 | Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on... | # -*- coding: utf-8 -*-
import sys
# fout = open("output.txt", "w")
fin = sys.stdin
# fin = open("input.txt", "r")
fout = sys.stdout
n = int(fin.readline())
a = list(map(int, fin.readline().split()))
def solution(n, a):
sorted_arr = [(i, elem) for i, elem in enumerate(a)]
sorted_arr.sort(key=lambda x: (x[1... | {
"input": [
"4\n6 3 1 2\n",
"1\n1000\n",
"7\n3 3 3 3 3 3 3\n",
"87\n12 2 2 10 12 1 5 9 15 2 4 7 7 14 8 10 1 6 7 6 13 15 10 6 2 11 13 1 15 14 8 8 4 7 11 12 3 15 9 2 13 1 7 11 2 1 13 11 8 14 2 2 12 7 13 4 13 3 13 3 11 1 7 13 15 8 12 4 12 4 1 4 9 3 13 12 10 15 14 10 7 7 7 2 7 6 10\n",
"20\n1 1 1 1 1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the s... |
877_A. Alex and broken contest_28699 | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | judul = input()
nama = ["Danil", "Olya", "Slava", "Ann", "Nikita"]
cek = 0
ada = []
for i in range(0, 5):
ada.append(judul.count(nama[i]))
cek = cek + ada[i]
if cek == 1:
print("YES")
else:
print("NO") | {
"input": [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n",
"Hardest_problem_ever\n",
"Wake_up_Neo\n",
"AnAnn\n",
"DanilOlyaOlya\n",
"And_Danil\n",
"Olya_and_energy_drinks\n",
"ann\n",
"Nikita_Nikita\n",
"Vanya\n",
"AnnAnn\n",
"Danil_Danil... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But ... |
900_B. Position in Fraction_28703 | You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).
Output
Print position of the first occurrence of digit c into the fraction. Positions... | a,b,c = map(int, input().split())
t = a
q, r = divmod(t, b)
for i in range(1, 10**5+1):
q, r = divmod(r*10, b)
#print(q)
if q == c:
print(i)
exit()
else:
print(-1)
| {
"input": [
"2 3 7\n",
"1 2 0\n",
"1 10 1\n",
"53 101 6\n",
"567 1580 0\n",
"69168 84860 4\n",
"35 111 4\n",
"99971 99989 0\n",
"25102 31579 2\n",
"13805 15538 3\n",
"38790 39359 0\n",
"2 3 0\n",
"7 31 3\n",
"1 9 0\n",
"45 97 0\n",
"1636 3269 6\n",
... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
Input
The first contains three single positi... |
950_B. Intercepted Message_28710 | Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.
Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred... | n,m=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
i=0
j=0
s1=0
s2=0
count=1
while i<n and j<m:
if s1==s2 and s1>0:
count+=1
s1=0
s2=0
elif s1>s2 or s2==0:
s2+=y[j]
j+=1
elif s1<s2 or s1==0:
s1+=x[i]
i+=1
pri... | {
"input": [
"1 4\n4\n1 1 1 1\n",
"7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8\n",
"3 3\n1 10 100\n1 100 10\n",
"1 1\n1000000\n1000000\n",
"2 2\n1 1\n1 1\n",
"2 2\n2 3\n3 2\n",
"2 3\n2 2\n1 1 2\n",
"2 3\n3 2\n2 1 2\n",
"2 2\n2 3\n4 1\n",
"1 1\n1\n1\n",
"30 50\n3 3 1 3 1 2 4 3 4 1 3 2 ... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.
Z... |
978_E. Bus Video System_28714 | The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If x is the number of passengers in a bus just before the current bus stop and y is the number of passengers in the bus just after current bus stop, the sy... | l=input().split()
n=int(l[0])
w=int(l[1])
l=input().split()
li=[int(i) for i in l]
left=0
right=w
sumi=0
for i in range(n):
sumi+=li[i]
left=max(left,-1*sumi)
right=min(right,w-sumi)
print(max(right-left+1,0))
| {
"input": [
"4 10\n2 4 1 2\n",
"3 5\n2 1 -3\n",
"2 4\n-1 1\n",
"5 21\n-3 2 -4 -1 -5\n",
"2 1000000000\n-1000000 1000000\n",
"2 1000000000\n-1000000 -1000000\n",
"1 1000000000\n0\n",
"5 9\n-2 -1 2 -1 -2\n",
"10 1\n-1 -1 3 -4 2 3 0 -3 3 2\n",
"3 4\n1 2 3\n",
"2 1000000000\n1... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If x is the number... |
998_D. Roman Digits_28718 | Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as... | a = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]
n = int(input())
if n < len(a):
print (a[n])
else:
print (a[11] + 49*(n-11))
| {
"input": [
"1\n",
"2\n",
"10\n",
"111199\n",
"1000\n",
"10000\n",
"11\n",
"244\n",
"1000000000\n",
"14\n",
"55\n",
"2000\n",
"116\n",
"20\n",
"6\n",
"600000000\n",
"198\n",
"12\n",
"999999999\n",
"100\n",
"83\n",
"13\n",
"8\... | 2CODEFORCES | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digi... |
p02661 AtCoder Beginner Contest 169 - Count Median_28732 | There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i. Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq A_i \leq B_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard ... | N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
A[i],B[i] = map(int, input().split())
A.sort()
B.sort()
if len(A)%2 != 0:
ans = B[N//2]-A[N//2]+1
else:
ans = (B[N//2]+B[N//2-1]) - (A[N//2]+A[N//2-1]) + 1
print(ans) | {
"input": [
"3\n100 100\n10 10000\n1 1000000000",
"2\n1 2\n2 3",
"3\n100 100\n8 10000\n1 1000000000",
"2\n1 2\n2 4",
"3\n100 100\n8 11000\n1 1000000000",
"2\n1 1\n2 4",
"2\n1 1\n1 7",
"2\n0 1\n1 7",
"2\n0 1\n0 7",
"3\n000 010\n8 11000\n1 1001000000",
"2\n0 1\n0 8",
"3\... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i. Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.
Constraints... |
p02790 AtCoder Beginner Contest 152 - Comparing Strings_28736 | Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller?
Constraints
* 1 \leq a \leq 9
* 1 \leq b \leq 9
* a and b are integers.
Input
Input is given from Stan... | N = list(map(int, input().split()))
a = N.sort()
print(str(N[0])*N[1]) | {
"input": [
"7 7",
"4 3",
"7 2",
"4 6",
"7 4",
"7 8",
"5 7",
"1 3",
"5 2",
"6 6",
"6 7",
"4 5",
"4 4",
"2 8",
"3 7",
"1 5",
"9 2",
"2 4",
"1 4",
"1 7",
"1 6",
"6 5",
"6 9",
"9 3",
"9 7",
"2 1",
"1 8",
"8 4... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these... |
p02926 AtCoder Beginner Contest 139 - Engines_28740 | E869120 is initially standing at the origin (0, 0) in a two-dimensional plane.
He has N engines, which can be used as follows:
* When E869120 uses the i-th engine, his X- and Y-coordinate change by x_i and y_i, respectively. In other words, if E869120 uses the i-th engine from coordinates (X, Y), he will move to the ... | n = int(input())
pi = 3.141592653589793238462643383279
xy = [list(map(int, input().split())) for _ in range(n)]
import math
atan = [math.atan2(x[0], x[1]) for x in xy]
d = []
def hoge(a):
ret = 0
if a % (2*pi) < pi:
ret = (a % pi)
elif a % (2*pi) > pi:
ret = (a % pi)-pi
else:
... | {
"input": [
"1\n90447 91000",
"2\n96000 -72000\n-72000 54000",
"3\n0 10\n5 -5\n-5 -5",
"10\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n15 16\n17 18\n19 20",
"5\n1 1\n1 0\n0 1\n-1 0\n0 -1",
"3\n0 0\n0 1\n1 0",
"5\n1 1\n2 2\n3 3\n4 4\n5 5",
"1\n52551 91000",
"2\n96000 -130259\n-72000 5... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
E869120 is initially standing at the origin (0, 0) in a two-dimensional plane.
He has N engines, which can be used as follows:
* When E869120 uses the i-th engine, his X- and Y-coor... |
p03061 AtCoder Beginner Contest 125 - GCD on Blackboard_28744 | There are N integers, A_1, A_2, ..., A_N, written on the blackboard.
You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.
Find the maximum possible greatest common divisor of the N integers on the blackboard afte... | from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n+1)
r=[0]*(n+1)
for i in range(n):
l[i+1]=gcd(l[i],a[i])
for i in range(n-1,-1,-1):
r[i]=gcd(r[i+1],a[i])
ans=l[-1]
for i in range(n):
ans=max(ans,gcd(l[i],r[i+1]))
print(ans)
| {
"input": [
"3\n7 6 8",
"2\n1000000000 1000000000",
"3\n12 15 18",
"3\n7 6 7",
"2\n1000010000 1000000000",
"3\n12 29 18",
"2\n1000000000 1000001000",
"3\n4 8 7",
"2\n1001000000 1000001000",
"3\n9 28 18",
"3\n9 28 30",
"2\n1001100000 1000001100",
"2\n1101000000 1000... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There are N integers, A_1, A_2, ..., A_N, written on the blackboard.
You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibl... |
p03352 AtCoder Beginner Contest 097 - Exponential_28750 | You are given a positive integer X. Find the largest perfect power that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
Constraints
* 1 ≤ X ≤ 1000
* X is an integer.
Input
Input is given from Standard Input ... | x=int(input())
l=[]
for b in range (1,32):
for i in range (2,10):
if b**i <=x:
l.append (b**i)
print(max(l)) | {
"input": [
"10",
"1",
"999",
"20",
"610",
"38",
"159",
"107",
"72",
"136",
"217",
"261",
"011",
"001",
"7",
"689",
"747",
"52",
"83",
"8",
"124",
"34",
"235",
"27",
"197",
"25",
"1074",
"324",
"186",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given a positive integer X. Find the largest perfect power that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not les... |
p03512 Code Festival Team Relay (Parallel) - Akashic Records_28753 | Consider an infinite sequence a_1, a_2, … Initially, the values of all the terms are 0, and from this state we will sequentially perform Q operations. The i-th operation (1 ≤ i ≤ Q) is as follows:
* For every positive integer j, add x_i to the value of a_{j × m_i}.
Find the value of the largest term after these Q o... | from itertools import product
Q = int(input())
mxs = [tuple(map(int, input().split())) for _ in range(Q)]
p1s = [2,3,5,7,11,13,17]
nums = [9,6,4,3,3,3,3]
rangeNums = [range(num) for num in nums]
p2s = [19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,17... | {
"input": [
"3\n10 -3\n50 4\n100 -5",
"3\n2 10\n3 -20\n6 15",
"5\n56 114834\n72 -149861\n100 190757\n192 -132693\n240 133108",
"3\n10 -3\n50 4\n101 -5",
"3\n2 18\n3 -20\n6 15",
"5\n56 114834\n72 -134386\n100 190757\n192 -132693\n240 133108",
"3\n10 -3\n91 4\n101 -5",
"3\n18 -3\n91 4\n... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Consider an infinite sequence a_1, a_2, … Initially, the values of all the terms are 0, and from this state we will sequentially perform Q operations. The i-th operation (1 ≤ i ≤ Q) i... |
p03674 AtCoder Beginner Contest 066 - 11_28757 | You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given s... | # ------ combination -------
N, MOD = 10**5 + 1, 10**9 + 7
fc, ifc = [0] * (N+1), [0] * (N+1)
def power(n, a):
res, exp = 1, n
while(a):
if a & 1:
res = res * exp % MOD
exp = exp * exp % MOD
a = a >> 1
return res
fc[0] = 1
for i in range(1, N+1):
fc[i] = fc[i-1] * i... | {
"input": [
"1\n1 1",
"32\n29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9",
"3\n1 2 1 3",
"3\n1 3 1 3",
"3\n1 0 0 2",
"3\n1 3 2 1",
"3\n1 3 1 2",
"3\n1 0 1 2",
"3\n1 0 1 0",
"3\n1 0 2 0",
"3\n2 0 2 0",
"3\n1 3 2 3",
"3\n2 ... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once i... |
p03828 AtCoder Beginner Contest 052 - Factors of Factorial_28761 | You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
Constraints
* 1≤N≤10^3
Input
The input is given from Standard Input in the following format:
N
Output
Print the number of the positive divisors of N!, modulo 10^9+7.
Examples
Input
3
Output
4
Input
6
Output
3... | n = int(input())
multiplier = [0 for _ in range(n)]
for m in range(2, n+1):
a = m
i = 2
while i ** 2 <= m:
while a % i == 0:
a = int(a / i)
multiplier[i-1] += 1
i += 1
if a != 1:
multiplier[a-1] += 1
ans = 1
for x in multiplier:
ans *= x + 1
print(ans... | {
"input": [
"6",
"3",
"1000",
"8",
"0",
"15",
"18",
"2",
"4",
"9",
"5",
"10",
"7",
"11",
"13",
"17",
"23",
"21",
"42",
"35",
"38",
"54",
"34",
"65",
"30",
"12",
"22",
"20",
"26",
"37",
"19",
... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
Constraints
* 1≤N≤10^3
Input
The input is given from Standard Input in the following for... |
p03995 CODE FESTIVAL 2016 qual A - Grid and Integers_28765 | There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that he fell asleep.
Mr. Aoki found the grid and tries to surprise Mr.... | import sys
readline = sys.stdin.readline
class UFP():
def __init__(self, num):
self.par = [-1]*num
self.dist = [0]*num
def find(self, x):
if self.par[x] < 0:
return x
else:
res = 0
xo = x
while self.par[x] >= 0:
res ... | {
"input": [
"2 2\n4\n1 1 0\n1 2 10\n2 1 30\n2 2 20",
"2 2\n3\n1 1 0\n1 2 10\n2 1 20",
"3 3\n4\n1 1 0\n1 3 10\n3 1 10\n3 3 20",
"2 2\n3\n1 1 20\n1 2 10\n2 1 0",
"2 3\n5\n1 1 0\n1 2 10\n1 3 20\n2 1 30\n2 3 40",
"2 4\n4\n1 1 0\n1 2 10\n2 1 30\n2 2 20",
"2 2\n3\n1 1 0\n1 2 10\n2 1 22",
"3... | 5ATCODER | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a ... |
p00083 Era Name Transformation_28769 | Create a program that converts the date expressed in the Christian era to the Japanese calendar using the era name and outputs the date. The input is three integers, as shown in the example, in the order year, month, and day. Convert this as shown in the sample output. If the date before the Meiji era is entered, pleas... | from bisect import bisect_left
import sys
name = ["pre-meiji", "meiji", "taisho", "showa", "heisei"]
period = [(1868,9,7), (1912,7,29), (1926,12,24), (1989,1,7)]
for t in (tuple(map(int, l.split())) for l in sys.stdin):
index = bisect_left(period, t)
if index:
date = "{} {} {}".format(t[0]-period[inde... | {
"input": [
"2005 9 3\n1868 12 2\n1868 9 7",
"2005 5 3\n1868 12 2\n1868 9 7",
"2005 5 3\n1868 12 2\n1868 9 9",
"2005 7 3\n1868 12 2\n1868 9 9",
"2005 9 3\n1868 12 3\n1868 9 7",
"2005 5 3\n1703 12 2\n1868 9 7",
"2005 5 3\n411 12 2\n1868 9 9",
"2005 5 6\n1703 12 2\n1868 9 7",
"2005 ... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
Create a program that converts the date expressed in the Christian era to the Japanese calendar using the era name and outputs the date. The input is three integers, as shown in the e... |
p00215 Pachimon Creature_28772 | A popular game in a certain country, Pachimon Creature, has been remade and released in Japan. If you love games, after playing this game many times, you've come to think about how you can clear it the fastest. However, no matter how much you think about it, you didn't know the fastest way to capture it, so you decided... | from heapq import heappop,heappush
# from line_profiler import LineProfiler
def main():
while(True):
W, H = map(int,input().split())
if not W: break
B = float('inf')
Bi = -1
consequNodes = []
monsterNodes = [[] for _ in range(5)]
idx = 0
for i in range... | {
"input": [
"6 6\nS.1..4\n3..5..\n..4.1.\n4....5\n.2.32.\n5.1..G\n3 2\n...\nS.G\n0 0",
"6 6\nS.1..4\n5..3..\n..4.1.\n4....5\n.2.32.\n5.1..G\n3 2\n...\nS.G\n0 0",
"6 6\nS.1..4\n3..5..\n..4.1.\n4...5.\n.2.32.\n5.1..G\n3 2\n...\nS.G\n0 0",
"6 6\nS.1..4\n4..5..\n..4.1.\n4....5\n.2.32.\n5.1..G\n3 2\n...\n... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
A popular game in a certain country, Pachimon Creature, has been remade and released in Japan. If you love games, after playing this game many times, you've come to think about how yo... |
p00375 Celsius and Fahrenheit_28776 | In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is commonly encountered while you are in America.
A value in Fahrenhei... | x=input()
x=int(x)
y=(x-30)//2
print(y)
| {
"input": [
"68",
"50",
"82",
"60",
"116",
"85",
"162",
"51",
"149",
"96",
"238",
"65",
"311",
"558",
"633",
"1080",
"1303",
"2092",
"3794",
"6199",
"10347",
"9393",
"10699",
"19116",
"1106",
"355",
"642",
... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees F... |
p00593 JPEG Compression_28780 | The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we don’t discuss about details of the algorithm, but you are asked to make simple pro- gram. You are given single integer N , and you must output zigzag path on a matrix where si... | t = 1
while 1:
N = int(input())
if N == 0:
break
print("Case %d:" % t); t += 1
M = [[0]*N for i in range(N)]
c = 1
for i in range(2*N-1):
for j in range(max(i-N+1, 0), min(N, i+1)):
if i % 2 == 0:
M[i-j][j] = "%3d" % c
else:
... | {
"input": [
"3\n4\n0",
"3\n7\n0",
"3\n3\n0",
"3\n0\n0",
"3\n1\n0",
"3\n2\n0",
"3\n-1\n0",
"3\n5\n0",
"3\n8\n0",
"3\n6\n0",
"3\n9\n0",
"3\n0\n-1",
"3\n0\n1",
"3\n0\n-2",
"3\n0\n2",
"3\n0\n-4",
"3\n0\n-5",
"3\n0\n3",
"3\n0\n-3",
"3\n0\n4",... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
The fundamental idea in the JPEG compression algorithm is to sort coeffi- cient of given image by zigzag path and encode it. In this problem, we don’t discuss about details of the alg... |
p00729 Analyzing Login/Logout Records_28784 | You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or more PCs at a time, no one can log in to a PC which has been logged in by someone who has not logged out of that PC yet.
You are asked to w... | def main(N, M):
member = [[0] * 721 for i in range(M)]
r = int(input())
for _ in range(r):
t, _, m, s = map(int, input().split())
t -= 540
if s == 0:
member[m - 1][t] -= 1
else:
member[m - 1][t] += 1
for i in range(M):
for t in range(1,721)... | {
"input": [
"4 2\n10\n775 1 1 1\n780 4 2 1\n790 2 1 1\n800 2 1 0\n810 3 1 1\n820 1 1 0\n825 3 1 0\n860 1 1 1\n870 4 2 0\n880 1 1 0\n1\n780 870 1\n13 15\n12\n540 12 13 1\n600 12 13 0\n650 13 15 1\n660 12 15 1\n665 11 13 1\n670 13 15 0\n675 11 13 0\n680 12 15 0\n1000 11 14 1\n1060 12 14 1\n1060 11 14 0\n1080 12 14... | 6AIZU | Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem.
### Description:
You have a computer literacy course in your university. In the computer system, the login/logout records of all PCs in a day are stored in a file. Although students may use two or mor... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.